33 lines
938 B
Python
33 lines
938 B
Python
import os
|
|
import tempfile
|
|
import shutil
|
|
import json
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
def tenants(transactional_db, request, settings):
|
|
from hobo.multitenant.models import Tenant
|
|
base = tempfile.mkdtemp('combo-tenant-base')
|
|
settings.TENANT_BASE = base
|
|
@pytest.mark.django_db
|
|
def make_tenant(name):
|
|
tenant_dir = os.path.join(base, name)
|
|
os.mkdir(tenant_dir)
|
|
with open(os.path.join(tenant_dir, 'unsecure'), 'w') as fd:
|
|
fd.write('1')
|
|
t = Tenant(domain_url=name,
|
|
schema_name=name.replace('-', '_').replace('.', '_'))
|
|
t.create_schema()
|
|
return t
|
|
tenants = [make_tenant('tenant1.example.net')]
|
|
def fin():
|
|
from django.db import connection
|
|
connection.set_schema_to_public()
|
|
for t in tenants:
|
|
t.delete(True)
|
|
shutil.rmtree(base)
|
|
request.addfinalizer(fin)
|
|
return tenants
|