forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_new.py
More file actions
43 lines (31 loc) · 1.13 KB
/
test_new.py
File metadata and controls
43 lines (31 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import shutil
import tempfile
from unittest import TestCase
from piccolo.apps.app.commands.new import module_exists, new
class TestModuleExists(TestCase):
def test_module_exists(self):
self.assertEqual(module_exists("sys"), True)
self.assertEqual(module_exists("abc123xyz"), False)
class TestNewApp(TestCase):
def test_new(self):
root = tempfile.gettempdir()
app_name = "my_app"
app_path = os.path.join(root, app_name)
if os.path.exists(app_path):
shutil.rmtree(app_path)
new(app_name=app_name, root=root)
self.assertTrue(os.path.exists(app_path))
def test_new_with_clashing_name(self):
"""
Test trying to create an app with the same name as a builtin Python
package - it shouldn't be allowed.
"""
root = tempfile.gettempdir()
app_name = "sys"
with self.assertRaises(SystemExit) as context:
new(app_name=app_name, root=root)
exception = context.exception
self.assertTrue(
exception.code.startswith("A module called sys already exists")
)