summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Donaghy <adamdonaghy1994@gmail.com>2021-03-24 11:22:27 +1100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-03-24 09:18:44 +0100
commitcdd0b213a825fcfe90ae93dcc554fba8c1e5ff5d (patch)
tree75015f9ce9c2796231bf6be5818e370e916e64cc
parenta96c730431196b119559bbb18a0e85e6ee8b2597 (diff)
Fixed #29606 -- Added type check for ALLOWED_HOSTS setting.
-rw-r--r--django/conf/__init__.py1
-rw-r--r--tests/settings_tests/tests.py6
2 files changed, 5 insertions, 2 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index 03bf923bb2..d6266521a9 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -141,6 +141,7 @@ class Settings:
mod = importlib.import_module(self.SETTINGS_MODULE)
tuple_settings = (
+ 'ALLOWED_HOSTS',
"INSTALLED_APPS",
"TEMPLATE_DIRS",
"LOCALE_PATHS",
diff --git a/tests/settings_tests/tests.py b/tests/settings_tests/tests.py
index f9f8bdb5ab..c0c53fe391 100644
--- a/tests/settings_tests/tests.py
+++ b/tests/settings_tests/tests.py
@@ -438,12 +438,13 @@ class IsOverriddenTest(SimpleTestCase):
self.assertEqual(repr(lazy_settings), expected)
-class TestListSettings(unittest.TestCase):
+class TestListSettings(SimpleTestCase):
"""
Make sure settings that should be lists or tuples throw
ImproperlyConfigured if they are set to a string instead of a list or tuple.
"""
list_or_tuple_settings = (
+ 'ALLOWED_HOSTS',
"INSTALLED_APPS",
"TEMPLATE_DIRS",
"LOCALE_PATHS",
@@ -452,11 +453,12 @@ class TestListSettings(unittest.TestCase):
def test_tuple_settings(self):
settings_module = ModuleType('fake_settings_module')
settings_module.SECRET_KEY = 'foo'
+ msg = 'The %s setting must be a list or a tuple.'
for setting in self.list_or_tuple_settings:
setattr(settings_module, setting, ('non_list_or_tuple_value'))
sys.modules['fake_settings_module'] = settings_module
try:
- with self.assertRaises(ImproperlyConfigured):
+ with self.assertRaisesMessage(ImproperlyConfigured, msg % setting):
Settings('fake_settings_module')
finally:
del sys.modules['fake_settings_module']