chore: Add support for testing tenant model to fixture model_instance
ref: #833
This commit is contained in:
@ -4,7 +4,7 @@ from django.contrib.auth.models import Group
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
from access.models.tenant import Tenant
|
||||
from access.models.team import Team
|
||||
|
||||
|
||||
@ -40,8 +40,8 @@ class Tenancy:
|
||||
_app_settings: AppSettings = None
|
||||
|
||||
|
||||
_user_organizations: list([Organization]) = None
|
||||
"""Cached User Organizations"""
|
||||
_user_organizations: list([Tenant]) = None
|
||||
"""Cached User Tenants"""
|
||||
|
||||
_user_teams: list([Team]) = None
|
||||
"""Cached User Teams"""
|
||||
@ -90,7 +90,7 @@ class Tenancy:
|
||||
|
||||
|
||||
|
||||
def is_member(self, organization: Organization) -> bool:
|
||||
def is_member(self, organization: Tenant) -> bool:
|
||||
"""Returns true if the current user is a member of the organization
|
||||
|
||||
iterates over the user_organizations list and returns true if the user is a member
|
||||
@ -113,11 +113,11 @@ class Tenancy:
|
||||
|
||||
|
||||
|
||||
def has_organization_permission(self, organization: Organization, permissions_required: str) -> bool:
|
||||
def has_organization_permission(self, organization: Tenant, permissions_required: str) -> bool:
|
||||
""" Check if user has permission within organization.
|
||||
|
||||
Args:
|
||||
organization (int): Organization to check.
|
||||
organization (int): Tenant to check.
|
||||
permissions_required (list): if doing object level permissions, pass in required permission.
|
||||
|
||||
Returns:
|
||||
@ -126,9 +126,9 @@ class Tenancy:
|
||||
|
||||
has_permission: bool = False
|
||||
|
||||
if type(organization) is not Organization:
|
||||
if type(organization) is not Tenant:
|
||||
|
||||
raise TypeError('Organization must be of type Organization')
|
||||
raise TypeError('Tenant must be of type Tenant')
|
||||
|
||||
|
||||
if type(permissions_required) is not str:
|
||||
|
50
app/tests/fixtures/model_instance.py
vendored
50
app/tests/fixtures/model_instance.py
vendored
@ -4,6 +4,8 @@ import pytest
|
||||
from django.apps import apps
|
||||
from django.db import models
|
||||
|
||||
from access.models.tenant import Tenant
|
||||
|
||||
|
||||
|
||||
model_objs: list = []
|
||||
@ -31,6 +33,32 @@ def model_instance(django_db_blocker, model_kwarg_data, model, model_kwargs):
|
||||
global model_objs
|
||||
|
||||
obj = None
|
||||
org = None
|
||||
|
||||
kwargs = model_kwargs
|
||||
|
||||
if kwargs_create:
|
||||
|
||||
if(
|
||||
'organization' in kwargs_create
|
||||
and type(model) is not Tenant
|
||||
):
|
||||
|
||||
org = kwargs_create['organization']
|
||||
|
||||
elif(
|
||||
'organization' in kwargs_create
|
||||
and type(model) is Tenant
|
||||
):
|
||||
|
||||
# org = kwargs_create['organization']
|
||||
|
||||
del kwargs_create['organization']
|
||||
|
||||
kwargs.update(
|
||||
**kwargs_create
|
||||
)
|
||||
|
||||
|
||||
|
||||
if model._meta.abstract:
|
||||
@ -52,17 +80,25 @@ def model_instance(django_db_blocker, model_kwarg_data, model, model_kwargs):
|
||||
else:
|
||||
|
||||
|
||||
obj = model_kwarg_data(
|
||||
model = model,
|
||||
model_kwargs = model_kwargs,
|
||||
create_instance = True,
|
||||
)
|
||||
if(
|
||||
model is not Tenant
|
||||
and org is not None
|
||||
):
|
||||
|
||||
obj = obj['instance']
|
||||
obj = model_kwarg_data(
|
||||
model = model,
|
||||
model_kwargs = kwargs,
|
||||
create_instance = True,
|
||||
)
|
||||
|
||||
obj = obj['instance']
|
||||
|
||||
model_objs += [ obj ]
|
||||
|
||||
else:
|
||||
|
||||
obj = org
|
||||
|
||||
model_objs += [ obj ]
|
||||
|
||||
return obj
|
||||
|
||||
|
Reference in New Issue
Block a user