Permalink
Browse files

added a test to demonstrate exceptions filtering with a middleware

  • Loading branch information...
1 parent 6aa38d3 commit 874486dfd0e8b0f87d9e2d26d6a47a1822b0b9f2 @flupke committed May 12, 2012
@@ -11,3 +11,9 @@ def process_response(self, request, response):
class BrokenViewMiddleware(object):
def process_view(self, request, func, args, kwargs):
raise ImportError('view')
+
+
+class FilteringMiddleware(object):
+ def process_exception(self, request, exception):
+ if isinstance(exception, IOError):
+ exception.skip_sentry = True
@@ -400,6 +400,14 @@ def test_request_capture(self):
self.assertTrue('SERVER_PORT' in env, env.keys())
self.assertEquals(env['SERVER_PORT'], '80')
+ def test_filtering_middleware(self):
+ with Settings(MIDDLEWARE_CLASSES=['tests.contrib.django.middleware.FilteringMiddleware']):
+ self.assertRaises(IOError, self.client.get, reverse('sentry-raise-ioerror'))
+ self.assertEquals(len(self.raven.events), 0)
+ self.assertRaises(Exception, self.client.get, reverse('sentry-raise-exc'))
+ self.assertEquals(len(self.raven.events), 1)
+ self.raven.events.pop(0)
+
class DjangoLoggingTest(TestCase):
def setUp(self):
@@ -13,8 +13,9 @@ def handler500(request):
url(r'^no-error$', 'tests.contrib.django.views.no_error', name='sentry-no-error'),
url(r'^fake-login$', 'tests.contrib.django.views.fake_login', name='sentry-fake-login'),
url(r'^trigger-500$', 'tests.contrib.django.views.raise_exc', name='sentry-raise-exc'),
+ url(r'^trigger-500-ioerror$', 'tests.contrib.django.views.raise_ioerror', name='sentry-raise-ioerror'),
url(r'^trigger-500-decorated$', 'tests.contrib.django.views.decorated_raise_exc', name='sentry-raise-exc-decor'),
url(r'^trigger-500-django$', 'tests.contrib.django.views.django_exc', name='sentry-django-exc'),
url(r'^trigger-500-template$', 'tests.contrib.django.views.template_exc', name='sentry-template-exc'),
url(r'^trigger-500-log-request$', 'tests.contrib.django.views.logging_request_exc', name='sentry-log-request-exc'),
-)
+)
@@ -17,6 +17,9 @@ def django_exc(request):
def raise_exc(request):
raise Exception(request.GET.get('message', 'view exception'))
+def raise_ioerror(request):
+ raise IOError(request.GET.get('message', 'view exception'))
+
def decorated_raise_exc(request):
return raise_exc(request)
@@ -29,4 +32,4 @@ def logging_request_exc(request):
raise Exception(request.GET.get('message', 'view exception'))
except Exception, e:
logger.error(e, exc_info=True, extra={'request': request})
- return HttpResponse('')
+ return HttpResponse('')

0 comments on commit 874486d

Please sign in to comment.