tox: fixed inconsistent / obscure db names during tests (#67933)
This commit is contained in:
parent
1c02ad4517
commit
5e5125c97d
|
@ -1,19 +1,20 @@
|
|||
import hashlib
|
||||
import os
|
||||
|
||||
|
||||
def get_safe_db_name(prefix):
|
||||
def get_safe_db_name():
|
||||
"""
|
||||
PostgreSQL database name limit is 68 characters, which can become
|
||||
PostgreSQL database name limit is 63 characters, which can become
|
||||
an issue during testing, because we need to build a unique
|
||||
database name using the branch and tox env.
|
||||
database name using the branch name and tox env.
|
||||
|
||||
Ergo, the following code to ensure the database name is always shorter than 68
|
||||
characters.
|
||||
Also, when running tests in parallel through `tox -p`,
|
||||
pytest django append the tox env name automatically
|
||||
through a fixture so we have to skip this step.
|
||||
"""
|
||||
BRANCH_NAME = os.environ.get('BRANCH_NAME', '').replace('/', '-')
|
||||
TOX_ENV_NAME = os.environ.get('TOX_ENV_NAME')
|
||||
DB_NAME = '_'.join([part for part in [prefix, BRANCH_NAME, TOX_ENV_NAME] if part])
|
||||
DB_NAME = hashlib.sha256(DB_NAME.encode()).hexdigest()[:10]
|
||||
|
||||
return DB_NAME
|
||||
BRANCH_NAME = os.environ.get('BRANCH_NAME', '').replace('/', '-')[:15]
|
||||
parts = [BRANCH_NAME]
|
||||
if not os.environ.get("TOX_PARALLEL_ENV"):
|
||||
# when we're in parallel mode, pytest-django will do this
|
||||
# for us at a later point
|
||||
parts.append(os.environ.get('TOX_ENV_NAME'))
|
||||
return '_'.join(parts)
|
||||
|
|
|
@ -21,7 +21,7 @@ HOBO_MANAGER_HOMEPAGE_URL_VAR = 'portal_agent_url'
|
|||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': os.environ.get('DB_ENGINE', 'django.db.backends.sqlite3'),
|
||||
'NAME': hobo.test_utils.get_safe_db_name('test-hobo'),
|
||||
'NAME': hobo.test_utils.get_safe_db_name(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ open_backup = open
|
|||
with patch.object(builtins, 'open', mock_open(read_data=b'xxx')):
|
||||
exec(open_backup(os.environ['DEBIAN_CONFIG_COMMON']).read())
|
||||
|
||||
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name('test-authentic')
|
||||
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name()
|
||||
|
||||
# Avoid conflic with real tenants
|
||||
# that might exist in /var/lib/authentic2_multitenant/tenants
|
||||
|
|
|
@ -14,7 +14,7 @@ open_backup = open
|
|||
with patch.object(builtins, 'open', mock_open(read_data=b'xxx')):
|
||||
exec(open_backup(os.path.join(os.path.dirname(__file__), '../debian/debian_config_common.py')).read())
|
||||
|
||||
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name('test-multipublik')
|
||||
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name()
|
||||
|
||||
CACHES = {
|
||||
'default': {
|
||||
|
|
|
@ -52,7 +52,7 @@ open_backup = open
|
|||
with patch.object(builtins, 'open', mock_open(read_data=b'xxx')):
|
||||
exec(open_backup(os.path.join(os.path.dirname(__file__), '../debian/debian_config_common.py')).read())
|
||||
|
||||
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name('test-multitenant')
|
||||
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name()
|
||||
|
||||
TENANT_APPS = (
|
||||
'django.contrib.auth',
|
||||
|
|
|
@ -18,7 +18,7 @@ with patch.object(builtins, 'open', mock_open(read_data=b'xxx')):
|
|||
exec(open_backup(os.environ['DEBIAN_CONFIG_COMMON']).read())
|
||||
|
||||
BRANCH_NAME = os.environ.get("BRANCH_NAME", "").replace('/', '-')[:15]
|
||||
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name('test-passerelle')
|
||||
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name()
|
||||
|
||||
# Avoid conflic with real tenants
|
||||
# that might exist in /var/lib/passerelle/tenants
|
||||
|
|
|
@ -12,7 +12,7 @@ BRANCH_NAME = (
|
|||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'tenant_schemas.postgresql_backend',
|
||||
'NAME': hobo.test_utils.get_safe_db_name('test-schemas'),
|
||||
'NAME': hobo.test_utils.get_safe_db_name(),
|
||||
}
|
||||
}
|
||||
DATABASE_ROUTERS = ('tenant_schemas.routers.TenantSyncRouter',)
|
||||
|
|
Loading…
Reference in New Issue