refactor(access): ViewSet TestSuite re-written to pytest for model Tenant

ref: #897 #899
This commit is contained in:
2025-07-28 13:05:42 +09:30
parent fa1cee32cf
commit 9e7c4a8191
4 changed files with 99 additions and 44 deletions

View File

@ -1,43 +0,0 @@
import pytest
from django.test import Client, TestCase
from rest_framework.reverse import reverse
from access.viewsets.organization import ViewSet
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
@pytest.mark.skip(reason = 'see #895, tests being refactored')
class OrganizationViewsetList(
ModelViewSetInheritedCases,
TestCase,
):
viewset = ViewSet
route_name = 'API:_api_tenant'
@classmethod
def setUpTestData(self):
"""Setup Test
1. make list request
"""
super().setUpTestData()
client = Client()
url = reverse(
self.route_name + '-list'
)
client.force_login(self.view_user)
self.http_options_response_list = client.options(url)

View File

@ -0,0 +1,85 @@
import pytest
from access.viewsets.organization import (
Tenant,
ViewSet,
)
from api.tests.unit.test_unit_common_viewset import (
ModelViewSetInheritedCases
)
@pytest.mark.model_tenant
class ViewsetTestCases(
ModelViewSetInheritedCases,
):
@pytest.fixture( scope = 'function' )
def viewset(self):
return ViewSet
@property
def parameterized_class_attributes(self):
return {
'_model_documentation': {
'type': type(None),
'value': None
},
'back_url': {
'type': type(None),
},
'documentation': {
'type': type(None),
},
'filterset_fields': {
'value': [
'name',
'manager',
]
},
'model': {
'value': Tenant
},
'model_documentation': {
'type': type(None),
},
'queryset': {
'type': type(None),
},
'serializer_class': {
'type': type(None),
},
'search_fields': {
'value': [
'name'
]
},
'view_description': {
'value': 'Centurion Tenants'
},
'view_name': {
'type': type(None),
},
'view_serializer_name': {
'type': type(None),
}
}
class TenantViewsetInheritedCases(
ViewsetTestCases,
):
pass
@pytest.mark.module_access
class TenantViewsetPyTest(
ViewsetTestCases,
):
pass

View File

@ -2219,7 +2219,19 @@ class ModelViewSetInheritedCases(
Use this Test Suite for ViewSet classes that inherit from ModelViewSet
"""
pass
@property
def parameterized_class_attributes(self):
return {
# '_log': {
# 'type': logging.Logger,
# 'value': None
# },
'_log': {
'type': type(None),
},
}

View File

@ -1146,6 +1146,7 @@ markers = [
"model_softwarecategory: Selects tests for model Software Category.",
"model_softwareenablefeatureflag: Selects tests for model Software Enabled Feature Flag.",
"model_softwareversion: Selects tests for model Software Version.",
"model_tenant: Selects tests for model Tenant.",
"model_ticketbase: Selects tests for model Ticket Base.",
"model_ticketcategory: Select all ticket category tests.",
"model_ticketcommentaction: Select test for model ticket Action Comment.",