Code

Ticket #16736: adminemail_getmessage_patch.3.diff

File adminemail_getmessage_patch.3.diff, 1.5 KB (added by strioni, 3 years ago)

Sorry, there was a typo due to excessive vimming...

Line 
1Index: regressiontests/logging_tests/tests.py
2===================================================================
3--- regressiontests/logging_tests/tests.py      (revision 16714)
4+++ regressiontests/logging_tests/tests.py      (working copy)
5@@ -115,3 +115,36 @@
6         f.filter("a record")
7 
8         self.assertEqual(collector, ["a record"])
9+
10+
11+class AdminEmailHandlerTest(TestCase):
12+    def test_accepts_args(self):
13+        from django.conf import settings
14+        from django.core import mail
15+        from django.utils.log import getLogger, logging
16+
17+        old_admins = settings.ADMINS
18+        settings.ADMINS = (('whatever admin', 'admin@example.com'),)
19+
20+        message = "this is my message, and it says '%s'"
21+        token = 'token'
22+
23+        logger = getLogger('django.request')
24+        # taken from regressiontests/views/views.py: send_log
25+        # ensuring the AdminEmailHandler does not get filtered out
26+        # even with DEBUG=True.
27+        admin_email_handler = [
28+            h for h in logger.handlers
29+            if h.__class__.__name__ == "AdminEmailHandler"
30+            ][0]
31+        orig_filters = admin_email_handler.filters
32+        admin_email_handler.filters = []
33+
34+        logger.error(message, token)
35+
36+        self.assertEqual(len(mail.outbox), 1)
37+        self.assertTrue('token' in mail.outbox[0].subject,
38+            "Subject should contain the token")
39+
40+        admin_email_handler.filters = orig_filters
41+        settings.ADMINS = old_admins