コード例 #1
0
 def setUpClass(cls):
     tenant = TenantModel(schema_name="tenant")
     tenant.save(verbosity=0)
     catalog = Catalog.objects.create()
     Catalog.objects.create()
     with SchemaDescriptor.create(schema_name="www"):
         user = User.objects.create(email="*****@*****.**",
                                    display_name="Main User")
         user.set_password("weakpassword")
         user.save()
         MainData.objects.create()
     with SchemaDescriptor.create(schema_name="blog"):
         user = User.objects.create(email="*****@*****.**",
                                    display_name="Blog User")
         user.set_password("weakpassword")
         user.save()
         BlogEntry.objects.create(user=user)
     with TenantModel.objects.first():
         user = User.objects.create(email="*****@*****.**",
                                    display_name="Tenant User")
         user.set_password("weakpassword")
         user.save()
         TenantData.objects.create(user=user, catalog=catalog)
     activate_public()
     super().setUpClass()
コード例 #2
0
 def setUpClass(cls):
     schema_name = "tenant1"
     tenant = TenantModel(schema_name=schema_name)
     tenant.save(verbosity=0)
     DomainModel.objects.create(tenant=tenant,
                                domain=f"{schema_name}.test.com")
     DomainModel.objects.create(tenant=tenant,
                                domain="everyone.test.com",
                                folder=schema_name)  # primary
     activate_public()
     super().setUpClass()
コード例 #3
0
 def test_cross_authentication(self):
     with SchemaDescriptor.create(schema_name="www"):
         self.assertTrue(authenticate(email="*****@*****.**", password="******"))  # good
         self.assertFalse(authenticate(email="*****@*****.**", password="******"))  # bad
         self.assertFalse(authenticate(email="*****@*****.**", password="******"))  # bad
     with SchemaDescriptor.create(schema_name="blog"):
         self.assertTrue(authenticate(email="*****@*****.**", password="******"))  # good
         self.assertFalse(authenticate(email="*****@*****.**", password="******"))  # bad
         self.assertFalse(authenticate(email="*****@*****.**", password="******"))  # bad
     with TenantModel.objects.first():
         self.assertTrue(authenticate(email="*****@*****.**", password="******"))  # good
         self.assertFalse(authenticate(email="*****@*****.**", password="******"))  # bad
         self.assertFalse(authenticate(email="*****@*****.**", password="******"))  # bad
     # Switching to public schema
     activate_public()
     with self.assertRaises(ProgrammingError):
         authenticate(email="*****@*****.**", password="******")  # unexisting, error
コード例 #4
0
    def setUpClass(cls):
        def reverser_func(self, name, domain, path="/"):
            """
            Reverses `name` in the urlconf returned by processing `domain` at `path`.
            """
            def fake_get_response(request):
                return request

            factory = RequestFactory()
            request = factory.get(path, HTTP_HOST=domain)
            modified_request = TenantMiddleware(fake_get_response)(request)
            with modified_request.tenant:
                urlconf = import_module(modified_request.urlconf)
                reverse_response = reverse(name, urlconf=urlconf)
                del sys.modules[modified_request.
                                urlconf]  # required to simulate new thread
                return reverse_response

        cls.reverser = reverser_func
        # This comes from app_tenants/urls.py
        cls.paths = {
            "tenant-home": "/",
            "profile": "/profile/",
            "advanced-profile": "/profile/advanced/"
        }

        for i in range(1, 4):
            schema_name = f"tenant{i}"
            tenant = TenantModel(schema_name=schema_name)
            tenant.save(verbosity=0)
            DomainModel.objects.create(tenant=tenant,
                                       domain=f"{schema_name}.test.com")
            DomainModel.objects.create(tenant=tenant,
                                       domain="everyone.test.com",
                                       folder=schema_name)  # primary
        activate_public()
        super().setUpClass()