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.
This commit is contained in:
Martin Bornhold 2016-09-27 09:48:23 +02:00
parent ae2b380d5b
commit 7eeedebf7b

View file

@ -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'))