diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2018-04-13 13:18:53 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-04-17 13:02:05 -0400 |
| commit | b3cffde5559c4fa97625512d7ec41a674be26076 (patch) | |
| tree | b5ad741522c6ffab550c1d98fa8200d6eb5abd6b /tests | |
| parent | fff689ed982c9aeb1402446c4eb91c2fb5a2c832 (diff) | |
Fixed #29324 -- Made Settings raise ImproperlyConfigured if SECRET_KEY is accessed and not set.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/admin_scripts/tests.py | 13 | ||||
| -rw-r--r-- | tests/settings_tests/tests.py | 14 |
2 files changed, 24 insertions, 3 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 3c4e01dfac..17347a476b 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -2213,7 +2213,11 @@ class DiffSettings(AdminScriptTestCase): out, err = self.run_manage(args) self.assertNoOutput(err) self.assertOutput(out, "+ FOO = 'bar'") - self.assertOutput(out, "- SECRET_KEY = ''") + self.assertOutput(out, "- INSTALLED_APPS = []") + self.assertOutput( + out, + "+ INSTALLED_APPS = ['django.contrib.auth', 'django.contrib.contenttypes', 'admin_scripts']" + ) self.assertOutput(out, "+ SECRET_KEY = 'django_tests_secret_key'") self.assertNotInOutput(out, " APPEND_SLASH = True") @@ -2229,7 +2233,12 @@ class DiffSettings(AdminScriptTestCase): self.assertNoOutput(err) self.assertOutput(out, " APPEND_SLASH = True") self.assertOutput(out, "+ FOO = 'bar'") - self.assertOutput(out, "- SECRET_KEY = ''") + self.assertOutput(out, "- INSTALLED_APPS = []") + self.assertOutput( + out, + "+ INSTALLED_APPS = ['django.contrib.auth', 'django.contrib.contenttypes', 'admin_scripts']" + ) + self.assertOutput(out, "+ SECRET_KEY = 'django_tests_secret_key'") class Dumpdata(AdminScriptTestCase): diff --git a/tests/settings_tests/tests.py b/tests/settings_tests/tests.py index 09c062c897..9187f87388 100644 --- a/tests/settings_tests/tests.py +++ b/tests/settings_tests/tests.py @@ -292,8 +292,20 @@ class SettingsTests(SimpleTestCase): def test_no_secret_key(self): settings_module = ModuleType('fake_settings_module') sys.modules['fake_settings_module'] = settings_module - msg = 'The SECRET_KEY setting must not be empty.' + msg = 'The SECRET_KEY setting must be set.' try: + settings = Settings('fake_settings_module') + with self.assertRaisesMessage(ImproperlyConfigured, msg): + settings.SECRET_KEY + finally: + del sys.modules['fake_settings_module'] + + def test_secret_key_empty_string(self): + settings_module = ModuleType('fake_settings_module') + settings_module.SECRET_KEY = '' + sys.modules['fake_settings_module'] = settings_module + try: + msg = 'The SECRET_KEY setting must not be empty.' with self.assertRaisesMessage(ImproperlyConfigured, msg): Settings('fake_settings_module') finally: |
