Reuse db schema instead of recreating it fro mscratch during tests (#67914)
This commit is contained in:
parent
d2b5a32997
commit
274b6eabde
|
@ -1,7 +1,9 @@
|
|||
import json
|
||||
import os
|
||||
|
||||
import django.db.utils
|
||||
import pytest
|
||||
from django.core.management import call_command
|
||||
from django.db import connection, transaction
|
||||
from django_webtest import DjangoTestApp, WebTestMixin
|
||||
from tenant_schemas.postgresql_backend.base import FakeTenant
|
||||
|
@ -74,18 +76,28 @@ def tenant_factory(transactional_db, tenant_base, settings):
|
|||
schema_name = name.replace('-', '_').replace('.', '_')
|
||||
t = Tenant(domain_url=name, schema_name=schema_name)
|
||||
with transaction.atomic():
|
||||
t.create_schema()
|
||||
t.create_schema(check_if_exists=True)
|
||||
connection.set_schema_to_public()
|
||||
tenants.append(t)
|
||||
return t
|
||||
|
||||
try:
|
||||
|
||||
yield factory
|
||||
finally:
|
||||
# cleanup all created tenants
|
||||
connection.set_schema_to_public()
|
||||
with tenant_context(FakeTenant('public')):
|
||||
for tenant in tenants:
|
||||
tenant.delete(force_drop=True)
|
||||
with tenant_context(tenant):
|
||||
call_command(
|
||||
"flush",
|
||||
verbosity=0,
|
||||
interactive=False,
|
||||
database='default',
|
||||
reset_sequences=False,
|
||||
allow_cascade=True,
|
||||
inhibit_post_migrate=False,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
4
tox.ini
4
tox.ini
|
@ -5,8 +5,8 @@
|
|||
[tox]
|
||||
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/hobo/{env:BRANCH_NAME:}
|
||||
envlist =
|
||||
py3-django22-drf39-{hobo,multipublik,multitenant,schemas,authentic,passerelle}
|
||||
py3-django22-drf312-coverage-{hobo,multipublik,multitenant,schemas,authentic,passerelle}
|
||||
py3-django22-drf39-{hobo,authentic,multipublik,multitenant,schemas,passerelle}
|
||||
py3-django22-drf312-coverage-{hobo,authentic,multipublik,multitenant,schemas,passerelle}
|
||||
py3-black
|
||||
|
||||
[testenv]
|
||||
|
|
Loading…
Reference in New Issue