Skip to content

Commit

Permalink
Provide a quick reference to the Flask app on functional tests
Browse files Browse the repository at this point in the history
Wrap the webtest.TestApp in a class that provides a flask_app property
so it can be used like this:

    app = self._get_test_app()
        with app.flask_app.test_request_context():
            offset = url_for(...
  • Loading branch information
amercader committed May 26, 2016
1 parent 8d2418f commit 5e38a9a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ckan/tests/helpers.py
Expand Up @@ -140,6 +140,21 @@ def call_auth(auth_name, context, **kwargs):
return logic.check_access(auth_name, context, data_dict=kwargs)


class CKANTestApp(webtest.TestApp):
'''A wrapper around webtest.TestApp
It adds some convenience methods for CKAN
'''

_flask_app = None

@property
def flask_app(self):
if not self._flask_app:
self._flask_app = find_flask_app(self)
return self._flask_app


def _get_test_app():
'''Return a webtest.TestApp for CKAN, with legacy templates disabled.
Expand All @@ -149,7 +164,7 @@ def _get_test_app():
'''
config['ckan.legacy_templates'] = False
app = ckan.config.middleware.make_app(config['global_conf'], **config)
app = webtest.TestApp(app)
app = CKANTestApp(app)
return app


Expand Down

0 comments on commit 5e38a9a

Please sign in to comment.