@@ -29,12 +29,15 @@ class User(AnonymousUserMixin):
2929 get_id = lambda x : 1
3030
3131
32- def create_app ():
32+ def create_app (ignore_exceptions = None ):
3333 import os
3434
3535 app = Flask (__name__ )
3636 app .config ['SECRET_KEY' ] = os .urandom (40 )
3737
38+ if ignore_exceptions :
39+ app .config ['RAVEN_IGNORE_EXCEPTIONS' ] = ignore_exceptions
40+
3841 @app .route ('/an-error/' , methods = ['GET' , 'POST' ])
3942 def an_error ():
4043 raise ValueError ('hello world' )
@@ -84,6 +87,12 @@ def bind_sentry(self):
8487 self .raven = TempStoreClient ()
8588 self .middleware = Sentry (self .app , client = self .raven )
8689
90+ def make_client_and_raven (self , * args , ** kwargs ):
91+ app = create_app (* args , ** kwargs )
92+ raven = TempStoreClient ()
93+ Sentry (app , client = raven )
94+ return app .test_client (), raven
95+
8796
8897class FlaskTest (BaseTest ):
8998 def test_does_add_to_extensions (self ):
@@ -192,6 +201,27 @@ def test_get_data_handles_disconnected_client(self, lfd):
192201 http = event ['sentry.interfaces.Http' ]
193202 self .assertEqual ({}, http .get ('data' ))
194203
204+ def test_error_handler_with_ignored_exception (self ):
205+ client , raven = self .make_client_and_raven (ignore_exceptions = [NameError , ValueError ])
206+
207+ response = client .get ('/an-error/' )
208+ self .assertEquals (response .status_code , 500 )
209+ self .assertEquals (len (raven .events ), 0 )
210+
211+ def test_error_handler_with_exception_not_ignored (self ):
212+ client , raven = self .make_client_and_raven (ignore_exceptions = [NameError , KeyError ])
213+
214+ response = client .get ('/an-error/' )
215+ self .assertEquals (response .status_code , 500 )
216+ self .assertEquals (len (raven .events ), 1 )
217+
218+ def test_error_handler_with_empty_ignore_exceptions_list (self ):
219+ client , raven = self .make_client_and_raven (ignore_exceptions = [])
220+
221+ response = client .get ('/an-error/' )
222+ self .assertEquals (response .status_code , 500 )
223+ self .assertEquals (len (raven .events ), 1 )
224+
195225
196226class FlaskLoginTest (BaseTest ):
197227 @before
0 commit comments