# HG changeset patch # User Anton Schur # Date 1493195370 -10800 # Node ID 6cc40e545e9a73186003620a2ad2afda4b9b2089 # Parent 865c1f65244c2044c13e1172974177f420a9ecb4 test: move test environment initialization from the main code to tests diff -r 865c1f65244c -r 6cc40e545e9a kallithea/config/app_cfg.py --- a/kallithea/config/app_cfg.py Thu Mar 23 23:49:19 2017 +0100 +++ b/kallithea/config/app_cfg.py Wed Apr 26 11:29:30 2017 +0300 @@ -150,25 +150,6 @@ load_rcextensions(root_path=config['here']) - # FIXME move test setup code out of here - test = os.path.split(config['__file__'])[-1] == 'test.ini' - if test: - test_env = not int(os.environ.get('KALLITHEA_NO_TMP_PATH', 0)) - test_index = not int(os.environ.get('KALLITHEA_WHOOSH_TEST_DISABLE', 0)) - if os.environ.get('TEST_DB'): - # swap config if we pass environment variable - config['sqlalchemy.url'] = os.environ.get('TEST_DB') - - from kallithea.tests.fixture import create_test_env, create_test_index - from kallithea.tests.base import TESTS_TMP_PATH - #set KALLITHEA_NO_TMP_PATH=1 to disable re-creating the database and - #test repos - if test_env: - create_test_env(TESTS_TMP_PATH, config) - #set KALLITHEA_WHOOSH_TEST_DISABLE=1 to disable whoosh index during tests - if test_index: - create_test_index(TESTS_TMP_PATH, config, True) - set_available_permissions(config) repos_path = make_ui('db').configitems('paths')[0][1] config['base_path'] = repos_path diff -r 865c1f65244c -r 6cc40e545e9a kallithea/tests/conftest.py --- a/kallithea/tests/conftest.py Thu Mar 23 23:49:19 2017 +0100 +++ b/kallithea/tests/conftest.py Wed Apr 26 11:29:30 2017 +0300 @@ -3,9 +3,8 @@ import logging import pkg_resources -from paste.deploy import loadapp +from paste.deploy import loadwsgi from routes.util import URLGenerator -from tg import config import pytest from kallithea.controllers.root import RootController @@ -24,7 +23,26 @@ # Disable INFO logging of test database creation, restore with NOTSET logging.disable(logging.INFO) - kallithea.tests.base.testapp = loadapp('config:kallithea/tests/test.ini', relative_to=path) + + context = loadwsgi.loadcontext(loadwsgi.APP, 'config:kallithea/tests/test.ini', relative_to=path) + + test_env = not int(os.environ.get('KALLITHEA_NO_TMP_PATH', 0)) + test_index = not int(os.environ.get('KALLITHEA_WHOOSH_TEST_DISABLE', 0)) + if os.environ.get('TEST_DB'): + # swap config if we pass environment variable + context.local_conf['sqlalchemy.url'] = os.environ.get('TEST_DB') + + from kallithea.tests.fixture import create_test_env, create_test_index + from kallithea.tests.base import TESTS_TMP_PATH + # set KALLITHEA_NO_TMP_PATH=1 to disable re-creating the database and + # test repos + if test_env: + create_test_env(TESTS_TMP_PATH, context.config()) + # set KALLITHEA_WHOOSH_TEST_DISABLE=1 to disable whoosh index during tests + if test_index: + create_test_index(TESTS_TMP_PATH, context.config(), True) + + kallithea.tests.base.testapp = context.create() logging.disable(logging.NOTSET) kallithea.tests.base.url = URLGenerator(RootController().mapper, kallithea.tests.base.environ) diff -r 865c1f65244c -r 6cc40e545e9a kallithea/tests/fixture.py --- a/kallithea/tests/fixture.py Thu Mar 23 23:49:19 2017 +0100 +++ b/kallithea/tests/fixture.py Wed Apr 26 11:29:30 2017 +0300 @@ -342,8 +342,8 @@ # PART TWO make test repo log.debug('making test vcs repositories') - idx_path = config['app_conf']['index_dir'] - data_path = config['app_conf']['cache_dir'] + idx_path = config['index_dir'] + data_path = config['cache_dir'] #clean index and data if idx_path and os.path.exists(idx_path): @@ -376,7 +376,7 @@ from kallithea.lib.indexers.daemon import WhooshIndexingDaemon from kallithea.lib.pidlock import DaemonLock, LockHeld - index_location = os.path.join(config['app_conf']['index_dir']) + index_location = os.path.join(config['index_dir']) if not os.path.exists(index_location): os.makedirs(index_location)