Changeset - 6cc40e545e9a
[Not reviewed]
default
0 3 0
Anton Schur - 9 years ago 2017-04-26 10:29:30
tonich.sh@gmail.com
test: move test environment initialization from the main code to tests
3 files changed with 24 insertions and 25 deletions:
0 comments (0 inline, 0 general)
kallithea/config/app_cfg.py
Show inline comments
 
@@ -150,25 +150,6 @@ def setup_configuration(app):
 

	
 
    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
kallithea/tests/conftest.py
Show inline comments
 
@@ -3,9 +3,8 @@ import sys
 
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 @@ def pytest_configure():
 

	
 
    # 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)
kallithea/tests/fixture.py
Show inline comments
 
@@ -342,8 +342,8 @@ def create_test_env(repos_test_path, con
 
    # 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 @@ def create_test_index(repo_location, con
 
    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)
 

	
0 comments (0 inline, 0 general)