Skip to content

Commit 9324292

Browse files
committed
added test for piccolo project new
1 parent a8b83d2 commit 9324292

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

piccolo/apps/project/commands/new.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
)
1818

1919

20-
def new_piccolo_conf(engine_name: str, force: bool = False):
21-
print(f"Creating new piccolo_conf file ...")
20+
def new_piccolo_conf(engine_name: str, force: bool = False, root: str = ""):
21+
print("Creating new piccolo_conf file ...")
2222

23-
if os.path.exists("piccolo_conf.py") and not force:
23+
file_path = os.path.join(root, "piccolo_conf.py")
24+
25+
if os.path.exists(file_path) and not force:
2426
print("The file already exists - exiting.")
2527
sys.exit(1)
2628

27-
with open("piccolo_conf.py", "w") as f:
29+
with open(file_path, "w") as f:
2830
template = JINJA_ENV.get_template("piccolo_conf.py.jinja")
2931
file_contents = template.render(engine_name=engine_name)
3032
file_contents = black.format_str(
@@ -34,7 +36,7 @@ def new_piccolo_conf(engine_name: str, force: bool = False):
3436
f.write(file_contents)
3537

3638

37-
def new(engine: str = "postgres", force: bool = False):
39+
def new(engine: str = "postgres", force: bool = False, root: str = ""):
3840
"""
3941
Creates a new Piccolo project file (piccolo_conf.py).
4042
@@ -44,6 +46,9 @@ def new(engine: str = "postgres", force: bool = False):
4446
:param force:
4547
If True, it will override the piccolo_conf.py file if it already
4648
exists.
49+
:param root:
50+
Where to create the app e.g. /my/folder. By default it creates the
51+
app in the current directory.
4752
4853
"""
49-
new_piccolo_conf(engine_name=engine, force=force)
54+
new_piccolo_conf(engine_name=engine, force=force, root=root)

tests/apps/project/__init__.py

Whitespace-only changes.

tests/apps/project/commands/__init__.py

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
from unittest import TestCase
3+
4+
from piccolo.apps.project.commands.new import new
5+
6+
7+
class TestNewProject(TestCase):
8+
def test_new(self):
9+
root = "/tmp"
10+
11+
file_path = "/tmp/piccolo_conf.py"
12+
13+
if os.path.exists(file_path):
14+
os.unlink(file_path)
15+
16+
new(root=root)
17+
18+
self.assertTrue(os.path.exists(file_path))

0 commit comments

Comments
 (0)