diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2023-08-31 20:15:22 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-09-01 13:24:05 +0200 |
| commit | bcd80de8b5264d8c853bbd38bfeb02279a9b3799 (patch) | |
| tree | 331cb588e34e4f655279bf5026e3b03fb56f5198 /tests/admin_scripts/tests.py | |
| parent | 9a9620dda649dcdb685662bbd9cb409bfeff4214 (diff) | |
Fixed #34778 -- Avoided importing modules in startapp/startproject.
Diffstat (limited to 'tests/admin_scripts/tests.py')
| -rw-r--r-- | tests/admin_scripts/tests.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 57fbc454ff..7f39d7fcfc 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -2447,6 +2447,28 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase): ) self.assertFalse(os.path.exists(testproject_dir)) + def test_command_does_not_import(self): + """ + startproject doesn't import modules (and cannot be fooled by a module + raising ImportError). + """ + bad_name = "raises_import_error" + args = ["startproject", bad_name] + testproject_dir = os.path.join(self.test_dir, bad_name) + + with open(os.path.join(self.test_dir, "raises_import_error.py"), "w") as f: + f.write("raise ImportError") + + out, err = self.run_django_admin(args) + self.assertOutput( + err, + "CommandError: 'raises_import_error' conflicts with the name of an " + "existing Python module and cannot be used as a project name. Please try " + "another name.", + ) + self.assertNoOutput(out) + self.assertFalse(os.path.exists(testproject_dir)) + def test_simple_project_different_directory(self): """ The startproject management command creates a project in a specific |
