diff options
| author | Aymeric Augustin | 2013-11-01 21:51:37 +0100 |
|---|---|---|
| committer | Aymeric Augustin | 2013-11-01 21:51:37 +0100 |
| commit | 96f1cb4b0d4b10903502e917ddaa460bc05f5ca3 (patch) | |
| tree | 2d72e912b523f498f7e1c82aad362d5e6a58f396 /tests/panels/test_logger.py | |
| parent | f69f51f7abf25aaf5282c953475e8975694f41c1 (diff) | |
| download | django-debug-toolbar-96f1cb4b0d4b10903502e917ddaa460bc05f5ca3.tar.bz2 | |
Split tests across several modules.
Fix #426.
Diffstat (limited to 'tests/panels/test_logger.py')
| -rw-r--r-- | tests/panels/test_logger.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/panels/test_logger.py b/tests/panels/test_logger.py new file mode 100644 index 0000000..477d100 --- /dev/null +++ b/tests/panels/test_logger.py @@ -0,0 +1,53 @@ +from __future__ import unicode_literals + +import logging + +from debug_toolbar.panels.logger import ( + LoggingPanel, MESSAGE_IF_STRING_REPRESENTATION_INVALID) + +from ..base import BaseTestCase + + +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']) |
