test(access): Tenant Model Tests

ref: #805 #790
This commit is contained in:
2025-06-08 13:51:45 +09:30
parent 35b3710562
commit a7a1d85978
6 changed files with 152 additions and 3 deletions

View File

@ -0,0 +1,19 @@
import pytest
@pytest.fixture( scope = 'class')
def model(model_tenant):
yield model_tenant
@pytest.fixture( scope = 'class', autouse = True)
def model_kwargs(request, kwargs_tenant):
request.cls.kwargs_create_item = kwargs_tenant.copy()
yield kwargs_tenant.copy()
if hasattr(request.cls, 'kwargs_create_item'):
del request.cls.kwargs_create_item

View File

@ -0,0 +1,90 @@
import pytest
from django.db import models
from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model import (
CenturionAbstractModelInheritedCases
)
from core.tests.unit.mixin_centurion.test_unit_centurion_mixin import (
CenturionMixnInheritedCases,
)
@pytest.mark.model_tenant
class TenantModelTestCases(
CenturionMixnInheritedCases
):
@property
def parameterized_class_attributes(self):
return {
'model_tag': {
'type': str,
'value': 'tenant'
},
}
parameterized_model_fields = {
'id': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.AutoField,
'null': False,
'unique': True,
},
'name': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.TextField,
'max_length': 50,
'null': False,
'unique': True,
},
'manager': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.ForeignKey,
'null': True,
'unique': False,
},
'model_notes': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.TextField,
'null': True,
'unique': False,
},
'created': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.DateTimeField,
'null': False,
'unique': False,
},
'modified': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.DateTimeField,
'null': False,
'unique': False,
},
}
class TenantModelInheritedCases(
TenantModelTestCases,
):
pass
class TenantModelPyTest(
TenantModelTestCases,
):
pass

View File

@ -545,7 +545,7 @@ def organization_one(django_db_blocker):
random_str = datetime.datetime.now(tz=datetime.timezone.utc)
item = Tenant.objects.create(
name = 'org one from global' + str(random_str)
name = 'org one global' + str(random_str)
)
yield item
@ -569,7 +569,7 @@ def organization_two(django_db_blocker):
random_str = datetime.datetime.now(tz=datetime.timezone.utc)
item = Tenant.objects.create(
name = 'org two from global' + str(random_str)
name = 'org two global' + str(random_str)
)
yield item
@ -590,7 +590,7 @@ def organization_three(django_db_blocker):
random_str = datetime.datetime.now(tz=datetime.timezone.utc)
item = Tenant.objects.create(
name = 'org three from global' + str(random_str)
name = 'org three global' + str(random_str)
)
yield item

View File

@ -133,6 +133,11 @@ from .model_teamuser import (
model_teamusers,
)
from .model_tenant import (
kwargs_tenant,
model_tenant,
)
from .model_tenancyabstract import (
kwargs_tenancyabstract,
model_tenancyabstract,

34
app/tests/fixtures/model_tenant.py vendored Normal file
View File

@ -0,0 +1,34 @@
import datetime
import pytest
from access.models.tenant import Tenant
@pytest.fixture( scope = 'class')
def model_tenant():
yield Tenant
@pytest.fixture( scope = 'class')
def kwargs_tenant( django_db_blocker, model_user ):
random_str = str(datetime.datetime.now(tz=datetime.timezone.utc))
with django_db_blocker.unblock():
user = model_user.objects.create(
username = 'a'+random_str,
password = 'password'
)
kwargs = {
'name': 'te',
'manager': user,
}
yield kwargs.copy()
with django_db_blocker.unblock():
user.delete()

View File

@ -1085,6 +1085,7 @@ markers = [
"model_knowledgebasecategory: Selects Knowledge base category tests.",
"model_manufacturer: Select all manufacturer tests.",
"models: Selects all models tests.",
"model_tenant: Select all Tentant model tests.",
"model_ticketcategory: Select all Ticket Categeory tests.",
"model_ticketcommentcategory: select all ticket comment category tests.",
"note_models: Selects all centurion model note models",