-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Create default tenant for newly created social users (#572)
* Create default tenant for newly created social users * Add social pipeline tests
- Loading branch information
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .models import Tenant | ||
|
||
|
||
def create_default_tenant(user=None, is_new=False, *args, **kwargs): | ||
if user and is_new: | ||
Tenant.objects.get_or_create_user_default_tenant(user) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from ..pipeline import create_default_tenant | ||
|
||
from ..models import Tenant | ||
from ..constants import TenantType | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
class TestCreateTenantPipeline: | ||
def test_create_default_tenant_user_and_is_new(self, user): | ||
create_default_tenant(user=user, is_new=True) | ||
tenant_exists = Tenant.objects.filter(creator=user, type=TenantType.DEFAULT).exists() | ||
assert tenant_exists | ||
|
||
def test_create_default_tenant_user_not_new(self, user): | ||
count_before = Tenant.objects.filter(creator=user, type=TenantType.DEFAULT).count() | ||
create_default_tenant(user=user, is_new=False) | ||
count_after = Tenant.objects.filter(creator=user, type=TenantType.DEFAULT).count() | ||
assert count_before == count_after | ||
|
||
def test_create_default_tenant_no_user(self): | ||
create_default_tenant(user=None, is_new=True) | ||
tenant_exists = Tenant.objects.exists() | ||
assert not tenant_exists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters