Tests are now compatible with Django 1.7

This commit is contained in:
Bernardo Pires 2015-01-05 12:33:10 +01:00
parent ac3876d168
commit 267c9f1e3b
3 changed files with 27 additions and 16 deletions

View File

@ -1,6 +1,8 @@
import django
from django.conf import settings
from django.core.management.base import CommandError, BaseCommand
from tenant_schemas.utils import django_is_in_test_mode
try:
from south.management.commands.migrate import Command as MigrateCommand
except ImportError:
@ -19,6 +21,6 @@ class Command(MigrateCommand):
super(Command, self).handle(*args, **options)
if django.VERSION >= (1, 7, 0):
if django.VERSION >= (1, 7, 0) and django_is_in_test_mode():
from .migrate_schemas import MigrateSchemasCommand
Command = MigrateSchemasCommand

View File

@ -1,3 +1,4 @@
import django
from django.conf import settings
from django.contrib.auth.models import User
from django.db import connection
@ -120,6 +121,7 @@ class TenantSyncTest(BaseTestCase):
Tests if the shared apps and the tenant apps get synced correctly
depending on if the public schema or a tenant is being synced.
"""
MIGRATION_TABLE_SIZE = 1 if django.VERSION >= (1, 7, 0) else 0
def test_shared_apps_does_not_sync_tenant_apps(self):
"""
@ -134,7 +136,7 @@ class TenantSyncTest(BaseTestCase):
self.sync_shared()
shared_tables = self.get_tables_list_in_schema(get_public_schema_name())
self.assertEqual(2+6+1, len(shared_tables))
self.assertEqual(2+6+1+self.MIGRATION_TABLE_SIZE, len(shared_tables))
self.assertNotIn('django_session', shared_tables)
def test_tenant_apps_does_not_sync_shared_apps(self):
@ -152,7 +154,7 @@ class TenantSyncTest(BaseTestCase):
tenant.save()
tenant_tables = self.get_tables_list_in_schema(tenant.schema_name)
self.assertEqual(1, len(tenant_tables))
self.assertEqual(1+self.MIGRATION_TABLE_SIZE, len(tenant_tables))
self.assertIn('django_session', tenant_tables)
def test_tenant_apps_and_shared_apps_can_have_the_same_apps(self):
@ -172,9 +174,9 @@ class TenantSyncTest(BaseTestCase):
shared_tables = self.get_tables_list_in_schema(get_public_schema_name())
tenant_tables = self.get_tables_list_in_schema(tenant.schema_name)
self.assertEqual(2+6+1+1, len(shared_tables))
self.assertIn('django_session', tenant_tables)
self.assertEqual(1, len(tenant_tables))
self.assertEqual(2+6+1+1+self.MIGRATION_TABLE_SIZE, len(shared_tables))
self.assertIn('django_session', shared_tables)
self.assertEqual(1+self.MIGRATION_TABLE_SIZE, len(tenant_tables))
self.assertIn('django_session', tenant_tables)
def test_content_types_is_not_mandatory(self):
@ -192,9 +194,9 @@ class TenantSyncTest(BaseTestCase):
shared_tables = self.get_tables_list_in_schema(get_public_schema_name())
tenant_tables = self.get_tables_list_in_schema(tenant.schema_name)
self.assertEqual(2+1, len(shared_tables))
self.assertEqual(2+1+self.MIGRATION_TABLE_SIZE, len(shared_tables))
self.assertIn('django_session', tenant_tables)
self.assertEqual(1, len(tenant_tables))
self.assertEqual(1+self.MIGRATION_TABLE_SIZE, len(tenant_tables))
self.assertIn('django_session', tenant_tables)

View File

@ -1,3 +1,4 @@
import django
from django.conf import settings
from django.core.management import call_command
from django.db import connection
@ -42,11 +43,17 @@ class BaseTestCase(TestCase):
@classmethod
def sync_shared(cls):
call_command('sync_schemas',
schema_name=get_public_schema_name(),
tenant=False,
public=True,
interactive=False,
migrate_all=True,
verbosity=0,
)
if django.VERSION >= (1, 7, 0):
call_command('migrate_schemas',
schema_name=get_public_schema_name(),
interactive=False,
verbosity=0)
else:
call_command('sync_schemas',
schema_name=get_public_schema_name(),
tenant=False,
public=True,
interactive=False,
migrate_all=True,
verbosity=0,
)