Changeset - 163d1c4f2b8b
[Not reviewed]
default
1 4 0
Mads Kiilerich - 8 years ago 2017-09-14 02:08:07
mads@kiilerich.com
tests: generate test.ini directly from template

Get rid of the committed generated test.ini
5 files changed with 24 insertions and 475 deletions:
0 comments (0 inline, 0 general)
MANIFEST.in
Show inline comments
 
include           .coveragerc
 
include           Apache-License-2.0.txt
 
include           CONTRIBUTORS
 
include           COPYING
 
include           Jenkinsfile
 
include           LICENSE-MERGELY.html
 
include           LICENSE.md
 
include           MIT-Permissive-License.txt
 
include           README.rst
 
include           dev_requirements.txt
 
include           development.ini
 
include           pytest.ini
 
include           requirements.txt
 
include           tox.ini
 
recursive-include docs *
 
recursive-include init.d *
 
recursive-include kallithea/alembic *
 
include           kallithea/bin/ldap_sync.conf
 
include           kallithea/lib/paster_commands/template.ini.mako
 
recursive-include kallithea/i18n *
 
recursive-include kallithea/public *
 
recursive-include kallithea/templates *
 
recursive-include kallithea/tests/fixtures *
 
recursive-include kallithea/tests/scripts *
 
include           kallithea/tests/models/test_dump_html_mails.ref.html
 
include           kallithea/tests/performance/test_vcs.py
 
include           kallithea/tests/test.ini
 
include           kallithea/tests/vcs/aconfig
 
recursive-include scripts *
kallithea/tests/conftest.py
Show inline comments
 
import os
 
import re
 
import sys
 
import logging
 
import pkg_resources
 
import time
 

	
 
import formencode
 
from paste.deploy import loadwsgi
 
from routes.util import URLGenerator
 
import pytest
 
from pytest_localserver.http import WSGIServer
 

	
 
from kallithea.controllers.root import RootController
 
from kallithea.lib import inifile
 
from kallithea.lib.utils import repo2db_mapper
 
from kallithea.model.user import UserModel
 
from kallithea.model.meta import Session
 
from kallithea.model.db import Setting, User, UserIpMap
 
from kallithea.model.scm import ScmModel
 
from kallithea.tests.base import invalidate_all_caches, TEST_USER_REGULAR_LOGIN, TESTS_TMP_PATH, \
 
    TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS
 
import kallithea.tests.base # FIXME: needed for setting testapp instance!!!
 

	
 
from tg.util.webtest import test_context
 

	
 

	
 
def pytest_configure():
 
    os.environ['TZ'] = 'UTC'
 
    if not kallithea.is_windows:
 
        time.tzset() # only available on Unix
 

	
 
    path = os.getcwd()
 
    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)
 

	
 
    with open(os.path.join(path, 'kallithea/tests/test.ini'), 'r') as input_file:
 
        test_ini = input_file.read()
 

	
 
    ini_settings = {
 
        '[server:main]': {
 
            'port': '4999',
 
        },
 
        '[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}',
 
        },
 
        '[handler_console]': {
 
            'formatter': 'color_formatter',
 
        },
 
        # The 'handler_console_sql' block is very similar to the one in
 
        # development.ini, but without the explicit 'level=DEBUG' setting:
 
        # it causes duplicate sqlalchemy debug logs, one through
 
        # handler_console_sql and another through another path.
 
        '[handler_console_sql]': {
 
            'formatter': 'color_formatter_sql',
 
        },
 
    }
 
    if 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)
 
        ini_settings['[app:main]']['sqlalchemy.url'] = os.environ.get('TEST_DB')
 

	
 
    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)
 
    inifile.create(test_ini_file, None, ini_settings)
 

	
 
    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())
 

	
 
    # set KALLITHEA_WHOOSH_TEST_DISABLE=1 to disable whoosh index during tests
 
    if not int(os.environ.get('KALLITHEA_WHOOSH_TEST_DISABLE', 0)):
 
        create_test_index(TESTS_TMP_PATH, context.config(), True)
 

	
 
    kallithea.tests.base.testapp = context.create()
 
    # do initial repo scan
 
    repo2db_mapper(ScmModel().repo_scan(TESTS_TMP_PATH))
 

	
 
    logging.disable(logging.NOTSET)
 

	
 
    kallithea.tests.base.url = URLGenerator(RootController().mapper, {'HTTP_HOST': 'example.com'})
 

	
 
    # set fixed language for form messages, regardless of environment settings
 
    formencode.api.set_stdtranslation(languages=[])
 

	
 

	
 
