diff options
| author | Julien Phalip <jphalip@gmail.com> | 2011-09-02 03:04:02 +0000 |
|---|---|---|
| committer | Julien Phalip <jphalip@gmail.com> | 2011-09-02 03:04:02 +0000 |
| commit | de35a3ab14ca2fb88b4524c8ea0ebaa9e28eb85b (patch) | |
| tree | 857f0513a4904a44d432cd178ecf94d003dfe3b5 /tests/regressiontests | |
| parent | 71f017b2a6677538f8c3578e33859d4586b5bea1 (diff) | |
Fixed #16736 -- Enabled the merging of user-supplied arguments to format the error emails' subject in `AdminEmailHandler`.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16715 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
| -rw-r--r-- | tests/regressiontests/logging_tests/tests.py | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/tests/regressiontests/logging_tests/tests.py b/tests/regressiontests/logging_tests/tests.py index fe8b169421..76c5185e66 100644 --- a/tests/regressiontests/logging_tests/tests.py +++ b/tests/regressiontests/logging_tests/tests.py @@ -4,7 +4,10 @@ import copy from django.conf import compat_patch_logging_config from django.test import TestCase -from django.utils.log import CallbackFilter +from django.test.utils import override_settings +from django.utils.log import CallbackFilter, getLogger +from django.core import mail + # logging config prior to using filter with mail_admins @@ -115,3 +118,43 @@ class CallbackFilterTest(TestCase): f.filter("a record") self.assertEqual(collector, ["a record"]) + + +class AdminEmailHandlerTest(TestCase): + + @override_settings( + ADMINS=(('whatever admin', 'admin@example.com'),), + EMAIL_SUBJECT_PREFIX='-SuperAwesomeSubject-' + ) + def test_accepts_args(self): + """ + Ensure that user-supplied arguments and the EMAIL_SUBJECT_PREFIX + setting are used to compose the email subject. + Refs #16736. + """ + + message = "Custom message that says '%s' and '%s'" + token1 = 'ping' + token2 = 'pong' + + logger = getLogger('django.request') + # Inspired from regressiontests/views/views.py: send_log() + # ensuring the AdminEmailHandler does not get filtered out + # even with DEBUG=True. + admin_email_handler = [ + h for h in logger.handlers + if h.__class__.__name__ == "AdminEmailHandler" + ][0] + # Backup then override original filters + orig_filters = admin_email_handler.filters + admin_email_handler.filters = [] + + logger.error(message, token1, token2) + + self.assertEqual(len(mail.outbox), 1) + self.assertEqual(mail.outbox[0].to, ['admin@example.com']) + self.assertEqual(mail.outbox[0].subject, + "-SuperAwesomeSubject-ERROR: Custom message that says 'ping' and 'pong'") + + # Restore original filters + admin_email_handler.filters = orig_filters |
