summaryrefslogtreecommitdiff
path: root/tests/admin_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/admin_scripts')
-rw-r--r--tests/admin_scripts/tests.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index f52eac6761..9ef2da83a0 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -1905,6 +1905,25 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
)
self.assertFalse(os.path.exists(testproject_dir))
+ def test_importable_project_name(self):
+ """
+ startproject validates that project name doesn't clash with existing
+ Python modules.
+ """
+ bad_name = 'os'
+ args = ['startproject', bad_name]
+ testproject_dir = os.path.join(self.test_dir, bad_name)
+ self.addCleanup(shutil.rmtree, testproject_dir, True)
+
+ out, err = self.run_django_admin(args)
+ self.assertOutput(
+ err,
+ "CommandError: 'os' conflicts with the name of an existing "
+ "Python module and cannot be used as a project name. Please try "
+ "another name."
+ )
+ self.assertFalse(os.path.exists(testproject_dir))
+
def test_simple_project_different_directory(self):
"Make sure the startproject management command creates a project in a specific directory"
args = ['startproject', 'testproject', 'othertestproject']
@@ -2085,6 +2104,43 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
'üäö €'])
+class StartApp(AdminScriptTestCase):
+
+ def test_invalid_name(self):
+ """startapp validates that app name is a valid Python identifier."""
+ for bad_name in ('7testproject', '../testproject'):
+ args = ['startapp', bad_name]
+ testproject_dir = os.path.join(self.test_dir, bad_name)
+ self.addCleanup(shutil.rmtree, testproject_dir, True)
+
+ out, err = self.run_django_admin(args)
+ self.assertOutput(
+ err,
+ "CommandError: '{}' is not a valid app name. Please make "
+ "sure the name is a valid identifier.".format(bad_name)
+ )
+ self.assertFalse(os.path.exists(testproject_dir))
+
+ def test_importable_name(self):
+ """
+ startapp validates that app name doesn't clash with existing Python
+ modules.
+ """
+ bad_name = 'os'
+ args = ['startapp', bad_name]
+ testproject_dir = os.path.join(self.test_dir, bad_name)
+ self.addCleanup(shutil.rmtree, testproject_dir, True)
+
+ out, err = self.run_django_admin(args)
+ self.assertOutput(
+ err,
+ "CommandError: 'os' conflicts with the name of an existing "
+ "Python module and cannot be used as an app name. Please try "
+ "another name."
+ )
+ self.assertFalse(os.path.exists(testproject_dir))
+
+
class DiffSettings(AdminScriptTestCase):
"""Tests for diffsettings management command."""