@pytest.fixture
 
def create_test_user():
 
    """Provide users that automatically disappear after test is over."""
 
    test_user_ids = []
 

	
 
    def _create_test_user(user_form):
 
        user = UserModel().create(user_form)
 
        test_user_ids.append(user.user_id)
 
        return user
 
    yield _create_test_user
 
    for user_id in test_user_ids:
 
        UserModel().delete(user_id)
 
    Session().commit()
 

	
 

	
 
def _set_settings(*kvtseq):
 
    session = Session()
 
    for kvt in kvtseq:
 
        assert len(kvt) in (2, 3)
 
        k = kvt[0]
 
        v = kvt[1]
 
        t = kvt[2] if len(kvt) == 3 else 'unicode'
 
        Setting.create_or_update(k, v, t)
 
    session.commit()
kallithea/tests/test.ini
Show inline comments
 
deleted file
scripts/generate-ini.py
Show inline comments
 
#!/usr/bin/env python2
 
"""
 
Based on kallithea/lib/paster_commands/template.ini.mako, generate
 
  development.ini
 
  kallithea/tests/test.ini
 
"""
 

	
 
import re
 

	
 
from kallithea.lib import inifile
 

	
 
# files to be generated from the mako template
 
ini_files = [
 
    ('kallithea/tests/test.ini',
 
        {
 
            '[server:main]': {
 
                'port': '4999',
 
            },
 
            '[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}',
 
            },
 
            '[handler_console]': {
 
                'formatter': 'color_formatter',
 
            },
 
            # The 'handler_console_sql' block is very similar to the one in
 
            # development.ini, but without the explicit 'level=DEBUG' setting:
 
            # it causes duplicate sqlalchemy debug logs, one through
 
            # handler_console_sql and another through another path.
 
            '[handler_console_sql]': {
 
                'formatter': 'color_formatter_sql',
 
            },
 
        },
 
    ),
 
    ('development.ini',
 
        {
 
            '[server:main]': {
 
                'host': '0.0.0.0',
 
            },
 
            '[app:main]': {
 
                'initial_repo_scan': 'true',
 
                'debug': 'true',
 
                'app_instance_uuid': 'development-not-secret',
 
                'beaker.session.secret': 'development-not-secret',
 
            },
 
            '[handler_console]': {
 
                'formatter': 'color_formatter',
 
            },
 
            '[handler_console_sql]': {
 
                'formatter': 'color_formatter_sql',
 
            },
 
        },
 
    ),
 
]
 

	
 

	
 
def main():
 
    # make sure all mako lines starting with '#' (the '##' comments) are marked up as <text>
 
    makofile = inifile.template_file
 
    print 'reading:', makofile
 
    mako_org = open(makofile).read()
 
    mako_no_text_markup = re.sub(r'</?%text>', '', mako_org)
 
    mako_marked_up = re.sub(r'\n(##.*)', r'\n<%text>\1</%text>', mako_no_text_markup, flags=re.MULTILINE)
 
    if mako_marked_up != mako_org:
 
        print 'writing:', makofile
 
        open(makofile, 'w').write(mako_marked_up)
 

	
 
    # create ini files
 
    for fn, settings in ini_files:
 
        print 'updating:', fn
 
        inifile.create(fn, None, settings)
 

	
 

	
 
if __name__ == '__main__':
 
    main()
scripts/manifest
Show inline comments
 
