Skip to content

Commit

Permalink
Added test for auto dropping schema when tenant deleted. Closes #378.
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardopires committed Sep 29, 2016
1 parent 97d42a1 commit dc442f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions tenant_schemas/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ class NonAutoSyncTenant(TenantMixin):

class Meta:
app_label = 'tenant_schemas'


class AutoDropTenant(TenantMixin):
auto_drop_schema = True

class Meta:
app_label = 'tenant_schemas'
22 changes: 20 additions & 2 deletions tenant_schemas/tests/test_tenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dts_test_app.models import DummyModel, ModelWithFkToPublicUser

from tenant_schemas.test.cases import TenantTestCase
from tenant_schemas.tests.models import Tenant, NonAutoSyncTenant
from tenant_schemas.tests.models import Tenant, NonAutoSyncTenant, AutoDropTenant
from tenant_schemas.tests.testcases import BaseTestCase
from tenant_schemas.utils import tenant_context, schema_context, schema_exists, get_tenant_model, get_public_schema_name

Expand Down Expand Up @@ -47,7 +47,7 @@ def test_non_auto_sync_tenant(self):
self.assertFalse(schema_exists('non_auto_sync_tenant'))

tenant = NonAutoSyncTenant(domain_url='something.test.com',
schema_name='test')
schema_name='non_auto_sync_tenant')
tenant.save(verbosity=BaseTestCase.get_verbosity())

self.assertFalse(schema_exists(tenant.schema_name))
Expand Down Expand Up @@ -76,6 +76,24 @@ def test_sync_tenant(self):
# test if data is still there
self.assertEquals(DummyModel.objects.count(), 2)

def test_auto_drop_schema(self):
"""
When deleting a tenant with auto_drop_schema=True, it should delete
the schema associated with the tenant.
"""
self.assertFalse(schema_exists('auto_drop_tenant'))
tenant = AutoDropTenant(domain_url='something.test.com',
schema_name='auto_drop_tenant')
tenant.save(verbosity=BaseTestCase.get_verbosity())
self.assertTrue(schema_exists(tenant.schema_name))
cursor = connection.cursor()

# Force pending trigger events to be executed
cursor.execute('SET CONSTRAINTS ALL IMMEDIATE')

tenant.delete()
self.assertFalse(schema_exists(tenant.schema_name))

def test_switching_search_path(self):
tenant1 = Tenant(domain_url='something.test.com',
schema_name='tenant1')
Expand Down

0 comments on commit dc442f4

Please sign in to comment.