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')
def emit(self, record): try: count = new_email() except Exception: traceback.print_exc() else: if count >= self.throttle: return AdminEmailHandler.emit(self, record)
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")
def test_emit_no_form_tag(self): """HTML email doesn't contain forms.""" handler = AdminEmailHandler(include_html=True) record = self.logger.makeRecord( 'name', logging.ERROR, 'function', 'lno', 'message', None, None, ) handler.emit(record) self.assertEqual(len(mail.outbox), 1) msg = mail.outbox[0] self.assertEqual(msg.subject, '[Django] ERROR: message') self.assertEqual(len(msg.alternatives), 1) body_html = str(msg.alternatives[0][0]) self.assertIn('<div id="traceback">', body_html) self.assertNotIn('<form', body_html)
def fire_email(self, record, exc_info=None): mail_handler = AdminEmailHandler(include_html=self.include_html) mail_handler.emit(record) mail_handler.emit(JiraRecord(record, exc_info))