from pecan import load_app
from webtest import TestApp


def load_test_app(config=None, **kwargs):
    """
    Used for functional tests where you need to test your
    literal application and its integration with the framework.

    :param config: Can be a dictionary containing configuration, a string which
                    represents a (relative) configuration filename or ``None``
                    which will fallback to get the ``PECAN_CONFIG`` env
                    variable.

    returns a pecan.Pecan WSGI application wrapped in a webtest.TestApp
    instance.

    ::
        app = load_test_app('path/to/some/config.py')

        resp = app.get('/path/to/some/resource').status_int
        assert resp.status_int == 200

        resp = app.post('/path/to/some/resource', params={'param': 'value'})
        assert resp.status_int == 302

    Alternatively you could call ``load_test_app`` with no parameters if the
    environment variable is set ::

        app = load_test_app()

        resp = app.get('/path/to/some/resource').status_int
        assert resp.status_int == 200
    """
    return TestApp(load_app(config, **kwargs))

@@ -1,12 +1,22 @@
+import os%0A
 from pecan i
@@ -1156,8 +1156,464 @@
 wargs))%0A
+%0A%0Adef reset_global_config():%0A    %22%22%22%0A    When tests alter application configurations they can get sticky and pollute%0A    other tests that might rely on a pristine configuration. This helper will%0A    reset the config by overwriting it with %60%60pecan.configuration.DEFAULT%60%60.%0A    %22%22%22%0A    from pecan import configuration%0A    configuration.set_config(%0A        dict(configuration.initconf()),%0A        overwrite=True%0A    )%0A    os.environ.pop('PECAN_CONFIG', None)%0A

create a testing utility to reset the global app configuration