当前位置: 首页>>代码示例>>Python>>正文


Python testcases.BaseTestCase类代码示例

本文整理汇总了Python中tenant_schemas.tests.testcases.BaseTestCase的典型用法代码示例。如果您正苦于以下问题:Python BaseTestCase类的具体用法?Python BaseTestCase怎么用?Python BaseTestCase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BaseTestCase类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_switching_search_path

    def test_switching_search_path(self):
        tenant1 = Tenant(domain_url='something.test.com',
                         schema_name='tenant1')
        tenant1.save(verbosity=BaseTestCase.get_verbosity())

        connection.set_schema_to_public()
        tenant2 = Tenant(domain_url='example.com', schema_name='tenant2')
        tenant2.save(verbosity=BaseTestCase.get_verbosity())

        # 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 snello to tenant1's path, test what we have
        self.assertEqual(2, DummyModel.objects.count())

        # switch snello to tenant2's path
        with tenant_context(tenant2):
            self.assertEqual(3, DummyModel.objects.count())
开发者ID:dszmaj,项目名称:django-multitenant,代码行数:29,代码来源:test_tenants.py

示例2: 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

示例3: 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(verbosity=BaseTestCase.get_verbosity())

        self.assertTrue(schema_exists(tenant.schema_name))
开发者ID:dszmaj,项目名称:django-multitenant,代码行数:8,代码来源:test_tenants.py

示例4: 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(verbosity=BaseTestCase.get_verbosity())
开发者ID:bernardopires,项目名称:django-tenant-schemas,代码行数:8,代码来源:test_routes.py

示例5: setUpClass

 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())
开发者ID:bernardopires,项目名称:django-tenant-schemas,代码行数:10,代码来源:test_routes.py

示例6: test_non_auto_sync_tenant

 def test_non_auto_sync_tenant(self):
     """
     When saving a tenant that has the flag auto_create_schema as
     False, the schema should not be created when saving the tenant.
     """
     self.assertFalse(schema_exists('non_auto_sync_tenant'))
     tenant = NonAutoSyncTenant(domain_url='something.test.com',
                                schema_name='non_auto_sync_tenant')
     tenant.save(verbosity=BaseTestCase.get_verbosity())
     self.assertFalse(schema_exists(tenant.schema_name))
开发者ID:bernardopires,项目名称:django-tenant-schemas,代码行数:10,代码来源:test_tenants.py

示例7: 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(verbosity=BaseTestCase.get_verbosity())

        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:dszmaj,项目名称:django-multitenant,代码行数:11,代码来源:test_tenants.py

示例8: 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

示例9: 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(verbosity=BaseTestCase.get_verbosity())

        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:dszmaj,项目名称:django-multitenant,代码行数:17,代码来源:test_tenants.py

示例10: 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(verbosity=BaseTestCase.get_verbosity())

        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:dszmaj,项目名称:django-multitenant,代码行数:19,代码来源: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_command

    def test_command(self):
        """
        Tests that tenant_command is capable of wrapping commands
        and its parameters.
        """
        settings.SHARED_APPS = ('tenant_schemas',
                                'django.contrib.contenttypes', )
        settings.TENANT_APPS = ()
        settings.INSTALLED_APPS = settings.SHARED_APPS + settings.TENANT_APPS
        self.sync_shared()
        Tenant(domain_url='localhost', schema_name='public').save(verbosity=BaseTestCase.get_verbosity())

        out = StringIO()
        call_command('tenant_command', 'dumpdata', 'tenant_schemas', natural_foreign=True,
                     schema_name=get_public_schema_name(), stdout=out)
        self.assertItemsEqual(
            json.loads('[{"fields": {"domain_url": "localhost", "schema_name": "public"}, '
                       '"model": "tenant_schemas.tenant", "pk": 1}]'),
            json.loads(out.getvalue()))
开发者ID:Dynora,项目名称:django-tenant-schemas,代码行数:19,代码来源:test_tenants.py

示例13: 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(verbosity=BaseTestCase.get_verbosity())

        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:dszmaj,项目名称:django-multitenant,代码行数:21,代码来源:test_tenants.py


注:本文中的tenant_schemas.tests.testcases.BaseTestCase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。