Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added exception tests for logbook and logging modules

  • Loading branch information...
commit c5aaec2a544841c1855500c7b7c506f7ae24c10a 1 parent 5afc6ab
@dcramer authored gandalfar committed
View
24 tests/test_contrib/test_logbook.py
@@ -25,3 +25,27 @@ def test_simple(self):
tags = dict(event.tags)
self.assertTrue('level' in tags)
self.assertEquals(tags['level'], 'warning')
+
+ def test_exception(self):
+ logger = Logger('sentry.tests.test_contrib.test_logbook')
+ handler = SentryHandler('INFO')
+ with handler.applicationbound():
+ try:
+ raise ValueError('foo')
+ except:
+ logger.exception('foo bar')
+
+ event = Event.objects.all()[0]
+
+ self.assertEquals(event.type, 'sentry.events.Exception')
+ self.assertEquals(event.time_spent, 0)
+ self.assertTrue('sentry.interfaces.Exception' in event.data)
+ event_data = event.data['sentry.interfaces.Exception']
+ self.assertTrue('type' in event_data)
+ self.assertEquals(event_data['type'], 'ValueError')
+ self.assertTrue('value' in event_data)
+ self.assertEquals(event_data['value'], 'foo')
+
+ tags = dict(event.tags)
+ self.assertTrue('level' in tags)
+ self.assertEquals(tags['level'], 'error')
View
27 tests/test_contrib/test_logging.py
@@ -29,3 +29,30 @@ def test_simple(self):
tags = dict(event.tags)
self.assertTrue('level' in tags)
self.assertEquals(tags['level'], 'info')
+
+ def test_exception(self):
+ handler = SentryHandler()
+
+ logger = logging.getLogger('sentry.tests.test_contrib.test_logging')
+ logger.setLevel(logging.INFO)
+ logger.addHandler(handler)
+
+ try:
+ raise ValueError('foo')
+ except:
+ logger.exception('foo bar')
+
+ event = Event.objects.all()[0]
+
+ self.assertEquals(event.type, 'sentry.events.Exception')
+ self.assertEquals(event.time_spent, 0)
+ self.assertTrue('sentry.interfaces.Exception' in event.data)
+ event_data = event.data['sentry.interfaces.Exception']
+ self.assertTrue('type' in event_data)
+ self.assertEquals(event_data['type'], 'ValueError')
+ self.assertTrue('value' in event_data)
+ self.assertEquals(event_data['value'], 'foo')
+
+ tags = dict(event.tags)
+ self.assertTrue('level' in tags)
+ self.assertEquals(tags['level'], 'error')
Please sign in to comment.
Something went wrong with that request. Please try again.