changeset 6621:6cc40e545e9a

test: move test environment initialization from the main code to tests
author Anton Schur <tonich.sh@gmail.com>
date Wed, 26 Apr 2017 11:29:30 +0300
parents 865c1f65244c
children ff287676b206
files kallithea/config/app_cfg.py kallithea/tests/conftest.py kallithea/tests/fixture.py
diffstat 3 files changed, 24 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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)
--- 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)