summaryrefslogtreecommitdiff
path: root/tests/logging_tests
diff options
context:
space:
mode:
authorNasir Hussain <nasirhjafri@gmail.com>2019-02-24 20:10:14 +0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-09-04 08:40:46 +0200
commit25706d728536fea88e12f62856de7c4b569ae282 (patch)
tree8078a729e666fb72a5c84de8d7fe8a7476ffdccb /tests/logging_tests
parent3c6a4fdb6d828a03e368632d88f8261cc30104da (diff)
downloaddjango-25706d728536fea88e12f62856de7c4b569ae282.tar.gz
Fixed #29714 -- Allowed using ExceptionReporter subclass with AdminEmailHandler.
Diffstat (limited to 'tests/logging_tests')
-rw-r--r--tests/logging_tests/logconfig.py6
-rw-r--r--tests/logging_tests/tests.py15
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/logging_tests/logconfig.py b/tests/logging_tests/logconfig.py
index b068103eb9..93b0186590 100644
--- a/tests/logging_tests/logconfig.py
+++ b/tests/logging_tests/logconfig.py
@@ -2,6 +2,7 @@ import logging
from django.conf import settings
from django.core.mail.backends.base import BaseEmailBackend
+from django.views.debug import ExceptionReporter
class MyHandler(logging.Handler):
@@ -13,3 +14,8 @@ class MyHandler(logging.Handler):
class MyEmailBackend(BaseEmailBackend):
def send_messages(self, email_messages):
pass
+
+
+class CustomExceptionReporter(ExceptionReporter):
+ def get_traceback_text(self):
+ return 'custom traceback text'
diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py
index a257cafa90..c341e89997 100644
--- a/tests/logging_tests/tests.py
+++ b/tests/logging_tests/tests.py
@@ -16,6 +16,7 @@ from django.utils.log import (
DEFAULT_LOGGING, AdminEmailHandler, CallbackFilter, RequireDebugFalse,
RequireDebugTrue, ServerFormatter,
)
+from django.views.debug import ExceptionReporter
from . import views
from .logconfig import MyEmailBackend
@@ -431,6 +432,20 @@ class AdminEmailHandlerTest(SimpleTestCase):
finally:
admin_email_handler.include_html = old_include_html
+ def test_default_exception_reporter_class(self):
+ admin_email_handler = self.get_admin_email_handler(self.logger)
+ self.assertEqual(admin_email_handler.reporter_class, ExceptionReporter)
+
+ @override_settings(ADMINS=[('A.N.Admin', 'admin@example.com')])
+ def test_custom_exception_reporter_is_used(self):
+ record = self.logger.makeRecord('name', logging.ERROR, 'function', 'lno', 'message', None, None)
+ record.request = self.request_factory.get('/')
+ handler = AdminEmailHandler(reporter_class='logging_tests.logconfig.CustomExceptionReporter')
+ handler.emit(record)
+ self.assertEqual(len(mail.outbox), 1)
+ msg = mail.outbox[0]
+ self.assertEqual(msg.body, 'message\n\ncustom traceback text')
+
class SettingsConfigTest(AdminScriptTestCase):
"""