I have multi-tenant applications in django with postgresql schemas. I tried to write test code inside a tenant folder "t002" as:
from django.test import TestCase
from path.customers.models import Client
# TestClass to test tenant setup
class TestTenantSetup(TestCase):
def setUp(self):
Client.objects.create(
name='t002',
schema_name='t002',
domain_url='t002.cmpny.com'
)
def test_tenant_exists(self):
client = Client.objects.get(name='t002')
self.assertEquals(client.schema_name, "t002")
But when I ran the test with python manage.py test path/t002/tests it was creating a test database for my actual database. So let's say I would follow this SO answer (django unit tests without a db) and avoid creating database, but I am not sure if I'm following the right path to test a multi-tenant django project. When I looked into the django-tenant-schemas docs (https://django-tenant-schemas.readthedocs.io/en/latest/test.html) I couldn't get my hands on it easily. Can anybody tell how start doing test for django multi-tenant applications ? And please do review the above code too whether it is right or wrong.
Specs - python==2.7, django==1.11, postgres==9.6
from How to write tests for django multi tenant applications?
No comments:
Post a Comment