aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin2013-10-18 03:22:49 -0700
committerAymeric Augustin2013-10-18 03:22:49 -0700
commit4b8eb92d1297d300218767a9a23a40ab40362fae (patch)
tree51320d2fb64566d11da1022950d83b0a65505929 /tests
parentf3a2e0b48d97b72cad9c79b48880f2a265be2e2d (diff)
parentddac484aa76176cc9cb783bd6137c85fa3e7ff0a (diff)
downloaddjango-debug-toolbar-4b8eb92d1297d300218767a9a23a40ab40362fae.tar.bz2
Merge pull request #415 from Bouke/tickets/151
Fix #151 -- Logging panel fails on invalid string representations
Diffstat (limited to 'tests')
-rw-r--r--tests/tests.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/tests.py b/tests/tests.py
index 1571800..aac41bd 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -2,6 +2,7 @@
from __future__ import unicode_literals
+import logging
import threading
import django
@@ -15,6 +16,8 @@ from django.utils import six
from django.utils import unittest
from debug_toolbar.middleware import DebugToolbarMiddleware
+from debug_toolbar.panels.logger import (LoggingPanel,
+ MESSAGE_IF_STRING_REPRESENTATION_INVALID)
from debug_toolbar.panels.sql import SQLDebugPanel
from debug_toolbar.panels.request_vars import RequestVarsDebugPanel
from debug_toolbar.panels.template import TemplateDebugPanel
@@ -287,3 +290,47 @@ class TemplatePanelTestCase(BaseTestCase):
ctx = template_panel.templates[0]['context'][base_ctx_idx]
self.assertIn('<<queryset of auth.User>>', ctx)
self.assertIn('<<triggers database query>>', ctx)
+
+
+class LoggingPanelTestCase(BaseTestCase):
+ def test_happy_case(self):
+ logger = logging.getLogger(__name__)
+ logger.info('Nothing to see here, move along!')
+
+ logging_panel = self.toolbar.get_panel(LoggingPanel)
+ logging_panel.process_response(None, None)
+ records = logging_panel.get_stats()['records']
+
+ self.assertEqual(1, len(records))
+ self.assertEqual('Nothing to see here, move along!',
+ records[0]['message'])
+
+ def test_formatting(self):
+ logger = logging.getLogger(__name__)
+ logger.info('There are %d %s', 5, 'apples')
+
+ logging_panel = self.toolbar.get_panel(LoggingPanel)
+ logging_panel.process_response(None, None)
+ records = logging_panel.get_stats()['records']
+
+ self.assertEqual(1, len(records))
+ self.assertEqual('There are 5 apples',
+ records[0]['message'])
+
+ def test_failing_formatting(self):
+ class BadClass(object):
+ def __str__(self):
+ raise Exception('Please not stringify me!')
+
+ logger = logging.getLogger(__name__)
+
+ # should not raise exception, but fail silently
+ logger.debug('This class is misbehaving: %s', BadClass())
+
+ logging_panel = self.toolbar.get_panel(LoggingPanel)
+ logging_panel.process_response(None, None)
+ records = logging_panel.get_stats()['records']
+
+ self.assertEqual(1, len(records))
+ self.assertEqual(MESSAGE_IF_STRING_REPRESENTATION_INVALID,
+ records[0]['message'])