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 json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import django.db.utils
|
||||||
import pytest
|
import pytest
|
||||||
|
from django.core.management import call_command
|
||||||
from django.db import connection, transaction
|
from django.db import connection, transaction
|
||||||
from django_webtest import DjangoTestApp, WebTestMixin
|
from django_webtest import DjangoTestApp, WebTestMixin
|
||||||
from tenant_schemas.postgresql_backend.base import FakeTenant
|
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('.', '_')
|
schema_name = name.replace('-', '_').replace('.', '_')
|
||||||
t = Tenant(domain_url=name, schema_name=schema_name)
|
t = Tenant(domain_url=name, schema_name=schema_name)
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
t.create_schema()
|
t.create_schema(check_if_exists=True)
|
||||||
|
connection.set_schema_to_public()
|
||||||
tenants.append(t)
|
tenants.append(t)
|
||||||
return t
|
return t
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
yield factory
|
yield factory
|
||||||
finally:
|
finally:
|
||||||
# cleanup all created tenants
|
# cleanup all created tenants
|
||||||
connection.set_schema_to_public()
|
connection.set_schema_to_public()
|
||||||
with tenant_context(FakeTenant('public')):
|
for tenant in tenants:
|
||||||
for tenant in tenants:
|
with tenant_context(tenant):
|
||||||
tenant.delete(force_drop=True)
|
call_command(
|
||||||
|
"flush",
|
||||||
|
verbosity=0,
|
||||||
|
interactive=False,
|
||||||
|
database='default',
|
||||||
|
reset_sequences=False,
|
||||||
|
allow_cascade=True,
|
||||||
|
inhibit_post_migrate=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
4
tox.ini
4
tox.ini
|
@ -5,8 +5,8 @@
|
||||||
[tox]
|
[tox]
|
||||||
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/hobo/{env:BRANCH_NAME:}
|
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/hobo/{env:BRANCH_NAME:}
|
||||||
envlist =
|
envlist =
|
||||||
py3-django22-drf39-{hobo,multipublik,multitenant,schemas,authentic,passerelle}
|
py3-django22-drf39-{hobo,authentic,multipublik,multitenant,schemas,passerelle}
|
||||||
py3-django22-drf312-coverage-{hobo,multipublik,multitenant,schemas,authentic,passerelle}
|
py3-django22-drf312-coverage-{hobo,authentic,multipublik,multitenant,schemas,passerelle}
|
||||||
py3-black
|
py3-black
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
|
|
Loading…
Reference in New Issue