<s> """<STR_LIT>""" <EOL> import flask <EOL> import unittest <EOL> from flask . testsuite import FlaskTestCase <EOL> class SignalsTestCase ( FlaskTestCase ) : <EOL> def test_template_rendered ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return flask . render_template ( '<STR_LIT>' , whiskey = <NUM_LIT> ) <EOL> recorded = [ ] <EOL> def record ( sender , template , context ) : <EOL> recorded . append ( ( template , context ) ) <EOL> flask . template_rendered . connect ( record , app ) <EOL> try : <EOL> app . test_client ( ) . get ( '<STR_LIT:/>' ) <EOL> self . assert_equal ( len ( recorded ) , <NUM_LIT:1> ) <EOL> template , context = recorded [ <NUM_LIT:0> ] <EOL> self . assert_equal ( template . name , '<STR_LIT>' ) <EOL> self . assert_equal ( context [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> finally : <EOL> flask . template_rendered . disconnect ( record , app ) <EOL> def test_request_signals ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> calls = [ ] <EOL> def before_request_signal ( sender ) : <EOL> calls . append ( '<STR_LIT>' ) <EOL> def after_request_signal ( sender , response ) : <EOL> self . assert_equal ( response . data , '<STR_LIT>' ) <EOL> calls . append ( '<STR_LIT>' ) <EOL> @ app . before_request <EOL> def before_request_handler ( ) : <EOL> calls . append ( '<STR_LIT>' ) <EOL> @ app . after_request <EOL> def after_request_handler ( response ) : <EOL> calls . append ( '<STR_LIT>' ) <EOL> response . data = '<STR_LIT>' <EOL> return response <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> calls . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> flask . request_started . connect ( before_request_signal , app ) <EOL> flask . request_finished . connect ( after_request_signal , app ) <EOL> try : <EOL> rv = app . test_client ( ) . get ( '<STR_LIT:/>' ) <EOL> self . assert_equal ( rv . data , '<STR_LIT>' ) <EOL> self . assert_equal ( calls , [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> finally : <EOL> flask . request_started . disconnect ( before_request_signal , app ) <EOL> flask . request_finished . disconnect ( after_request_signal , app ) <EOL> def test_request_exception_signal ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> recorded = [ ] <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> def record ( sender , exception ) : <EOL> recorded . append ( exception ) <EOL> flask . got_request_exception . connect ( record , app ) <EOL> try : <EOL> self . assert_equal ( app . test_client ( ) . get ( '<STR_LIT:/>' ) . status_code , <NUM_LIT> ) <EOL> self . assert_equal ( len ( recorded ) , <NUM_LIT:1> ) <EOL> self . assert_ ( isinstance ( recorded [ <NUM_LIT:0> ] , ZeroDivisionError ) ) <EOL> finally : <EOL> flask . got_request_exception . disconnect ( record , app ) <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> if flask . signals_available : <EOL> suite . addTest ( unittest . makeSuite ( SignalsTestCase ) ) <EOL> return suite </s>
