From 7eeedebf7b5e7b5642ebae7ee927bb9d836d10d0 Mon Sep 17 00:00:00 2001 From: Martin Bornhold Date: Tue, 27 Sep 2016 09:48:23 +0200 Subject: [PATCH] tests: Add a ``db`` fixture that initializes the database. This is quite useful if tests only need the database and not the whole app. Then only this fixture is needed instead of the full blown pylonsapp/app fixtures. --- rhodecode/tests/plugin.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rhodecode/tests/plugin.py b/rhodecode/tests/plugin.py index b057ff28..a5460f56 100644 --- a/rhodecode/tests/plugin.py +++ b/rhodecode/tests/plugin.py @@ -218,7 +218,7 @@ def app(request, pylonsapp, http_environ): return app -@pytest.fixture() +@pytest.fixture(scope='session') def app_settings(pylonsapp, pylons_config): """ Settings dictionary used to create the app. @@ -234,6 +234,18 @@ def app_settings(pylonsapp, pylons_config): return settings +@pytest.fixture(scope='session') +def db(app_settings): + """ + Initializes the database connection. + + It uses the same settings which are used to create the ``pylonsapp`` or + ``app`` fixtures. + """ + from rhodecode.config.utils import initialize_database + initialize_database(app_settings) + + LoginData = collections.namedtuple('LoginData', ('csrf_token', 'user'))