0002-Speed-up-authentic-provisionning-tests.patch
tests_authentic/conftest.py | ||
---|---|---|
1 | 1 |
import json |
2 | 2 |
import os |
3 | 3 | |
4 |
import django.db.utils |
|
4 | 5 |
import pytest |
6 |
from django.core.management import call_command |
|
5 | 7 |
from django.db import connection, transaction |
6 | 8 |
from django_webtest import DjangoTestApp, WebTestMixin |
7 | 9 |
from tenant_schemas.postgresql_backend.base import FakeTenant |
... | ... | |
74 | 76 |
schema_name = name.replace('-', '_').replace('.', '_') |
75 | 77 |
t = Tenant(domain_url=name, schema_name=schema_name) |
76 | 78 |
with transaction.atomic(): |
77 |
t.create_schema() |
|
79 |
t.create_schema(check_if_exists=True) |
|
80 |
connection.set_schema_to_public() |
|
78 | 81 |
tenants.append(t) |
79 | 82 |
return t |
80 | 83 | |
81 | 84 |
try: |
85 | ||
82 | 86 |
yield factory |
83 | 87 |
finally: |
84 | 88 |
# cleanup all created tenants |
85 | 89 |
connection.set_schema_to_public() |
86 |
with tenant_context(FakeTenant('public')): |
|
87 |
for tenant in tenants: |
|
88 |
tenant.delete(force_drop=True) |
|
90 |
for tenant in tenants: |
|
91 |
with tenant_context(tenant): |
|
92 |
call_command( |
|
93 |
"flush", |
|
94 |
verbosity=0, |
|
95 |
interactive=False, |
|
96 |
database='default', |
|
97 |
reset_sequences=False, |
|
98 |
allow_cascade=True, |
|
99 |
inhibit_post_migrate=False, |
|
100 |
) |
|
89 | 101 | |
90 | 102 | |
91 | 103 |
@pytest.fixture |
92 |
- |