diff options
Diffstat (limited to 'tests/admin_scripts/tests.py')
| -rw-r--r-- | tests/admin_scripts/tests.py | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index a6f7845b20..9a6cf06a60 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -1004,28 +1004,24 @@ class ManageMultipleSettings(AdminScriptTestCase): self.assertOutput(out, "EXECUTE:NoArgsCommand") -class ManageSettingsWithImportError(AdminScriptTestCase): - """Tests for manage.py when using the default settings.py file - with an import error. Ticket #14130. +class ManageSettingsWithSettingsErrors(AdminScriptTestCase): + """ + Tests for manage.py when using the default settings.py file containing + runtime errors. """ def tearDown(self): self.remove_settings('settings.py') - def write_settings_with_import_error(self, filename, apps=None, is_dir=False, sdict=None): - if is_dir: - settings_dir = os.path.join(test_dir, filename) - os.mkdir(settings_dir) - settings_file_path = os.path.join(settings_dir, '__init__.py') - else: - settings_file_path = os.path.join(test_dir, filename) + def write_settings_with_import_error(self, filename): + settings_file_path = os.path.join(test_dir, filename) with open(settings_file_path, 'w') as settings_file: settings_file.write('# Settings file automatically generated by admin_scripts test case\n') settings_file.write('# The next line will cause an import error:\nimport foo42bar\n') - def test_builtin_command(self): + def test_import_error(self): """ import error: manage.py builtin commands shows useful diagnostic info - when settings with import errors is provided + when settings with import errors is provided (#14130). """ self.write_settings_with_import_error('settings.py') args = ['sqlall', 'admin_scripts'] @@ -1034,9 +1030,10 @@ class ManageSettingsWithImportError(AdminScriptTestCase): self.assertOutput(err, "No module named") self.assertOutput(err, "foo42bar") - def test_builtin_command_with_attribute_error(self): + def test_attribute_error(self): """ - manage.py builtin commands does not swallow attribute errors from bad settings (#18845) + manage.py builtin commands does not swallow attribute error due to bad + settings (#18845). """ self.write_settings('settings.py', sdict={'BAD_VAR': 'INSTALLED_APPS.crash'}) args = ['collectstatic', 'admin_scripts'] @@ -1044,6 +1041,13 @@ class ManageSettingsWithImportError(AdminScriptTestCase): self.assertNoOutput(out) self.assertOutput(err, "AttributeError: 'list' object has no attribute 'crash'") + def test_key_error(self): + self.write_settings('settings.py', sdict={'BAD_VAR': 'DATABASES["blah"]'}) + args = ['collectstatic', 'admin_scripts'] + out, err = self.run_manage(args) + self.assertNoOutput(out) + self.assertOutput(err, "KeyError: 'blah'") + class ManageValidate(AdminScriptTestCase): def tearDown(self): |
