Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #17895 -- Made override_settings send the setting_changed signa…

…l both when a setting is overridden and when it's restored.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17708 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4b14546215ad4ef15f04e748e3b5f0da7b613b45 1 parent 2a0f457
@aaugustin aaugustin authored
View
19 django/test/utils.py
@@ -167,15 +167,6 @@ def restore_template_loaders():
delattr(loader, RESTORE_LOADERS_ATTR)
-class OverrideSettingsHolder(UserSettingsHolder):
- """
- A custom setting holder that sends a signal upon change.
- """
- def __setattr__(self, name, value):
- UserSettingsHolder.__setattr__(self, name, value)
- setting_changed.send(sender=self.__class__, setting=name, value=value)
-
-
class override_settings(object):
"""
Acts as either a decorator, or a context manager. If it's a decorator it
@@ -215,10 +206,18 @@ def inner(*args, **kwargs):
return inner
def enable(self):
- override = OverrideSettingsHolder(settings._wrapped)
+ override = UserSettingsHolder(settings._wrapped)
for key, new_value in self.options.items():
setattr(override, key, new_value)
settings._wrapped = override
+ for key, new_value in self.options.items():
+ setting_changed.send(sender=settings._wrapped.__class__,
+ setting=key, value=new_value)
def disable(self):
settings._wrapped = self.wrapped
+ for key in self.options:
+ new_value = getattr(settings, key, None)
+ setting_changed.send(sender=settings._wrapped.__class__,
+ setting=key, value=new_value)
+
View
10 docs/ref/signals.txt
@@ -477,20 +477,24 @@ setting_changed
.. data:: django.test.signals.setting_changed
:module:
-Sent when some :ref:`settings are overridden <overriding-settings>` with the
+This signal is sent when the value of a setting is changed through the
:meth:`django.test.TestCase.setting` context manager or the
:func:`django.test.utils.override_settings` decorator/context manager.
+It's actually sent twice: when the new value is applied ("setup") and when the
+original value is restored ("teardown").
+
Arguments sent with this signal:
``sender``
The settings handler.
``setting``
- Same as sender
+ The name of the setting.
``value``
- The new setting value.
+ The value of the setting after the change. For settings that initially
+ don't exist, in the "teardown" phase, ``value`` is ``None``.
template_rendered
-----------------
View
1  tests/regressiontests/settings_tests/tests.py
@@ -132,6 +132,7 @@ def test_signal_callback_context_manager(self):
self.assertRaises(AttributeError, getattr, settings, 'TEST')
with self.settings(TEST='override'):
self.assertEqual(testvalue, 'override')
+ self.assertEqual(testvalue, None)
@override_settings(TEST='override')
def test_signal_callback_decorator(self):
Please sign in to comment.
Something went wrong with that request. Please try again.