summaryrefslogtreecommitdiff
path: root/tests/logging_tests
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2016-04-13 14:38:17 -0700
committerTim Graham <timograham@gmail.com>2016-04-20 20:56:40 -0400
commit5e00b14403db75d83a274864ecd008d0e826c61d (patch)
tree648f314ace3668b8f973540444bf9627780b5376 /tests/logging_tests
parent86880ab89b1343f24c6a431d609927d1453c4495 (diff)
downloaddjango-5e00b14403db75d83a274864ecd008d0e826c61d.tar.gz
Added tests for logging of Http404 warnings.
Diffstat (limited to 'tests/logging_tests')
-rw-r--r--tests/logging_tests/tests.py39
-rw-r--r--tests/logging_tests/urls.py1
-rw-r--r--tests/logging_tests/urls_i18n.py9
-rw-r--r--tests/logging_tests/views.py5
4 files changed, 51 insertions, 3 deletions
diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py
index df210f0740..22a059cb0d 100644
--- a/tests/logging_tests/tests.py
+++ b/tests/logging_tests/tests.py
@@ -66,19 +66,22 @@ class LoggingFiltersTest(SimpleTestCase):
self.assertEqual(filter_.filter("record is not used"), False)
-class DefaultLoggingTest(LoggingCaptureMixin, SimpleTestCase):
+class SetupDefaultLoggingMixin(object):
@classmethod
def setUpClass(cls):
- super(DefaultLoggingTest, cls).setUpClass()
+ super(SetupDefaultLoggingMixin, cls).setUpClass()
cls._logging = settings.LOGGING
logging.config.dictConfig(DEFAULT_LOGGING)
@classmethod
def tearDownClass(cls):
- super(DefaultLoggingTest, cls).tearDownClass()
+ super(SetupDefaultLoggingMixin, cls).tearDownClass()
logging.config.dictConfig(cls._logging)
+
+class DefaultLoggingTests(SetupDefaultLoggingMixin, LoggingCaptureMixin, SimpleTestCase):
+
def test_django_logger(self):
"""
The 'django' base logger only output anything when DEBUG=True.
@@ -106,6 +109,36 @@ class DefaultLoggingTest(LoggingCaptureMixin, SimpleTestCase):
self.assertEqual(self.logger_output.getvalue(), '')
+@override_settings(DEBUG=True, ROOT_URLCONF='logging_tests.urls')
+class HandlerLoggingTests(SetupDefaultLoggingMixin, LoggingCaptureMixin, SimpleTestCase):
+
+ def test_page_found_no_warning(self):
+ self.client.get('/innocent/')
+ self.assertEqual(self.logger_output.getvalue(), '')
+
+ def test_page_not_found_warning(self):
+ self.client.get('/does_not_exist/')
+ self.assertEqual(self.logger_output.getvalue(), 'Not Found: /does_not_exist/\n')
+
+
+@override_settings(
+ DEBUG=True,
+ USE_I18N=True,
+ LANGUAGES=[('en', 'English')],
+ MIDDLEWARE_CLASSES=[
+ 'django.middleware.locale.LocaleMiddleware',
+ 'django.middleware.common.CommonMiddleware',
+ ],
+ ROOT_URLCONF='logging_tests.urls_i18n',
+)
+class I18nLoggingTests(SetupDefaultLoggingMixin, LoggingCaptureMixin, SimpleTestCase):
+
+ def test_i18n_page_not_found_warning(self):
+ self.client.get('/this_does_not/')
+ self.client.get('/en/nor_this/')
+ self.assertEqual(self.logger_output.getvalue(), 'Not Found: /this_does_not/\nNot Found: /en/nor_this/\n')
+
+
class WarningLoggerTests(SimpleTestCase):
"""
Tests that warnings output for RemovedInDjangoXXWarning (XX being the next
diff --git a/tests/logging_tests/urls.py b/tests/logging_tests/urls.py
index 50f86cdbb2..ca6dd9b430 100644
--- a/tests/logging_tests/urls.py
+++ b/tests/logging_tests/urls.py
@@ -5,6 +5,7 @@ from django.conf.urls import url
from . import views
urlpatterns = [
+ url(r'^innocent/$', views.innocent),
url(r'^suspicious/$', views.suspicious),
url(r'^suspicious_spec/$', views.suspicious_spec),
]
diff --git a/tests/logging_tests/urls_i18n.py b/tests/logging_tests/urls_i18n.py
new file mode 100644
index 0000000000..80ce990413
--- /dev/null
+++ b/tests/logging_tests/urls_i18n.py
@@ -0,0 +1,9 @@
+from __future__ import unicode_literals
+
+from django.conf.urls import url
+from django.conf.urls.i18n import i18n_patterns
+from django.http import HttpResponse
+
+urlpatterns = i18n_patterns(
+ url(r'^exists/$', lambda r: HttpResponse()),
+)
diff --git a/tests/logging_tests/views.py b/tests/logging_tests/views.py
index 77186be329..a362509700 100644
--- a/tests/logging_tests/views.py
+++ b/tests/logging_tests/views.py
@@ -1,6 +1,11 @@
from __future__ import unicode_literals
from django.core.exceptions import DisallowedHost, SuspiciousOperation
+from django.http import HttpResponse
+
+
+def innocent(request):
+ return HttpResponse('innocent')
def suspicious(request):