refactor(itim): ViewSet Unit Test Suite re-written to Pytest for model Cluster

ref: #932 #928
This commit is contained in:
2025-08-03 11:31:46 +09:30
parent 6c1542f572
commit c2344e95c5

View File

@ -1,45 +1,86 @@
import pytest
from django.test import Client, TestCase
from rest_framework.reverse import reverse
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
from itim.viewsets.cluster import ViewSet
from itim.viewsets.cluster import (
Cluster,
ViewSet,
)
@pytest.mark.skip(reason = 'see #895, tests being refactored')
@pytest.mark.model_cluster
@pytest.mark.module_itim
class ClusterViewsetList(
class ViewsetTestCases(
ModelViewSetInheritedCases,
TestCase,
):
viewset = ViewSet
route_name = 'v2:_api_cluster'
@pytest.fixture( scope = 'function' )
def viewset(self):
return ViewSet
@classmethod
def setUpTestData(self):
"""Setup Test
1. make list request
"""
super().setUpTestData()
@property
def parameterized_class_attributes(self):
return {
'_model_documentation': {
'type': type(None),
},
'back_url': {
'type': type(None),
},
'documentation': {
'type': type(None),
'value': None
},
'filterset_fields': {
'value': [
'parent_cluster',
'cluster_type',
'nodes',
'devices'
]
},
'model': {
'value': Cluster
},
'model_documentation': {
'type': type(None),
},
'queryset': {
'type': type(None),
},
'serializer_class': {
'type': type(None),
},
'search_fields': {
'value': [
'name',
]
},
'view_description': {
'value': 'Physical Devices'
},
'view_name': {
'type': type(None),
},
'view_serializer_name': {
'type': type(None),
}
}
client = Client()
url = reverse(
self.route_name + '-list',
kwargs = self.kwargs
)
class ClusterViewsetInheritedCases(
ViewsetTestCases,
):
pass
client.force_login(self.view_user)
self.http_options_response_list = client.options(url)
@pytest.mark.module_itim
class ClusterViewsetPyTest(
ViewsetTestCases,
):
pass