summaryrefslogtreecommitdiff
path: root/tests/logging_tests/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/logging_tests/tests.py')
-rw-r--r--tests/logging_tests/tests.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py
index 8e5445cd42..0c2d269464 100644
--- a/tests/logging_tests/tests.py
+++ b/tests/logging_tests/tests.py
@@ -8,9 +8,10 @@ import warnings
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.test.utils import override_settings, patch_logger
from django.utils.encoding import force_text
-from django.utils.log import CallbackFilter, RequireDebugFalse, RequireDebugTrue
+from django.utils.log import (CallbackFilter, RequireDebugFalse,
+ RequireDebugTrue)
from django.utils.six import StringIO
from django.utils.unittest import skipUnless
@@ -354,3 +355,22 @@ class SettingsConfigureLogging(TestCase):
settings.configure(
LOGGING_CONFIG='logging_tests.tests.dictConfig')
self.assertTrue(dictConfig.called)
+
+
+class SecurityLoggerTest(TestCase):
+
+ urls = 'logging_tests.urls'
+
+ def test_suspicious_operation_creates_log_message(self):
+ with self.settings(DEBUG=True):
+ with patch_logger('django.security.SuspiciousOperation', 'error') as calls:
+ response = self.client.get('/suspicious/')
+ self.assertEqual(len(calls), 1)
+ self.assertEqual(calls[0], 'dubious')
+
+ def test_suspicious_operation_uses_sublogger(self):
+ with self.settings(DEBUG=True):
+ with patch_logger('django.security.DisallowedHost', 'error') as calls:
+ response = self.client.get('/suspicious_spec/')
+ self.assertEqual(len(calls), 1)
+ self.assertEqual(calls[0], 'dubious')