# HG changeset patch # User Johannes Bornhold # Date 2016-06-07 07:31:33 # Node ID 0652b43fd39f0457f12a28d1d82506397439e234 # Parent be1c5590879fdead55872dab4c20ec0ea5ce458b db: Move initialization of test environment up to pyramid layer. diff --git a/rhodecode/config/environment.py b/rhodecode/config/environment.py --- a/rhodecode/config/environment.py +++ b/rhodecode/config/environment.py @@ -112,18 +112,6 @@ def load_environment(global_conf, app_co # sets the c attribute access when don't existing attribute are accessed config['pylons.strict_tmpl_context'] = True - config_file_name = os.path.split(config['__file__'])[-1] - test = re.match('^test[\w_]*\.ini$', config_file_name) is not None - if test: - if test_env is None: - test_env = not int(os.environ.get('RC_NO_TMP_PATH', 0)) - - from rhodecode.lib.utils import create_test_env, create_test_index - from rhodecode.tests import TESTS_TMP_PATH - # test repos - if test_env: - create_test_env(TESTS_TMP_PATH, config) - create_test_index(TESTS_TMP_PATH, config, True) # Limit backends to "vcs.backends" from configuration backends = config['vcs.backends'] = aslist( diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -157,14 +157,22 @@ def make_pyramid_app(global_config, **se # behavior in the old application. settings_pylons = settings.copy() - # TODO: Remove this by refactoring the init DB function. - # Put debug flag into settings for DB setup. - settings['debug'] = global_config.get('debug', False) - utils.initialize_database(settings) + # Some parts of the code expect a merge of global and app settings. + settings_merged = global_config.copy() + settings_merged.update(settings) sanitize_settings_and_apply_defaults(settings) config = Configurator(settings=settings) add_pylons_compat_data(config.registry, global_config, settings_pylons) + + # Initialize the database connection. + utils.initialize_database(settings_merged) + + # If this is a test run we prepare the test environment like + # creating a test database, test search index and test repositories. + if settings['is_test']: + utils.initialize_test_environment(settings_merged) + includeme(config) includeme_last(config) pyramid_app = config.make_wsgi_app() diff --git a/rhodecode/config/utils.py b/rhodecode/config/utils.py --- a/rhodecode/config/utils.py +++ b/rhodecode/config/utils.py @@ -73,6 +73,18 @@ def initialize_database(config): init_model(engine, encryption_key=config['beaker.session.secret']) +def initialize_test_environment(settings, test_env=None): + if test_env is None: + test_env = not int(os.environ.get('RC_NO_TMP_PATH', 0)) + + from rhodecode.lib.utils import create_test_env, create_test_index + from rhodecode.tests import TESTS_TMP_PATH + # test repos + if test_env: + create_test_env(TESTS_TMP_PATH, settings) + create_test_index(TESTS_TMP_PATH, settings, True) + + def get_vcs_server_protocol(config): protocol = config.get('vcs.server.protocol', 'pyro4') return protocol diff --git a/rhodecode/lib/utils.py b/rhodecode/lib/utils.py --- a/rhodecode/lib/utils.py +++ b/rhodecode/lib/utils.py @@ -755,10 +755,10 @@ def create_test_env(repos_test_path, con # PART TWO make test repo log.debug('making test vcs repositories') - idx_path = config['app_conf']['search.location'] - data_path = config['app_conf']['cache_dir'] + idx_path = config['search.location'] + data_path = config['cache_dir'] - #clean index and data + # clean index and data if idx_path and os.path.exists(idx_path): log.debug('remove %s', idx_path) shutil.rmtree(idx_path) @@ -767,7 +767,7 @@ def create_test_env(repos_test_path, con log.debug('remove %s', data_path) shutil.rmtree(data_path) - #CREATE DEFAULT TEST REPOS + # CREATE DEFAULT TEST REPOS cur_dir = dn(dn(abspath(__file__))) with tarfile.open(jn(cur_dir, 'tests', 'fixtures', 'vcs_test_hg.tar.gz')) as tar: @@ -787,7 +787,6 @@ def create_test_env(repos_test_path, con tar.extractall(jn(TESTS_TMP_PATH, SVN_REPO)) - #============================================================================== # PASTER COMMANDS #==============================================================================