mirror of https://github.com/django/django.git
Fixes #21833 -- Fix UserSettingsHolder.is_overridden() and add tests.
This commit is contained in:
parent
56516ade5e
commit
6070a5d6a6
|
@ -108,7 +108,6 @@ class Settings(BaseSettings):
|
|||
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 @@ class UserSettingsHolder(BaseSettings):
|
|||
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()
|
||||
|
|
|
@ -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 @@ class SecureProxySslHeaderTest(TestCase):
|
|||
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'))
|
||||
|
|
Loading…
Reference in New Issue