Changeset - cddff7f0dd08
[Not reviewed]
default
0 3 0
domruf - 8 years ago 2017-08-14 22:34:28
dominikruf@gmail.com
tests: use temporary copy of test.ini, possibly customized for TEST_DB

It was an undocumented feature that if setting the environment variable
TEST_DB, that would be used for tests instead of the default
kallithea/tests/test.ini sqlalchemy.url . That did however not work for Git
hooks and tests would fail.

Instead, create a copy of test.ini in the temp folder and use that for testing.
If TEST_DB is set, edit the file so the specified DB URL is used. This fixes
Git hook related tests if TEST_DB is used.

Since this also changes the path of %(here)s to the temporary location, just
use the default paths.

This also has the advantage that the data folders are now in the temp folder
as well. Therefore a broken data folder, from a past run, can no longer
influence a test.
3 files changed with 18 insertions and 21 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/conftest.py
Show inline comments
 
import os
 
import re
 
import sys
 
import logging
 
import pkg_resources
 
import time
 

	
 
import formencode
 
@@ -31,18 +32,26 @@ def pytest_configure():
 
    sys.path.insert(0, path)
 
    pkg_resources.working_set.add_entry(path)
 

	
 
    # Disable INFO logging of test database creation, restore with NOTSET
 
    logging.disable(logging.INFO)
 

	
 
    context = loadwsgi.loadcontext(loadwsgi.APP, 'config:kallithea/tests/test.ini', relative_to=path)
 
    with open(os.path.join(path, 'kallithea/tests/test.ini'), 'r') as input_file:
 
        test_ini = input_file.read()
 

	
 
    if os.environ.get('TEST_DB'):
 
        # swap config if we pass environment variable
 
        context.local_conf['sqlalchemy.url'] = os.environ.get('TEST_DB')
 
        test_ini = re.sub('^\s*sqlalchemy.url\s*=.*$',
 
                           'sqlalchemy.url = %s' % os.environ.get('TEST_DB'),
 
                           test_ini,
 
                           flags=re.M)
 

	
 
    test_ini_file = os.path.join(TESTS_TMP_PATH, 'test.ini')
 
    with open(test_ini_file, 'w') as output_file:
 
        output_file.write(test_ini)
 

	
 
    context = loadwsgi.loadcontext(loadwsgi.APP, 'config:%s' % test_ini_file)
 
    from kallithea.tests.fixture import create_test_env, create_test_index
 

	
 
    # set KALLITHEA_NO_TMP_PATH=1 to disable re-creating the database and test repos
 
    if not int(os.environ.get('KALLITHEA_NO_TMP_PATH', 0)):
 
        create_test_env(TESTS_TMP_PATH, context.config())
 

	
kallithea/tests/test.ini
Show inline comments
 
@@ -181,24 +181,21 @@ static_files = true
 
## Internationalization (see setup documentation for details)
 
## By default, the language requested by the browser is used if available.
 
#i18n.enable = false
 
## Fallback language, empty for English (valid values are the names of subdirectories in kallithea/i18n):
 
i18n.lang =
 

	
 
#cache_dir = %(here)s/data
 
cache_dir = %(here)s/../../data/test/cache
 
#index_dir = %(here)s/data/index
 
index_dir = %(here)s/../../data/test/index
 
cache_dir = %(here)s/data
 
index_dir = %(here)s/data/index
 

	
 
## perform a full repository scan on each server start, this should be
 
## set to false after first startup, to allow faster server restarts.
 
initial_repo_scan = false
 

	
 
## uncomment and set this path to use archive download cache
 
#archive_cache_dir = %(here)s/tarballcache
 
archive_cache_dir = %(here)s/../../data/test/tarballcache
 
archive_cache_dir = %(here)s/tarballcache
 

	
 
## change this to unique ID for security
 
app_instance_uuid = test
 

	
 
## cut off limit for large diffs (size in bytes)
 
cut_off_limit = 256000
 
@@ -340,16 +337,14 @@ celeryd.max.tasks.per.child = 1
 
celery.always.eager = false
 

	
 
####################################
 
###         BEAKER CACHE        ####
 
####################################
 

	
 
#beaker.cache.data_dir = %(here)s/data/cache/data
 
beaker.cache.data_dir = %(here)s/../../data/test/cache/data
 
#beaker.cache.lock_dir = %(here)s/data/cache/lock
 
beaker.cache.lock_dir = %(here)s/../../data/test/cache/lock
 
beaker.cache.data_dir = %(here)s/data/cache/data
 
beaker.cache.lock_dir = %(here)s/data/cache/lock
 

	
 
beaker.cache.regions = short_term,long_term,sql_cache_short
 

	
 
beaker.cache.short_term.type = memory
 
beaker.cache.short_term.expire = 60
 
beaker.cache.short_term.key_length = 256
 
@@ -496,14 +491,13 @@ logview.pylons.util = #eee
 

	
 
#########################################################
 
### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG    ###
 
#########################################################
 

	
 
# SQLITE [default]
 
#sqlalchemy.url = sqlite:///%(here)s/kallithea.db?timeout=60
 
sqlalchemy.url = sqlite:///%(here)s/kallithea_test.sqlite
 
sqlalchemy.url = sqlite:///%(here)s/kallithea.db?timeout=60
 

	
 
# POSTGRESQL
 
#sqlalchemy.url = postgresql://user:pass@localhost/kallithea
 

	
 
# MySQL
 
#sqlalchemy.url = mysql://user:pass@localhost/kallithea?charset=utf8
scripts/generate-ini.py
Show inline comments
 
@@ -38,18 +38,12 @@ ini_files = [
 
            },
 
            '[app:main]': {
 
                'app_instance_uuid': 'test',
 
                'show_revision_number': 'true',
 
                'beaker.cache.sql_cache_short.expire': '1',
 
                'beaker.session.secret': '{74e0cd75-b339-478b-b129-07dd221def1f}',
 
                'cache_dir': '%(here)s/../../data/test/cache',
 
                'index_dir': '%(here)s/../../data/test/index',
 
                'archive_cache_dir': '%(here)s/../../data/test/tarballcache',
 
                'beaker.cache.data_dir': '%(here)s/../../data/test/cache/data',
 
                'beaker.cache.lock_dir': '%(here)s/../../data/test/cache/lock',
 
                'sqlalchemy.url': 'sqlite:///%(here)s/kallithea_test.sqlite',
 
            },
 
            '[handler_console]': {
 
                'level': 'DEBUG',
 
                'formatter': 'color_formatter',
 
            },
 
            # The 'handler_console_sql' block is very similar to the one in
0 comments (0 inline, 0 general)