本文整理汇总了Python中tenant_schemas.tests.models.Tenant类的典型用法代码示例。如果您正苦于以下问题:Python Tenant类的具体用法?Python Tenant怎么用?Python Tenant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tenant类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_auto_drop_schema_bulk_delete
def test_auto_drop_schema_bulk_delete(self):
"""
When bulk deleting tenants, it should also drop the schemas of
tenants that have auto_drop_schema set to True.
"""
Tenant.auto_drop_schema = True
schemas = ['auto_drop_schema1', 'auto_drop_schema2']
for schema in schemas:
self.assertFalse(schema_exists(schema))
tenant = Tenant(
domain_url='%s.test.com' % schema,
schema_name=schema
)
tenant.save(verbosity=BaseTestCase.get_verbosity())
self.assertTrue(schema_exists(tenant.schema_name))
# Force pending trigger events to be executed
cursor = connection.cursor()
cursor.execute('SET CONSTRAINTS ALL IMMEDIATE')
# get a queryset of our 2 tenants and do a bulk delete
Tenant.objects.filter(schema_name__in=schemas).delete()
# verify that the schemas where deleted
for schema in schemas:
self.assertFalse(schema_exists(schema))
Tenant.auto_drop_schema = False
开发者ID:ArtProcessors,项目名称:django-tenant-schemas,代码行数:28,代码来源:test_tenants.py
示例2: test_tenant_schema_is_created
def test_tenant_schema_is_created(self):
"""
When saving a tenant, it's schema should be created.
"""
tenant = Tenant(domain_url='something.test.com', schema_name='test')
tenant.save()
self.assertTrue(schema_exists(tenant.schema_name))
开发者ID:MatheusCampello,项目名称:django-tenant-schemas,代码行数:8,代码来源:test_tenants.py
示例3: test_switching_tenant_without_previous_tenant
def test_switching_tenant_without_previous_tenant(self):
tenant = Tenant(domain_url='something.test.com', schema_name='test')
tenant.save()
connection.tenant = None
with tenant_context(tenant):
DummyModel(name="No exception please").save()
connection.tenant = None
with schema_context(tenant.schema_name):
DummyModel(name="Survived it!").save()
开发者ID:MatheusCampello,项目名称:django-tenant-schemas,代码行数:11,代码来源:test_tenants.py
示例4: RoutesTestCase
class RoutesTestCase(TransactionTestCase):
@classmethod
def setUpClass(cls):
settings.TENANT_APPS = ('tenant_schemas', 'django.contrib.contenttypes', 'django.contrib.auth', )
def setUp(self):
self.factory = RequestFactory()
self.tm = TenantMiddleware()
# settings needs some patching
settings.TENANT_MODEL = 'tenant_schemas.Tenant'
settings.PUBLIC_SCHEMA_URL_TOKEN = '/public'
# add the public tenant
self.public_tenant_domain = 'test.com'
self.public_tenant = Tenant(domain_url=self.public_tenant_domain, schema_name='public')
self.public_tenant.save()
# add a test tenant
self.tenant_domain = 'tenant.test.com'
self.tenant = Tenant(domain_url=self.tenant_domain, schema_name='test')
self.tenant.save()
def tearDown(self):
Tenant.objects.all().delete()
def test_tenant_routing(self):
"""
request path should not be altered
"""
request_url = '/any/request/'
request = self.factory.get('/any/request/', HTTP_HOST=self.tenant_domain)
self.tm.process_request(request)
self.assertEquals(request.path_info, request_url)
# request.tenant should also have been set
self.assertEquals(request.tenant, self.tenant)
def test_public_schema_routing(self):
"""
request path should get prepended with PUBLIC_SCHEMA_URL_TOKEN
"""
request_url = '/any/request/'
request = self.factory.get('/any/request/', HTTP_HOST=self.public_tenant_domain)
self.tm.process_request(request)
self.assertEquals(request.path_info, settings.PUBLIC_SCHEMA_URL_TOKEN + request_url)
# request.tenant should also have been set
self.assertEquals(request.tenant, self.public_tenant)
开发者ID:MontmereLimited,项目名称:django-tenant-schemas,代码行数:51,代码来源:routes.py
示例5: RoutesTestCase
class RoutesTestCase(BaseTestCase):
@classmethod
def setUpClass(cls):
super(RoutesTestCase, cls).setUpClass()
settings.SHARED_APPS = ('tenant_schemas', )
settings.TENANT_APPS = ('dts_test_app',
'django.contrib.contenttypes',
'django.contrib.auth', )
settings.INSTALLED_APPS = settings.SHARED_APPS + settings.TENANT_APPS
cls.sync_shared()
cls.public_tenant = Tenant(domain_url='test.com', schema_name=get_public_schema_name())
cls.public_tenant.save(verbosity=BaseTestCase.get_verbosity())
def setUp(self):
super(RoutesTestCase, self).setUp()
self.factory = RequestFactory()
self.tm = TenantMiddleware()
self.tenant_domain = 'tenant.test.com'
self.tenant = Tenant(domain_url=self.tenant_domain, schema_name='test')
self.tenant.save(verbosity=BaseTestCase.get_verbosity())
def test_tenant_routing(self):
"""
Request path should not be altered.
"""
request_url = '/any/request/'
request = self.factory.get('/any/request/',
HTTP_HOST=self.tenant_domain)
self.tm.process_request(request)
self.assertEquals(request.path_info, request_url)
# request.tenant should also have been set
self.assertEquals(request.tenant, self.tenant)
def test_public_schema_routing(self):
"""
Request path should not be altered.
"""
request_url = '/any/request/'
request = self.factory.get('/any/request/',
HTTP_HOST=self.public_tenant.domain_url)
self.tm.process_request(request)
self.assertEquals(request.path_info, request_url)
# request.tenant should also have been set
self.assertEquals(request.tenant, self.public_tenant)
开发者ID:bernardopires,项目名称:django-tenant-schemas,代码行数:49,代码来源:test_routes.py
示例6: setUp
def setUp(self):
super(CeleryTasksTests, self).setUp()
self.tenant1 = Tenant(domain_url='test1', schema_name='test1')
self.tenant1.save()
self.tenant2 = Tenant(domain_url='test2', schema_name='test2')
self.tenant2.save()
connection.set_tenant(self.tenant1)
self.dummy1 = DummyModel.objects.create(name='test1')
connection.set_tenant(self.tenant2)
self.dummy2 = DummyModel.objects.create(name='test2')
connection.set_schema_to_public()
开发者ID:bufke,项目名称:tenant-schemas-celery,代码行数:15,代码来源:tests.py
示例7: RoutesTestCase
class RoutesTestCase(TestCase):
def setUp(self):
self.factory = RequestFactory()
self.tm = TenantMiddleware()
# settings needs some patching
settings.TENANT_MODEL = 'tenant_schemas.Tenant'
settings.TENANT_URL_TOKEN = '/tenant'
# add the public tenant
self.public_tenant_domain = 'test.com'
self.public_tenant = Tenant(domain_url=self.public_tenant_domain, schema_name='public')
self.public_tenant.save()
# add a test tenant
self.tenant_domain = 'tenant.test.com'
self.tenant = Tenant(domain_url=self.tenant_domain, schema_name='test')
self.tenant.save()
def tearDown(self):
Tenant.objects.all().delete()
def test_tenant_routing(self):
"""
request path should get prepended with TENANT_URL_TOKEN
"""
request_url = '/any/request/'
request = self.factory.get('/any/request/', HTTP_HOST=self.tenant_domain)
self.tm.process_request(request)
self.assertEquals(request.path_info, settings.TENANT_URL_TOKEN + request_url)
# request.tenant should also have been set
self.assertEquals(request.tenant, self.tenant)
def test_public_schema_routing(self):
"""
request path should not be altered, tenant should be the public one
"""
request_url = '/any/request/'
request = self.factory.get('/any/request/', HTTP_HOST=self.public_tenant_domain)
self.tm.process_request(request)
self.assertEquals(request.path_info, request_url)
# request.tenant should also have been set
self.assertEquals(request.tenant, self.public_tenant)
开发者ID:rctay,项目名称:django-tenant-schemas,代码行数:47,代码来源:routes.py
示例8: setUp
def setUp(self):
super(RoutesTestCase, self).setUp()
self.factory = RequestFactory()
self.tm = TenantMiddleware()
self.tenant_domain = 'tenant.test.com'
self.tenant = Tenant(domain_url=self.tenant_domain, schema_name='test')
self.tenant.save()
开发者ID:MichaelBechard,项目名称:django-tenant-schemas,代码行数:8,代码来源:routes.py
示例9: setUp
def setUp(self):
self.factory = RequestFactory()
self.tm = TenantMiddleware()
# settings needs some patching
settings.TENANT_MODEL = 'tenant_schemas.Tenant'
settings.PUBLIC_SCHEMA_URL_TOKEN = '/public'
# add the public tenant
self.public_tenant_domain = 'test.com'
self.public_tenant = Tenant(domain_url=self.public_tenant_domain, schema_name='public')
self.public_tenant.save()
# add a test tenant
self.tenant_domain = 'tenant.test.com'
self.tenant = Tenant(domain_url=self.tenant_domain, schema_name='test')
self.tenant.save()
开发者ID:acmeguy,项目名称:django-tenant-schemas,代码行数:17,代码来源:routes.py
示例10: test_tenant_apps_does_not_sync_shared_apps
def test_tenant_apps_does_not_sync_shared_apps(self):
"""
Tests that if an app is in TENANT_APPS, it does not get synced to
the public schema.
"""
settings.SHARED_APPS = ('tenant_schemas',
'django.contrib.auth',
'django.contrib.contenttypes', )
settings.TENANT_APPS = ('django.contrib.sessions', ) # 1 table
settings.INSTALLED_APPS = settings.SHARED_APPS + settings.TENANT_APPS
self.sync_shared()
tenant = Tenant(domain_url='arbitrary.test.com', schema_name='test')
tenant.save()
tenant_tables = self.get_tables_list_in_schema(tenant.schema_name)
self.assertEqual(1+self.MIGRATION_TABLE_SIZE, len(tenant_tables))
self.assertIn('django_session', tenant_tables)
开发者ID:MatheusCampello,项目名称:django-tenant-schemas,代码行数:17,代码来源:test_tenants.py
示例11: test_auto_drop_schema
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.auto_drop_schema = True
tenant = Tenant(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))
Tenant.auto_drop_schema = False
开发者ID:bernardopires,项目名称:django-tenant-schemas,代码行数:19,代码来源:test_tenants.py
示例12: test_content_types_is_not_mandatory
def test_content_types_is_not_mandatory(self):
"""
Tests that even if content types is in SHARED_APPS, it's
not required in TENANT_APPS.
"""
settings.SHARED_APPS = ('tenant_schemas', # 2 tables
'django.contrib.contenttypes', ) # 1 table
settings.TENANT_APPS = ('django.contrib.sessions', ) # 1 table
settings.INSTALLED_APPS = settings.SHARED_APPS + settings.TENANT_APPS
self.sync_shared()
tenant = Tenant(domain_url='something.test.com', schema_name='test')
tenant.save()
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+self.MIGRATION_TABLE_SIZE, len(shared_tables))
self.assertIn('django_session', tenant_tables)
self.assertEqual(1+self.MIGRATION_TABLE_SIZE, len(tenant_tables))
self.assertIn('django_session', tenant_tables)
开发者ID:MatheusCampello,项目名称:django-tenant-schemas,代码行数:19,代码来源:test_tenants.py
示例13: setUp
def setUp(self):
# settings needs some patching
settings.TENANT_MODEL = 'tenant_schemas.Tenant'
# add the public tenant
self.public_tenant_domain = 'test.com'
self.public_tenant = Tenant(domain_url=self.public_tenant_domain,
schema_name='public')
self.public_tenant.save()
connection.set_schema_to_public()
开发者ID:10clouds,项目名称:django-tenant-schemas,代码行数:11,代码来源:tenants.py
示例14: test_tenant_apps_and_shared_apps_can_have_the_same_apps
def test_tenant_apps_and_shared_apps_can_have_the_same_apps(self):
"""
Tests that both SHARED_APPS and TENANT_APPS can have apps in common.
In this case they should get synced to both tenant and public schemas.
"""
settings.SHARED_APPS = ('tenant_schemas', # 2 tables
'django.contrib.auth', # 6 tables
'django.contrib.contenttypes', # 1 table
'django.contrib.sessions', ) # 1 table
settings.TENANT_APPS = ('django.contrib.sessions', ) # 1 table
settings.INSTALLED_APPS = settings.SHARED_APPS + settings.TENANT_APPS
self.sync_shared()
tenant = Tenant(domain_url='arbitrary.test.com', schema_name='test')
tenant.save()
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+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)
开发者ID:MatheusCampello,项目名称:django-tenant-schemas,代码行数:21,代码来源:test_tenants.py
示例15: test_switching_search_path
def test_switching_search_path(self):
tenant1 = Tenant(domain_url='something.test.com',
schema_name='tenant1')
tenant1.save()
connection.set_schema_to_public()
tenant2 = Tenant(domain_url='example.com', schema_name='tenant2')
tenant2.save()
# go to tenant1's path
connection.set_tenant(tenant1)
# add some data, 2 DummyModels for tenant1
DummyModel(name="Schemas are").save()
DummyModel(name="awesome!").save()
# switch temporarily to tenant2's path
with tenant_context(tenant2):
# add some data, 3 DummyModels for tenant2
DummyModel(name="Man,").save()
DummyModel(name="testing").save()
DummyModel(name="is great!").save()
# we should be back to tenant1's path, test what we have
self.assertEqual(2, DummyModel.objects.count())
# switch back to tenant2's path
with tenant_context(tenant2):
self.assertEqual(3, DummyModel.objects.count())
开发者ID:MatheusCampello,项目名称:django-tenant-schemas,代码行数:29,代码来源:test_tenants.py
示例16: test_switching_search_path
def test_switching_search_path(self):
dummies_tenant1_count, dummies_tenant2_count = 0, 0
tenant1 = Tenant(domain_url='test.com', schema_name='tenant1')
tenant1.save()
tenant2 = Tenant(domain_url='example.com', schema_name='tenant2')
tenant2.save()
# go to tenant1's path
connection.set_tenant(tenant1)
# add some data
DummyModel(name="Schemas are").save()
DummyModel(name="awesome!").save()
dummies_tenant1_count = DummyModel.objects.count()
# switch temporarily to tenant2's path
with tenant_context(tenant2):
# add some data
DummyModel(name="Man,").save()
DummyModel(name="testing").save()
DummyModel(name="is great!").save()
dummies_tenant2_count = DummyModel.objects.count()
# we should be back to tenant1's path, test what we have
self.assertEqual(DummyModel.objects.count(), dummies_tenant1_count)
# switch back to tenant2's path
with tenant_context(tenant2):
self.assertEqual(DummyModel.objects.count(), dummies_tenant2_count)
开发者ID:bogeymin,项目名称:django-tenant-schemas,代码行数:31,代码来源:schemas.py
示例17: RoutesTestCase
class RoutesTestCase(BaseTestCase):
def setUp(self):
super(RoutesTestCase, self).setUp()
self.factory = RequestFactory()
self.tm = TenantMiddleware()
self.tenant_domain = 'tenant.test.com'
self.tenant = Tenant(domain_url=self.tenant_domain, schema_name='test')
self.tenant.save()
def test_tenant_routing(self):
"""
request path should not be altered
"""
request_url = '/any/request/'
request = self.factory.get('/any/request/',
HTTP_HOST=self.tenant_domain)
self.tm.process_request(request)
self.assertEquals(request.path_info, request_url)
# request.tenant should also have been set
self.assertEquals(request.tenant, self.tenant)
def test_public_schema_routing(self):
"""
request path should not be altered
"""
request_url = '/any/request/'
request = self.factory.get('/any/request/',
HTTP_HOST=self.public_tenant_domain)
self.tm.process_request(request)
self.assertEquals(request.path_info, request_url)
# request.tenant should also have been set
self.assertEquals(request.tenant, self.public_tenant)
开发者ID:MichaelBechard,项目名称:django-tenant-schemas,代码行数:37,代码来源:routes.py
示例18: test_edit_tenant
def test_edit_tenant(self):
"""
when editing an existing tenant, all data should be kept
"""
tenant = Tenant(domain_url='test.com', schema_name='test')
tenant.save()
# go to tenant's path
connection.set_tenant(tenant)
# add some data
DummyModel(name="Schemas are").save()
DummyModel(name="awesome!").save()
# edit tenant
tenant.domain_url = 'example.com'
tenant.save()
# test if data is still there
self.assertEquals(DummyModel.objects.count(), 2)
开发者ID:bogeymin,项目名称:django-tenant-schemas,代码行数:20,代码来源:schemas.py
示例19: test_sync_tenant
def test_sync_tenant(self):
"""
When editing an existing tenant, all data should be kept.
"""
tenant = Tenant(domain_url='something.test.com', schema_name='test')
tenant.save(verbosity=BaseTestCase.get_verbosity())
# go to tenant's path
connection.set_tenant(tenant)
# add some data
DummyModel(name="Schemas are").save()
DummyModel(name="awesome!").save()
# edit tenant
connection.set_schema_to_public()
tenant.domain_url = 'example.com'
tenant.save(verbosity=BaseTestCase.get_verbosity())
connection.set_tenant(tenant)
# test if data is still there
self.assertEquals(DummyModel.objects.count(), 2)
开发者ID:dszmaj,项目名称:django-multitenant,代码行数:23,代码来源:test_tenants.py
示例20: CeleryTasksTests
class CeleryTasksTests(BaseTestCase):
def setUp(self):
super(CeleryTasksTests, self).setUp()
self.tenant1 = Tenant(domain_url='test1', schema_name='test1')
self.tenant1.save()
self.tenant2 = Tenant(domain_url='test2', schema_name='test2')
self.tenant2.save()
connection.set_tenant(self.tenant1)
self.dummy1 = DummyModel.objects.create(name='test1')
connection.set_tenant(self.tenant2)
self.dummy2 = DummyModel.objects.create(name='test2')
connection.set_schema_to_public()
def test_basic_model_update(self):
# We should be in public schema where dummies don't exist.
for dummy in self.dummy1, self.dummy2:
# Test both async and local versions.
with self.assertRaises(DummyModel.DoesNotExist):
update_task.apply_async(args=(dummy.pk, 'updated-name'))
with self.assertRaises(DummyModel.DoesNotExist):
update_task.apply(args=(dummy.pk, 'updated-name'))
connection.set_tenant(self.tenant1)
update_task.apply_async(args=(self.dummy1.pk, 'updated-name'))
self.assertEqual(connection.schema_name, self.tenant1.schema_name)
# The task restores the schema from before running the task, so we are
# using the `tenant1` tenant now.
model_count = DummyModel.objects.filter(name='updated-name').count()
self.assertEqual(model_count, 1)
connection.set_tenant(self.tenant2)
model_count = DummyModel.objects.filter(name='updated-name').count()
self.assertEqual(model_count, 0)
def test_task_retry(self):
# Schema name should persist through retry attempts.
connection.set_tenant(self.tenant1)
update_retry_task.apply_async(args=(self.dummy1.pk, 'updated-name'))
model_count = DummyModel.objects.filter(name='updated-name').count()
self.assertEqual(model_count, 1)
def test_restoring_schema_name(self):
update_task.apply_async(
args=(self.dummy1.pk, 'updated-name'),
kwargs={'_schema_name': self.tenant1.schema_name}
)
self.assertEqual(connection.schema_name, get_public_schema_name())
connection.set_tenant(self.tenant1)
update_task.apply_async(
args=(self.dummy2.pk, 'updated-name'),
kwargs={'_schema_name': self.tenant2.schema_name}
)
self.assertEqual(connection.schema_name, self.tenant1.schema_name)
connection.set_tenant(self.tenant2)
# The model does not exist in the public schema.
with self.assertRaises(DummyModel.DoesNotExist):
update_task.apply_async(
args=(self.dummy2.pk, 'updated-name'),
kwargs={'_schema_name': get_public_schema_name()}
)
self.assertEqual(connection.schema_name, self.tenant2.schema_name)
开发者ID:bufke,项目名称:tenant-schemas-celery,代码行数:71,代码来源:tests.py
注:本文中的tenant_schemas.tests.models.Tenant类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论