#NEWLINE# @ patch ( 'bugsnag.notification.deliver' ) #NEWLINE# def test_bugsnag_middleware_closes_iterables( self , deliver ) : #NEWLINE# #INDENT# class CrashOnCloseIterable ( object ) : #NEWLINE# #INDENT# def __init__( self , environ , start_response ) : #NEWLINE# #INDENT# start_response ( '200 OK' , [ ( 'Content-Type' , 'text/plain; charset=utf-8' ) ] ) #NEWLINE# #UNINDENT# def __iter__( self ) : #NEWLINE# #INDENT# ( yield 'OK' ) #NEWLINE# #UNINDENT# def close( self ) : #NEWLINE# #INDENT# raise SentinelError ( 'oops' ) #NEWLINE# #UNINDENT# #UNINDENT# app = TestApp ( BugsnagMiddleware ( CrashOnCloseIterable ) ) #NEWLINE# self . assertRaises ( SentinelError , ( lambda : app . get ( '/beans' ) ) ) #NEWLINE# self . assertEqual ( deliver . call_count , 1 ) #NEWLINE# payload = deliver . call_args [ 0 ] [ 0 ] #NEWLINE# environ = payload [ 'events' ] [ 0 ] [ 'metaData' ] [ 'environment' ] #NEWLINE# self . assertEqual ( environ [ 'PATH_INFO' ] , '/beans' )