Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checked for subfolder prefix #86

Merged
merged 3 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ addopts =
--doctest-modules
--tb=short
--cov=tenant_users
--cov=tests
--cov-branch
--cov-report=term-missing:skip-covered
--cov-report=html
Expand Down
7 changes: 5 additions & 2 deletions tenant_users/tenants/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ def provision_tenant(tenant_name, tenant_slug, user_email, is_staff=False):
user = UserModel.objects.get(email=user_email)
if not user.is_active:
raise InactiveError('Inactive user passed to provision tenant')

tenant_domain = '{0}.{1}'.format(tenant_slug, settings.TENANT_USERS_DOMAIN)

if hasattr(settings, 'TENANT_SUBFOLDER_PREFIX'):
tenant_domain = tenant_slug
else:
tenant_domain = '{0}.{1}'.format(tenant_slug, settings.TENANT_USERS_DOMAIN)

if TENANT_SCHEMAS:
if TenantModel.objects.filter(domain_url=tenant_domain).exists():
Expand Down
14 changes: 14 additions & 0 deletions tests/test_tenants/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ def test_provision_tenant(tenant_user_admin):
assert tenant_domain == '{0}.{1}'.format(slug, settings.TENANT_USERS_DOMAIN)


@pytest.mark.django_db()
def test_provision_tenant_with_subfolder(settings, tenant_user_admin):
"""Tests tasks.provision_tenant() for correctness when using subfolders."""
settings.TENANT_SUBFOLDER_PREFIX = 'clients'
slug = 'sample'
tenant_domain = tasks.provision_tenant(
'Sample Tenant',
slug,
tenant_user_admin,
)

assert tenant_domain == slug


@pytest.mark.django_db()
def test_provision_tenant_inactive_user(tenant_user):
"""Test tenant creation with inactive user."""
Expand Down