Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #21833 -- Fix UserSettingsHolder.is_overridden() and add tests.

  • Loading branch information...
commit 6070a5d6a6950bdbd93853c4b1636c7eec820b20 1 parent 56516ad
@carljm carljm authored
Showing with 35 additions and 6 deletions.
  1. +4 −5 django/conf/__init__.py
  2. +31 −1 tests/settings_tests/tests.py
View
9 django/conf/__init__.py
@@ -108,7 +108,6 @@ def __init__(self, settings_module):
isinstance(setting_value, six.string_types)):
raise ImproperlyConfigured("The %s setting must be a tuple. "
"Please fix your settings." % setting)
-
setattr(self, setting, setting_value)
self._explicit_settings.add(setting)
@@ -164,9 +163,9 @@ def __dir__(self):
return list(self.__dict__) + dir(self.default_settings)
def is_overridden(self, setting):
- if setting in self._deleted:
- return False
- else:
- return self.default_settings.is_overridden(setting)
+ deleted = (setting in self._deleted)
+ set_locally = (setting in self.__dict__)
+ set_on_default = getattr(self.default_settings, 'is_overridden', lambda s: False)(setting)
+ return (deleted or set_locally or set_on_default)
settings = LazySettings()
View
32 tests/settings_tests/tests.py
@@ -1,8 +1,10 @@
import os
+import sys
+from types import ModuleType
import unittest
import warnings
-from django.conf import settings
+from django.conf import LazySettings, Settings, settings
from django.core.exceptions import ImproperlyConfigured
from django.http import HttpRequest
from django.test import (SimpleTestCase, TransactionTestCase, TestCase,
@@ -404,3 +406,31 @@ def test_set_with_xheader_right(self):
req = HttpRequest()
req.META['HTTP_X_FORWARDED_PROTOCOL'] = 'https'
self.assertEqual(req.is_secure(), True)
+
+
+
+class IsOverriddenTest(TestCase):
+ def test_configure(self):
+ s = LazySettings()
+ s.configure(SECRET_KEY='foo')
+
+ self.assertTrue(s.is_overridden('SECRET_KEY'))
+
+
+ def test_module(self):
+ settings_module = ModuleType('fake_settings_module')
+ settings_module.SECRET_KEY = 'foo'
+ sys.modules['fake_settings_module'] = settings_module
+ try:
+ s = Settings('fake_settings_module')
+
+ self.assertTrue(s.is_overridden('SECRET_KEY'))
+ self.assertFalse(s.is_overridden('TEMPLATE_LOADERS'))
+ finally:
+ del sys.modules['fake_settings_module']
+
+
+ def test_override(self):
+ self.assertFalse(settings.is_overridden('TEMPLATE_LOADERS'))
+ with override_settings(TEMPLATE_LOADERS=[]):
+ self.assertTrue(settings.is_overridden('TEMPLATE_LOADERS'))
Please sign in to comment.
Something went wrong with that request. Please try again.