mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Removed backwards-compatibility shim for #16288.
Also unit-tested django.utils.log.RequireDebugTrue for consistency.
This commit is contained in:
@@ -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):
|
||||
def test_require_debug_true_filter(self):
|
||||
"""
|
||||
Test that the logging configuration is not modified if the mail_admins
|
||||
handler already has a "filters" key.
|
||||
|
||||
Test the RequireDebugTrue filter class.
|
||||
"""
|
||||
config = copy.deepcopy(OLD_LOGGING)
|
||||
config["handlers"]["mail_admins"]["filters"] = []
|
||||
new_config = copy.deepcopy(config)
|
||||
compat_patch_logging_config(new_config)
|
||||
filter_ = RequireDebugTrue()
|
||||
|
||||
self.assertEqual(config, new_config)
|
||||
|
||||
def test_no_patch_if_no_mail_admins_handler(self):
|
||||
"""
|
||||
Test that the logging configuration is not modified if the mail_admins
|
||||
handler is not present.
|
||||
|
||||
"""
|
||||
config = copy.deepcopy(OLD_LOGGING)
|
||||
config["handlers"].pop("mail_admins")
|
||||
new_config = copy.deepcopy(config)
|
||||
compat_patch_logging_config(new_config)
|
||||
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user