refactor(access): Update Test Suite for Role model

ref: #862 #844
This commit is contained in:
2025-07-12 16:56:07 +09:30
parent 953dce2984
commit 3b7e88969e
12 changed files with 131 additions and 25 deletions

View File

@ -10,6 +10,8 @@ from access.serializers.role import Role, ModelSerializer
@pytest.mark.model_role
@pytest.mark.module_role
class ValidationSerializer(
TestCase,
):

View File

@ -1,4 +1,6 @@
import django
import pytest
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.test import Client, TestCase
@ -20,6 +22,8 @@ User = django.contrib.auth.get_user_model()
@pytest.mark.model_role
@pytest.mark.module_role
class ViewSetBase:
add_data: dict = None

View File

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

View File

@ -1,3 +1,4 @@
import pytest
import django
from django.contrib.auth.models import Permission
@ -18,6 +19,7 @@ User = django.contrib.auth.get_user_model()
@pytest.mark.model_role
class APITestCases(
APITenancyObject,
):
@ -48,7 +50,7 @@ class APITestCases(
**self.kwargs_item_create
)
self.url_view_kwargs = {
'pk': self.item.id
}
@ -154,6 +156,7 @@ class APITestCases(
@pytest.mark.module_role
class RoleAPITest(
APITestCases,
TestCase,

View File

@ -1,30 +1,70 @@
from django.test import TestCase
import pytest
from access.models.role import Role
from django.db import models
from centurion.tests.unit.test_unit_models import (
TenancyObjectInheritedCases
from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model import (
CenturionAbstractModelInheritedCases
)
@pytest.mark.model_role
class RoleModelTestCases(
TenancyObjectInheritedCases,
CenturionAbstractModelInheritedCases
):
model = None
kwargs_item_create: dict = None
@property
def parameterized_class_attributes(self):
return {
'model_tag': {
'type': str,
'value': 'role'
},
}
@property
def parameterized_model_fields(self):
class RoleModelTest(
RoleModelTestCases,
TestCase,
):
model = Role
kwargs_item_create: dict = {
'name': 'a role'
return {
'name': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.CharField,
'max_length': 30,
'null': False,
'unique': False,
},
'permissions': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.ManyToManyField,
'null': False,
'unique': False,
},
'modified': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.DateTimeField,
'null': False,
'unique': False,
},
}
class RoleModelInheritedCases(
RoleModelTestCases,
):
pass
@pytest.mark.module_role
class RoleModelPyTest(
RoleModelTestCases,
):
pass

View File

@ -20,6 +20,8 @@ import pytest
###############################################################################
@pytest.mark.model_role
@pytest.mark.module_role
@pytest.mark.skip( reason = 'figure out how to isolate so entirety of unit tests can run without this test failing' )
# @pytest.mark.forked
# @pytest.mark.django_db

View File

@ -1,3 +1,5 @@
import pytest
from django.test import Client, TestCase
from rest_framework.reverse import reverse
@ -9,6 +11,7 @@ from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
@pytest.mark.model_role
class ViewsetTestCases(
ModelViewSetInheritedCases,
):
@ -44,6 +47,7 @@ class ViewsetTestCases(
@pytest.mark.module_role
class RoleViewsetTest(
ViewsetTestCases,
TestCase,