<s> """<STR_LIT>""" <EOL> from __future__ import with_statement <EOL> import flask <EOL> import unittest <EOL> from flask . testsuite import FlaskTestCase <EOL> class AppContextTestCase ( FlaskTestCase ) : <EOL> def test_basic_url_generation ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> app . config [ '<STR_LIT>' ] = '<STR_LIT:localhost>' <EOL> app . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> pass <EOL> with app . app_context ( ) : <EOL> rv = flask . url_for ( '<STR_LIT:index>' ) <EOL> self . assert_equal ( rv , '<STR_LIT>' ) <EOL> def test_url_generation_requires_server_name ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> with app . app_context ( ) : <EOL> with self . assert_raises ( RuntimeError ) : <EOL> flask . url_for ( '<STR_LIT:index>' ) <EOL> def test_url_generation_without_context_fails ( self ) : <EOL> with self . assert_raises ( RuntimeError ) : <EOL> flask . url_for ( '<STR_LIT:index>' ) <EOL> def test_request_context_means_app_context ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> with app . test_request_context ( ) : <EOL> self . assert_equal ( flask . current_app . _get_current_object ( ) , app ) <EOL> self . assert_equal ( flask . _app_ctx_stack . top , None ) <EOL> def test_app_context_provides_current_app ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> with app . app_context ( ) : <EOL> self . assert_equal ( flask . current_app . _get_current_object ( ) , app ) <EOL> self . assert_equal ( flask . _app_ctx_stack . top , None ) <EOL> def test_app_tearing_down ( self ) : <EOL> cleanup_stuff = [ ] <EOL> app = flask . Flask ( __name__ ) <EOL> @ app . teardown_appcontext <EOL> def cleanup ( exception ) : <EOL> cleanup_stuff . append ( exception ) <EOL> with app . app_context ( ) : <EOL> pass <EOL> self . assert_equal ( cleanup_stuff , [ None ] ) <EOL> def test_custom_request_globals_class ( self ) : <EOL> class CustomRequestGlobals ( object ) : <EOL> def __init__ ( self ) : <EOL> self . spam = '<STR_LIT>' <EOL> app = flask . Flask ( __name__ ) <EOL> app . request_globals_class = CustomRequestGlobals <EOL> with app . test_request_context ( ) : <EOL> self . assert_equal ( <EOL> flask . render_template_string ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_context_refcounts ( self ) : <EOL> called = [ ] <EOL> app = flask . Flask ( __name__ ) <EOL> @ app . teardown_request <EOL> def teardown_req ( error = None ) : <EOL> called . append ( '<STR_LIT>' ) <EOL> @ app . teardown_appcontext <EOL> def teardown_app ( error = None ) : <EOL> called . append ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> with flask . _app_ctx_stack . top : <EOL> with flask . _request_ctx_stack . top : <EOL> pass <EOL> self . assert_ ( flask . _request_ctx_stack . request . environ <EOL> [ '<STR_LIT>' ] is not None ) <EOL> c = app . test_client ( ) <EOL> c . get ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( called , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( unittest . makeSuite ( AppContextTestCase ) ) <EOL> return suite </s>
