Ticket #16736: adminemail_getmessage_patch.2.diff

File adminemail_getmessage_patch.2.diff, 2.3 KB (added by strioni, 4 years ago)
  • django/utils/log.py

     
    5353        except:
    5454            subject = '%s: %s' % (
    5555                record.levelname,
    56                 record.msg
     56                record.getMessage()
    5757            )
    5858            request = None
    5959            request_repr = "Request repr() unavailable."
     
    6262            exc_info = record.exc_info
    6363            stack_trace = '\n'.join(traceback.format_exception(*record.exc_info))
    6464        else:
    65             exc_info = (None, record.msg, None)
     65            exc_info = (None, record.getMessage(), None)
    6666            stack_trace = 'No stack trace available'
    6767
    6868        message = "%s\n\n%s" % (stack_trace, request_repr)
  • tests/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_admin
Back to Top