summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-12-24 22:32:41 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-12-29 21:58:12 +0100
commitfb9f1b9bfb7378027adfe916733c701a89f8bb24 (patch)
treee87438c9e4c907f6afe35755647afcda60dae0bf
parent067505ad19f088e8db1d8c788ceea388c7241bcd (diff)
Removed backwards-compatibility shim for #16288.
Also unit-tested django.utils.log.RequireDebugTrue for consistency.
-rw-r--r--django/conf/__init__.py39
-rw-r--r--django/utils/log.py2
-rw-r--r--tests/regressiontests/logging_tests/tests.py71
3 files changed, 12 insertions, 100 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index b00c8d5046..ccf7a94af6 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -74,11 +74,8 @@ class LazySettings(LazyObject):
logging_config_func(DEFAULT_LOGGING)
+ # ... then invoke it with the logging settings
if self.LOGGING:
- # Backwards-compatibility shim for #16288 fix
- compat_patch_logging_config(self.LOGGING)
-
- # ... then invoke it with the logging settings
logging_config_func(self.LOGGING)
def configure(self, default_settings=global_settings, **options):
@@ -195,37 +192,3 @@ class UserSettingsHolder(BaseSettings):
return list(self.__dict__) + dir(self.default_settings)
settings = LazySettings()
-
-
-
-def compat_patch_logging_config(logging_config):
- """
- Backwards-compatibility shim for #16288 fix. Takes initial value of
- ``LOGGING`` setting and patches it in-place (issuing deprecation warning)
- if "mail_admins" logging handler is configured but has no filters.
-
- """
- # Shim only if LOGGING["handlers"]["mail_admins"] exists,
- # but has no "filters" key
- if "filters" not in logging_config.get(
- "handlers", {}).get(
- "mail_admins", {"filters": []}):
-
- warnings.warn(
- "You have no filters defined on the 'mail_admins' logging "
- "handler: adding implicit debug-false-only filter. "
- "See http://docs.djangoproject.com/en/dev/releases/1.4/"
- "#request-exceptions-are-now-always-logged",
- DeprecationWarning)
-
- filter_name = "require_debug_false"
-
- filters = logging_config.setdefault("filters", {})
- while filter_name in filters:
- filter_name = filter_name + "_"
-
- filters[filter_name] = {
- "()": "django.utils.log.RequireDebugFalse",
- }
-
- logging_config["handlers"]["mail_admins"]["filters"] = [filter_name]
diff --git a/django/utils/log.py b/django/utils/log.py
index 736154a178..292bd0794c 100644
--- a/django/utils/log.py
+++ b/django/utils/log.py
@@ -152,4 +152,4 @@ class RequireDebugFalse(logging.Filter):
class RequireDebugTrue(logging.Filter):
def filter(self, record):
- return settings.DEBUG
+ return settings.DEBUG
diff --git a/tests/regressiontests/logging_tests/tests.py b/tests/regressiontests/logging_tests/tests.py
index 07804eb398..f9838949ab 100644
--- a/tests/regressiontests/logging_tests/tests.py
+++ b/tests/regressiontests/logging_tests/tests.py
@@ -5,12 +5,12 @@ import logging
import sys
import warnings
-from django.conf import compat_patch_logging_config, LazySettings
+from django.conf import LazySettings
from django.core import mail
from django.test import TestCase, RequestFactory
from django.test.utils import override_settings
from django.utils.encoding import force_text
-from django.utils.log import CallbackFilter, RequireDebugFalse
+from django.utils.log import CallbackFilter, RequireDebugFalse, RequireDebugTrue
from django.utils.six import StringIO
from django.utils.unittest import skipUnless
@@ -40,46 +40,10 @@ OLD_LOGGING = {
}
-class PatchLoggingConfigTest(TestCase):
- """
- Tests for backward-compat shim for #16288. These tests should be removed in
- Django 1.6 when that shim and DeprecationWarning are removed.
-
- """
- def test_filter_added(self):
- """
- Test that debug-false filter is added to mail_admins handler if it has
- no filters.
-
- """
- config = copy.deepcopy(OLD_LOGGING)
-
- with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter("always")
- compat_patch_logging_config(config)
- self.assertEqual(len(w), 1)
-
- self.assertEqual(
- config["handlers"]["mail_admins"]["filters"],
- ['require_debug_false'])
-
- def test_filter_configuration(self):
- """
- Test that the auto-added require_debug_false filter is an instance of
- `RequireDebugFalse` filter class.
-
- """
- config = copy.deepcopy(OLD_LOGGING)
- with warnings.catch_warnings(record=True):
- compat_patch_logging_config(config)
-
- flt = config["filters"]["require_debug_false"]
- self.assertEqual(flt["()"], "django.utils.log.RequireDebugFalse")
-
+class LoggingFiltersTest(TestCase):
def test_require_debug_false_filter(self):
"""
Test the RequireDebugFalse filter class.
-
"""
filter_ = RequireDebugFalse()
@@ -89,32 +53,17 @@ class PatchLoggingConfigTest(TestCase):
with self.settings(DEBUG=False):
self.assertEqual(filter_.filter("record is not used"), True)
- def test_no_patch_if_filters_key_exists(self):
- """
- Test that the logging configuration is not modified if the mail_admins
- handler already has a "filters" key.
-
- """
- config = copy.deepcopy(OLD_LOGGING)
- config["handlers"]["mail_admins"]["filters"] = []
- new_config = copy.deepcopy(config)
- compat_patch_logging_config(new_config)
-
- self.assertEqual(config, new_config)
-
- def test_no_patch_if_no_mail_admins_handler(self):
+ def test_require_debug_true_filter(self):
"""
- Test that the logging configuration is not modified if the mail_admins
- handler is not present.
-
+ Test the RequireDebugTrue filter class.
"""
- config = copy.deepcopy(OLD_LOGGING)
- config["handlers"].pop("mail_admins")
- new_config = copy.deepcopy(config)
- compat_patch_logging_config(new_config)
+ filter_ = RequireDebugTrue()
- self.assertEqual(config, new_config)
+ with self.settings(DEBUG=True):
+ self.assertEqual(filter_.filter("record is not used"), True)
+ with self.settings(DEBUG=False):
+ self.assertEqual(filter_.filter("record is not used"), False)
class DefaultLoggingTest(TestCase):
def setUp(self):