12288 Added new check on INSTALL_APPS for unique values #1445

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+25 −0
Diff settings

Always

Just for now

View
@@ -107,6 +107,9 @@ def __setattr__(self, name, value):
elif name == "ALLOWED_INCLUDE_ROOTS" and isinstance(value, six.string_types):
raise ValueError("The ALLOWED_INCLUDE_ROOTS setting must be set "
"to a tuple, not a string.")
+ elif name == "INSTALLED_APPS" and len(value) != len(set(value)):
+ raise ImproperlyConfigured("The INSTALLED_APPS setting must contain unique values.")
+
object.__setattr__(self, name, value)
@@ -226,6 +226,28 @@ def test_complex_override_warning(self):
self.assertEqual('Overriding setting TEST_WARN can lead to unexpected behaviour.', str(w[-1].message))
+class UniqueSettngsTests(TestCase):
+ """
+ Tests for the INSTALLED_APPS setting.
+
+ Applications in INSTALLED_APPS must be unique.
+ """
+ settings_module = settings
+
+ def setUp(self):
+ self._installed_apps = self.settings_module.INSTALLED_APPS
+
+ def tearDown(self):
+ self.settings_module.INSTALLED_APPS = self._installed_apps
+
+ def test_unique(self):
+ """
+ An ImproperlyConfigured exception is raised if the INSTALLED_APPS contains
+ any duplicate strings.
+ """
+ with self.assertRaises(ImproperlyConfigured):
+ self.settings_module.INSTALLED_APPS = ("myApp1", "myApp1", "myApp2", "myApp3")
+
class TrailingSlashURLTests(TestCase):
"""
Tests for the MEDIA_URL and STATIC_URL settings.