0001-tox-fixed-inconsistent-obscure-db-names-during-tests.patch
hobo/test_utils.py | ||
---|---|---|
1 |
import hashlib |
|
2 | 1 |
import os |
3 | 2 | |
4 | 3 | |
5 |
def get_safe_db_name(prefix):
|
|
4 |
def get_safe_db_name(): |
|
6 | 5 |
""" |
7 | 6 |
PostgreSQL database name limit is 68 characters, which can become |
8 | 7 |
an issue during testing, because we need to build a unique |
9 |
database name using the branch and tox env. |
|
8 |
database name using the branch name and tox env.
|
|
10 | 9 | |
11 |
Ergo, the following code to ensure the database name is always shorter than 68 |
|
12 |
characters. |
|
10 |
Also, when running tests in parallel through `tox -p`, |
|
11 |
pytest django append the tox env name automatically |
|
12 |
through a fixture so we have to skip this step. |
|
13 | 13 |
""" |
14 |
BRANCH_NAME = os.environ.get('BRANCH_NAME', '').replace('/', '-') |
|
15 |
TOX_ENV_NAME = os.environ.get('TOX_ENV_NAME') |
|
16 |
DB_NAME = '_'.join([part for part in [prefix, BRANCH_NAME, TOX_ENV_NAME] if part]) |
|
17 |
DB_NAME = hashlib.sha256(DB_NAME.encode()).hexdigest()[:10] |
|
18 | ||
19 |
return DB_NAME |
|
14 |
BRANCH_NAME = os.environ.get('BRANCH_NAME', '').replace('/', '-')[:15] |
|
15 |
parts = [BRANCH_NAME] |
|
16 |
if not os.environ.get("TOX_PARALLEL_ENV"): |
|
17 |
# when we're in parallel mode, pytest-django will do this |
|
18 |
# for us at a later point |
|
19 |
parts.append(os.environ.get('TOX_ENV_NAME')) |
|
20 |
return '_'.join(parts) |
tests/settings.py | ||
---|---|---|
21 | 21 |
DATABASES = { |
22 | 22 |
'default': { |
23 | 23 |
'ENGINE': os.environ.get('DB_ENGINE', 'django.db.backends.sqlite3'), |
24 |
'NAME': hobo.test_utils.get_safe_db_name('test-hobo'),
|
|
24 |
'NAME': hobo.test_utils.get_safe_db_name(), |
|
25 | 25 |
} |
26 | 26 |
} |
27 | 27 |
tests_authentic/settings.py | ||
---|---|---|
15 | 15 |
with patch.object(builtins, 'open', mock_open(read_data=b'xxx')): |
16 | 16 |
exec(open_backup(os.environ['DEBIAN_CONFIG_COMMON']).read()) |
17 | 17 | |
18 |
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name('test-authentic')
|
|
18 |
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name() |
|
19 | 19 | |
20 | 20 |
# Avoid conflic with real tenants |
21 | 21 |
# that might exist in /var/lib/authentic2_multitenant/tenants |
tests_multipublik/settings.py | ||
---|---|---|
14 | 14 |
with patch.object(builtins, 'open', mock_open(read_data=b'xxx')): |
15 | 15 |
exec(open_backup(os.path.join(os.path.dirname(__file__), '../debian/debian_config_common.py')).read()) |
16 | 16 | |
17 |
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name('test-multipublik')
|
|
17 |
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name() |
|
18 | 18 | |
19 | 19 |
CACHES = { |
20 | 20 |
'default': { |
tests_multitenant/settings.py | ||
---|---|---|
52 | 52 |
with patch.object(builtins, 'open', mock_open(read_data=b'xxx')): |
53 | 53 |
exec(open_backup(os.path.join(os.path.dirname(__file__), '../debian/debian_config_common.py')).read()) |
54 | 54 | |
55 |
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name('test-multitenant')
|
|
55 |
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name() |
|
56 | 56 | |
57 | 57 |
TENANT_APPS = ( |
58 | 58 |
'django.contrib.auth', |
tests_passerelle/settings.py | ||
---|---|---|
18 | 18 |
exec(open_backup(os.environ['DEBIAN_CONFIG_COMMON']).read()) |
19 | 19 | |
20 | 20 |
BRANCH_NAME = os.environ.get("BRANCH_NAME", "").replace('/', '-')[:15] |
21 |
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name('test-passerelle')
|
|
21 |
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name() |
|
22 | 22 | |
23 | 23 |
# Avoid conflic with real tenants |
24 | 24 |
# that might exist in /var/lib/passerelle/tenants |
tests_schemas/settings.py | ||
---|---|---|
12 | 12 |
DATABASES = { |
13 | 13 |
'default': { |
14 | 14 |
'ENGINE': 'tenant_schemas.postgresql_backend', |
15 |
'NAME': hobo.test_utils.get_safe_db_name('test-schemas'),
|
|
15 |
'NAME': hobo.test_utils.get_safe_db_name(), |
|
16 | 16 |
} |
17 | 17 |
} |
18 | 18 |
DATABASE_ROUTERS = ('tenant_schemas.routers.TenantSyncRouter',) |
19 |
- |