Show More
@@ -92,6 +92,17 b' Note that on unix systems, the temporary' | |||||
92 | and the test suite creates repositories in the temporary directory. Linux |
|
92 | and the test suite creates repositories in the temporary directory. Linux | |
93 | systems with /tmp mounted noexec will thus fail. |
|
93 | systems with /tmp mounted noexec will thus fail. | |
94 |
|
94 | |||
|
95 | Tests can be run on PostgreSQL like:: | |||
|
96 | ||||
|
97 | sudo -u postgres createuser 'kallithea-test' --pwprompt # password password | |||
|
98 | sudo -u postgres createdb 'kallithea-test' --owner 'kallithea-test' | |||
|
99 | REUSE_TEST_DB='postgresql://kallithea-test:password@localhost/kallithea-test' py.test | |||
|
100 | ||||
|
101 | Tests can be run on MariaDB/MySQL like:: | |||
|
102 | ||||
|
103 | echo "GRANT ALL PRIVILEGES ON \`kallithea-test\`.* TO 'kallithea-test'@'localhost' IDENTIFIED BY 'password'" | sudo -u mysql mysql | |||
|
104 | TEST_DB='mysql://kallithea-test:password@localhost/kallithea-test?charset=utf8' py.test | |||
|
105 | ||||
95 | You can also use ``tox`` to run the tests with all supported Python versions. |
|
106 | You can also use ``tox`` to run the tests with all supported Python versions. | |
96 |
|
107 | |||
97 | When running tests, Kallithea generates a `test.ini` based on template values |
|
108 | When running tests, Kallithea generates a `test.ini` based on template values |
@@ -59,8 +59,12 b' def pytest_configure():' | |||||
59 | 'formatter': 'color_formatter_sql', |
|
59 | 'formatter': 'color_formatter_sql', | |
60 | }, |
|
60 | }, | |
61 | } |
|
61 | } | |
62 | if os.environ.get('TEST_DB'): |
|
62 | create_database = os.environ.get('TEST_DB') # TODO: rename to 'CREATE_TEST_DB' | |
63 | ini_settings['[app:main]']['sqlalchemy.url'] = os.environ.get('TEST_DB') |
|
63 | if create_database: | |
|
64 | ini_settings['[app:main]']['sqlalchemy.url'] = create_database | |||
|
65 | reuse_database = os.environ.get('REUSE_TEST_DB') | |||
|
66 | if reuse_database: | |||
|
67 | ini_settings['[app:main]']['sqlalchemy.url'] = reuse_database | |||
64 |
|
68 | |||
65 | test_ini_file = os.path.join(TESTS_TMP_PATH, 'test.ini') |
|
69 | test_ini_file = os.path.join(TESTS_TMP_PATH, 'test.ini') | |
66 | inifile.create(test_ini_file, None, ini_settings) |
|
70 | inifile.create(test_ini_file, None, ini_settings) | |
@@ -70,7 +74,7 b' def pytest_configure():' | |||||
70 |
|
74 | |||
71 | # set KALLITHEA_NO_TMP_PATH=1 to disable re-creating the database and test repos |
|
75 | # set KALLITHEA_NO_TMP_PATH=1 to disable re-creating the database and test repos | |
72 | if not int(os.environ.get('KALLITHEA_NO_TMP_PATH', 0)): |
|
76 | if not int(os.environ.get('KALLITHEA_NO_TMP_PATH', 0)): | |
73 | create_test_env(TESTS_TMP_PATH, context.config()) |
|
77 | create_test_env(TESTS_TMP_PATH, context.config(), reuse_database=bool(reuse_database)) | |
74 |
|
78 | |||
75 | # set KALLITHEA_WHOOSH_TEST_DISABLE=1 to disable whoosh index during tests |
|
79 | # set KALLITHEA_WHOOSH_TEST_DISABLE=1 to disable whoosh index during tests | |
76 | if not int(os.environ.get('KALLITHEA_WHOOSH_TEST_DISABLE', 0)): |
|
80 | if not int(os.environ.get('KALLITHEA_WHOOSH_TEST_DISABLE', 0)): |
@@ -349,7 +349,7 b' class Fixture(object):' | |||||
349 | # Global test environment setup |
|
349 | # Global test environment setup | |
350 | #============================================================================== |
|
350 | #============================================================================== | |
351 |
|
351 | |||
352 | def create_test_env(repos_test_path, config): |
|
352 | def create_test_env(repos_test_path, config, reuse_database): | |
353 | """ |
|
353 | """ | |
354 | Makes a fresh database and |
|
354 | Makes a fresh database and | |
355 | install test repository into tmp dir |
|
355 | install test repository into tmp dir | |
@@ -366,7 +366,7 b' def create_test_env(repos_test_path, con' | |||||
366 |
|
366 | |||
367 | dbmanage = DbManage(dbconf=dbconf, root=config['here'], |
|
367 | dbmanage = DbManage(dbconf=dbconf, root=config['here'], | |
368 | tests=True) |
|
368 | tests=True) | |
369 | dbmanage.create_tables() |
|
369 | dbmanage.create_tables(reuse_database=reuse_database) | |
370 | # for tests dynamically set new root paths based on generated content |
|
370 | # for tests dynamically set new root paths based on generated content | |
371 | dbmanage.create_settings(dbmanage.prompt_repo_root_path(repos_test_path)) |
|
371 | dbmanage.create_settings(dbmanage.prompt_repo_root_path(repos_test_path)) | |
372 | dbmanage.create_default_user() |
|
372 | dbmanage.create_default_user() |
General Comments 0
You need to be logged in to leave comments.
Login now