diff options
| author | Adam Johnson <me@adamj.eu> | 2017-05-28 12:52:49 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-05-30 09:40:32 -0400 |
| commit | b3e55109bd2ec5125042b65cdaac0789574c1848 (patch) | |
| tree | 04390dc08d05f74d8d7093074c5323ebc0a39a6d /tests/admin_scripts | |
| parent | c32476e5ba2f1c18758cfcffc857fa4eab37e816 (diff) | |
Improved test coverage for startapp/startproject management commands.
Diffstat (limited to 'tests/admin_scripts')
| -rw-r--r-- | tests/admin_scripts/tests.py | 56 |
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.""" |
