Skip to content

Commit

Permalink
fixes get_tenant in middlwares and tests the new case
Browse files Browse the repository at this point in the history
  • Loading branch information
hugobessa committed Aug 30, 2017
1 parent 51e7cca commit e95da97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shared_schema_tenants/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_tenant(request):

lazy_tenant._setup()
request._cached_tenant = lazy_tenant._wrapped
except TenantSite.DoesNotExist:
except Tenant.DoesNotExist:
return None

return request._cached_tenant
Expand Down
9 changes: 9 additions & 0 deletions tests/test_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ def test_with_http_header(self):

self.assertEqual(retrieved_tenant, tenant)

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 test_with_previously_set_tenant(self):
tenant = create_tenant(name='test', slug='test', extra_data={}, domains=['test.localhost:8000'])
factory = RequestFactory()
Expand Down

0 comments on commit e95da97

Please sign in to comment.