Ticket #16736: adminemail_getmessage_patch.3.diff

File adminemail_getmessage_patch.3.diff, 1.5 KB (added by Saverio Trioni, 13 years ago)

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

  • regressiontests/logging_tests/tests.py

     
    115115        f.filter("a record")
    116116
    117117        self.assertEqual(collector, ["a record"])
     118
     119
     120class AdminEmailHandlerTest(TestCase):
     121    def test_accepts_args(self):
     122        from django.conf import settings
     123        from django.core import mail
     124        from django.utils.log import getLogger, logging
     125
     126        old_admins = settings.ADMINS
     127        settings.ADMINS = (('whatever admin', 'admin@example.com'),)
     128
     129        message = "this is my message, and it says '%s'"
     130        token = 'token'
     131
     132        logger = getLogger('django.request')
     133        # taken from regressiontests/views/views.py: send_log
     134        # ensuring the AdminEmailHandler does not get filtered out
     135        # even with DEBUG=True.
     136        admin_email_handler = [
     137            h for h in logger.handlers
     138            if h.__class__.__name__ == "AdminEmailHandler"
     139            ][0]
     140        orig_filters = admin_email_handler.filters
     141        admin_email_handler.filters = []
     142
     143        logger.error(message, token)
     144
     145        self.assertEqual(len(mail.outbox), 1)
     146        self.assertTrue('token' in mail.outbox[0].subject,
     147            "Subject should contain the token")
     148
     149        admin_email_handler.filters = orig_filters
     150        settings.ADMINS = old_admins
Back to Top