def test_with_unexistent_tenant_in_http_header(self):
        create_tenant(name='test',
                      slug='test',
                      extra_data={},
                      domains=['test.localhost:8000'])
        factory = RequestFactory()
        request = factory.get(reverse('shared_schema_tenants:tenant_list'),
                              **{'HTTP_TENANT_SLUG': 'unexistent'})

        with self.assertRaises(TenantNotFoundError):
            get_tenant(request)
    def test_with_unexistent_tenant_in_http_header(self):
        create_tenant(name='test',
                      slug='test',
                      extra_data={},
                      domains=['test.localhost:8000'])
        factory = RequestFactory()
        request = factory.get(reverse('shared_schema_tenants:tenant_list'),
                              **{'HTTP_TENANT_SLUG': 'unexistent'})

        retrieved_tenant = get_tenant(request)

        self.assertEqual(retrieved_tenant, None)
    def handle(self, *args, **options):
        name = input('Enter the Tenant name: ')
        slug = input('Enter the Tenant slug: (%s)' % slugify(name))
        domain = input('Enter the Tenant site: (localhost:8000)')

        if not slug:
            slug = slugify(name)

        if not domain:
            domain = 'localhost:8000'

        with transaction.atomic():
            create_tenant(name, slug, {}, [domain])

            self.stdout.write(
                self.style.SUCCESS('Successfully created Tenant %s' % name))
Beispiel #4
0
    def setUp(self):
        self.tenant_1 = create_tenant(name='tenant_1',
                                      slug='tenant_1',
                                      extra_data={})
        self.tenant_2 = create_tenant(name='tenant_2',
                                      slug='tenant_2',
                                      extra_data={})

        self.tags_t1 = mommy.make(Tag, tenants=[self.tenant_1], _quantity=5)
        self.tags_t2 = mommy.make(Tag, tenants=[self.tenant_2], _quantity=3)
        self.shared_tags = mommy.make(Tag,
                                      tenants=[self.tenant_1, self.tenant_2],
                                      _quantity=7)

        set_current_tenant(self.tenant_1.slug)

        self.tags_manager = Tag.objects
        if django.utils.version.get_complete_version()[1] < 10:
            self.tags_manager = Tag.tenant_objects
Beispiel #5
0
    def setUp(self):
        self.tenant_1 = create_tenant(name='tenant_1',
                                      slug='tenant_1',
                                      extra_data={})
        self.tenant_2 = create_tenant(name='tenant_2',
                                      slug='tenant_2',
                                      extra_data={})

        self.articles_t1 = mommy.make(Article,
                                      tenant=self.tenant_1,
                                      _quantity=5)
        self.articles_t2 = mommy.make(Article,
                                      tenant=self.tenant_2,
                                      _quantity=3)

        set_current_tenant(self.tenant_1.slug)

        self.articles_manager = Article.objects
        if django.utils.version.get_complete_version()[1] < 10:
            self.articles_manager = Article.tenant_objects
    def test_with_correct_domain(self):
        tenant = create_tenant(name='test',
                               slug='test',
                               extra_data={},
                               domains=['test.localhost:8000'])
        factory = RequestFactory()
        request = factory.get(reverse('shared_schema_tenants:tenant_list'),
                              HTTP_HOST='test.localhost:8000')
        retrieved_tenant = get_tenant(request)

        self.assertEqual(retrieved_tenant, tenant)
    def test_with_previously_set_tenant(self):
        tenant = create_tenant(name='test',
                               slug='test',
                               extra_data={},
                               domains=['test.localhost:8000'])
        factory = RequestFactory()
        request = factory.get(reverse('shared_schema_tenants:tenant_list'))

        set_current_tenant(tenant.slug)
        retrieved_tenant = get_tenant(request)

        self.assertEqual(retrieved_tenant, tenant)
    def test_process_request_adds_tenant_to_request(self, get_tenant):
        tenant = create_tenant(name='test',
                               slug='test',
                               extra_data={},
                               domains=['test.localhost:8000'])
        get_tenant.return_value = tenant
        factory = RequestFactory()
        request = factory.get(reverse('shared_schema_tenants:tenant_list'),
                              HTTP_HOST='test.localhost:8000')
        response = HttpResponse()
        request = TenantMiddleware(lambda r: response).process_request(request)

        self.assertEqual(request.tenant.slug, tenant.slug)
        get_tenant.assert_called_once()
    def test_call_returns_correct_response(self):
        tenant = create_tenant(name='test',
                               slug='test',
                               extra_data={},
                               domains=['test.localhost:8000'])
        get_tenant.return_value = tenant
        factory = RequestFactory()
        request = factory.get(reverse('shared_schema_tenants:tenant_list'),
                              HTTP_HOST='test.localhost:8000')

        response = HttpResponse()
        processed_response = TenantMiddleware(lambda r: response).__call__(
            request)

        self.assertEqual(response, processed_response)
Beispiel #10
0
 def create(self, validated_data):
     return create_tenant(user=self.context['request'].user,
                          **validated_data)