File: conftest.py

package info (click to toggle)
python-django-pgschemas 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 848 kB
  • sloc: python: 3,887; makefile: 33; sh: 10; sql: 2
file content (72 lines) | stat: -rw-r--r-- 1,653 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from io import StringIO

import pytest


@pytest.fixture(scope="session", autouse=True)
def setup(django_db_setup, django_db_blocker):
    from sandbox.shared_public.models import Tenant

    with django_db_blocker.unblock():
        Tenant.objects.get_or_create(schema_name="tenant1")
        Tenant.objects.get_or_create(schema_name="tenant2")
        Tenant.objects.get_or_create(schema_name="tenant3")


@pytest.fixture(autouse=True, params=["static-only", "tenants-no-domains", "tenants-and-domains"])
def tenants_settings(request, settings):
    from copy import deepcopy

    current = deepcopy(settings.TENANTS)

    if request.param == "static-only":
        del settings.TENANTS["default"]

    if request.param == "tenants-no-domains":
        del settings.TENANTS["default"]["DOMAIN_MODEL"]

    yield settings.TENANTS

    settings.TENANTS.clear()
    settings.TENANTS.update(current)


@pytest.fixture
def TenantModel():
    from django_pgschemas.utils import get_tenant_model

    return get_tenant_model()


@pytest.fixture
def DomainModel():
    from django_pgschemas.utils import get_domain_model

    return get_domain_model()


@pytest.fixture
def tenant1(db):
    from sandbox.shared_public.models import Tenant

    return Tenant.objects.get(schema_name="tenant1")


@pytest.fixture
def tenant2(db):
    from sandbox.shared_public.models import Tenant

    return Tenant.objects.get(schema_name="tenant2")


@pytest.fixture
def tenant3(db):
    from sandbox.shared_public.models import Tenant

    return Tenant.objects.get(schema_name="tenant3")


@pytest.fixture
def stdout():
    with StringIO() as buffer:
        yield buffer