test(api): SubModel ViewSet Test Suite to test re-written class

ref: #897 #895
This commit is contained in:
2025-07-28 10:31:30 +09:30
parent 209c01f5a3
commit 2769859db0
2 changed files with 43 additions and 35 deletions

View File

@ -7,13 +7,13 @@ from access.viewsets.entity import (
ViewSet, ViewSet,
) )
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases from api.tests.unit.test_unit_common_viewset import SubModelViewSetInheritedCases
@pytest.mark.model_entity @pytest.mark.model_entity
class ViewsetTestCases( class ViewsetTestCases(
ModelViewSetInheritedCases, SubModelViewSetInheritedCases,
): ):
@ -37,6 +37,9 @@ class ViewsetTestCases(
'type': type(None), 'type': type(None),
'value': None 'value': None
}, },
'base_model': {
'value': Entity
},
'documentation': { 'documentation': {
'type': type(None), 'type': type(None),
'value': None 'value': None
@ -53,6 +56,12 @@ class ViewsetTestCases(
'type': type(None), 'type': type(None),
'value': None 'value': None
}, },
'model_kwarg': {
'value': 'model_name'
},
'model_suffix': {
'type': type(None)
},
'queryset': { 'queryset': {
'type': type(None), 'type': type(None),
'value': None 'value': None

View File

@ -32,6 +32,7 @@ from api.viewsets.common import (
CommonViewSet, CommonViewSet,
ModelViewSet, ModelViewSet,
SubModelViewSet, SubModelViewSet,
SubModelViewSet_ReWrite,
ModelCreateViewSet, ModelCreateViewSet,
ModelListRetrieveDeleteViewSet, ModelListRetrieveDeleteViewSet,
@ -1069,6 +1070,10 @@ class SubModelViewSetTestCases(
'model_kwarg': { 'model_kwarg': {
'type': str, 'type': str,
'value': None 'value': None
},
'model_suffix': {
'type': str,
'value': None
} }
} }
@ -1136,7 +1141,7 @@ class SubModelViewSetPyTest(
@pytest.fixture( scope = 'function' ) @pytest.fixture( scope = 'function' )
def viewset(self): def viewset(self):
return SubModelViewSet return SubModelViewSet_ReWrite
@property @property
@ -1163,8 +1168,11 @@ class SubModelViewSetPyTest(
'value': None 'value': None
}, },
'model': { 'model': {
'type': django.db.models.NOT_PROVIDED,
'value': django.db.models.NOT_PROVIDED
},
'model_suffix': {
'type': type(None), 'type': type(None),
'value': None
}, },
'model_documentation': { 'model_documentation': {
'type': type(None), 'type': type(None),
@ -1197,20 +1205,6 @@ class SubModelViewSetPyTest(
} }
def test_view_attr_model_not_empty(self, viewset):
"""Attribute Test
This test case overrides a test case of the same name. As this test is
checking the base classes, it's return is different to a class that
has inherited from this or parent classes.
Attribute `model` must return a value that is not None
"""
assert viewset().model is None
def test_view_attr_type_base_model(self): def test_view_attr_type_base_model(self):
"""Attribute Test """Attribute Test
@ -2235,18 +2229,6 @@ class SubModelViewSetInheritedCases(
Use this Test Suite for ViewSet classes that inherit from SubModelViewSet Use this Test Suite for ViewSet classes that inherit from SubModelViewSet
""" """
http_options_response_list = None
"""Inherited class must make and store here a HTTP/Options request"""
route_name = None
"""Inherited class must define the url rout name with namespace"""
base_model = None
"""The Sub Model that is returned from the model property"""
# viewset = None
# @classmethod # @classmethod
# def setUpTestData(self): # def setUpTestData(self):
# """Setup Test # """Setup Test
@ -2260,14 +2242,31 @@ class SubModelViewSetInheritedCases(
# super().setUpTestData() # super().setUpTestData()
@property
def parameterized_class_attributes(self):
return {
'model_suffix': {
'type': str,
'value': None
},
'base_model': {
'type': django.db.models.base.ModelBase,
'value': None
},
'model_kwarg': {
'type': str,
'value': None
}
}
def test_view_attr_model_value(self, viewset):
"""Attribute Test
Attribute `model` must return the correct sub-model # ToDo: model
"""
assert viewset().model == self.model # ToDo: related_objects
# ToDo: get_serializer_class
# ToDo: related_objects