1import os 2from pecan import load_app 3from webtest import TestApp 4 5 6def load_test_app(config=None, **kwargs): 7 """ 8 Used for functional tests where you need to test your 9 literal application and its integration with the framework. 10 11 :param config: Can be a dictionary containing configuration, a string which 12 represents a (relative) configuration filename or ``None`` 13 which will fallback to get the ``PECAN_CONFIG`` env 14 variable. 15 16 returns a pecan.Pecan WSGI application wrapped in a webtest.TestApp 17 instance. 18 19 :: 20 app = load_test_app('path/to/some/config.py') 21 22 resp = app.get('/path/to/some/resource').status_int 23 assert resp.status_int == 200 24 25 resp = app.post('/path/to/some/resource', params={'param': 'value'}) 26 assert resp.status_int == 302 27 28 Alternatively you could call ``load_test_app`` with no parameters if the 29 environment variable is set :: 30 31 app = load_test_app() 32 33 resp = app.get('/path/to/some/resource').status_int 34 assert resp.status_int == 200 35 """ 36 return TestApp(load_app(config, **kwargs)) 37 38 39def reset_global_config(): 40 """ 41 When tests alter application configurations they can get sticky and pollute 42 other tests that might rely on a pristine configuration. This helper will 43 reset the config by overwriting it with ``pecan.configuration.DEFAULT``. 44 """ 45 from pecan import configuration 46 configuration.set_config( 47 dict(configuration.initconf()), 48 overwrite=True 49 ) 50 os.environ.pop('PECAN_CONFIG', None) 51