#NEWLINE# def test_request_signals( ) : #NEWLINE# #INDENT# app = flask . Flask ( __name__ ) #NEWLINE# calls = [ ] #NEWLINE# def before_request_signal( sender ) : #NEWLINE# #INDENT# calls . append ( 'before-signal' ) #NEWLINE# #UNINDENT# def after_request_signal( sender , response ) : #NEWLINE# #INDENT# assert ( response . data == b'stuff' ) #NEWLINE# calls . append ( 'after-signal' ) #NEWLINE# #UNINDENT# @ app . before_request #NEWLINE# def before_request_handler( ) : #NEWLINE# #INDENT# calls . append ( 'before-handler' ) #NEWLINE# #UNINDENT# @ app . after_request #NEWLINE# def after_request_handler( response ) : #NEWLINE# #INDENT# calls . append ( 'after-handler' ) #NEWLINE# response . data = 'stuff' #NEWLINE# return response #NEWLINE# #UNINDENT# @ app . route ( '/' ) #NEWLINE# def index( ) : #NEWLINE# #INDENT# calls . append ( 'handler' ) #NEWLINE# return 'ignored anyway' #NEWLINE# #UNINDENT# flask . request_started . connect ( before_request_signal , app ) #NEWLINE# flask . request_finished . connect ( after_request_signal , app ) #NEWLINE# try : #NEWLINE# #INDENT# rv = app . test_client ( ) . get ( '/' ) #NEWLINE# assert ( rv . data == b'stuff' ) #NEWLINE# assert ( calls == [ 'before-signal' , 'before-handler' , 'handler' , 'after-handler' , 'after-signal' ] ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# flask . request_started . disconnect ( before_request_signal , app ) #NEWLINE# flask . request_finished . disconnect ( after_request_signal , app )