@@ -873,74 +873,73 @@ kallithea/tests/functional/test_admin_re
 
kallithea/tests/functional/test_admin_repos.py
 
kallithea/tests/functional/test_admin_settings.py
 
kallithea/tests/functional/test_admin_user_groups.py
 
kallithea/tests/functional/test_admin_users.py
 
kallithea/tests/functional/test_branches.py
 
kallithea/tests/functional/test_changelog.py
 
kallithea/tests/functional/test_changeset.py
 
kallithea/tests/functional/test_changeset_comments.py
 
kallithea/tests/functional/test_compare.py
 
kallithea/tests/functional/test_compare_local.py
 
kallithea/tests/functional/test_feed.py
 
kallithea/tests/functional/test_files.py
 
kallithea/tests/functional/test_followers.py
 
kallithea/tests/functional/test_forks.py
 
kallithea/tests/functional/test_home.py
 
kallithea/tests/functional/test_journal.py
 
kallithea/tests/functional/test_login.py
 
kallithea/tests/functional/test_my_account.py
 
kallithea/tests/functional/test_pullrequests.py
 
kallithea/tests/functional/test_repo_groups.py
 
kallithea/tests/functional/test_search.py
 
kallithea/tests/functional/test_summary.py
 
kallithea/tests/functional/test_tags.py
 
kallithea/tests/models/
 
kallithea/tests/models/__init__.py
 
kallithea/tests/models/common.py
 
kallithea/tests/models/test_changeset_status.py
 
kallithea/tests/models/test_diff_parsers.py
 
kallithea/tests/models/test_notifications.py
 
kallithea/tests/models/test_permissions.py
 
kallithea/tests/models/test_repo_groups.py
 
kallithea/tests/models/test_repos.py
 
kallithea/tests/models/test_user_group_permissions_on_repo_groups.py
 
kallithea/tests/models/test_user_groups.py
 
kallithea/tests/models/test_user_permissions_on_repo_groups.py
 
kallithea/tests/models/test_user_permissions_on_repos.py
 
kallithea/tests/models/test_users.py
 
kallithea/tests/other/
 
kallithea/tests/other/__init__.py
 
kallithea/tests/other/manual_test_vcs_operations.py
 
kallithea/tests/other/test_libs.py
 
kallithea/tests/other/test_mail.py
 
kallithea/tests/other/test_validators.py
 
kallithea/tests/scripts/
 
kallithea/tests/scripts/create_rc.sh
 
kallithea/tests/scripts/manual_test_concurrency.py
 
kallithea/tests/scripts/manual_test_crawler.py
 
kallithea/tests/scripts/mem_watch
 
kallithea/tests/test.ini
 
kallithea/tests/vcs/
 
kallithea/tests/vcs/__init__.py
 
kallithea/tests/vcs/aconfig
 
kallithea/tests/vcs/base.py
 
kallithea/tests/vcs/conf.py
 
kallithea/tests/vcs/test_archives.py
 
kallithea/tests/vcs/test_branches.py
 
kallithea/tests/vcs/test_changesets.py
 
kallithea/tests/vcs/test_filenodes_unicode_path.py
 
kallithea/tests/vcs/test_getitem.py
 
kallithea/tests/vcs/test_getslice.py
 
kallithea/tests/vcs/test_git.py
 
kallithea/tests/vcs/test_hg.py
 
kallithea/tests/vcs/test_inmemchangesets.py
 
kallithea/tests/vcs/test_nodes.py
 
kallithea/tests/vcs/test_repository.py
 
kallithea/tests/vcs/test_tags.py
 
kallithea/tests/vcs/test_utils.py
 
kallithea/tests/vcs/test_utils_filesize.py
 
kallithea/tests/vcs/test_vcs.py
 
kallithea/tests/vcs/test_workdirs.py
 
kallithea/tests/vcs/utils.py
 
kallithea/websetup.py
 
setup.cfg
 
setup.py
0 comments (0 inline, 0 general)