refactor(itam): ViewSet Unit Test Suite re-written to Pytest for model OperatingSystem

ref: #925 #922
This commit is contained in:
2025-08-02 10:25:45 +09:30
parent 3d4018e306
commit 7413a5686d

View File

@ -1,44 +1,84 @@
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 itam.viewsets.operating_system import ViewSet
from itam.viewsets.operating_system import (
OperatingSystem,
ViewSet,
)
@pytest.mark.skip(reason = 'see #895, tests being refactored')
@pytest.mark.model_operatingsystem
@pytest.mark.module_itam
class OperatingSystemViewsetList(
class ViewsetTestCases(
ModelViewSetInheritedCases,
TestCase,
):
viewset = ViewSet
route_name = 'v2:_api_operatingsystem'
@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': str,
'value': 'itam/operating_system'
},
'filterset_fields': {
'value': [
'organization',
'publisher'
]
},
'model': {
'value': OperatingSystem
},
'model_documentation': {
'type': type(None),
},
'queryset': {
'type': type(None),
},
'serializer_class': {
'type': type(None),
},
'search_fields': {
'value': [
'name'
]
},
'view_description': {
'value': 'Operating Systems'
},
'view_name': {
'type': type(None),
},
'view_serializer_name': {
'type': type(None),
}
}
client = Client()
url = reverse(
self.route_name + '-list',
kwargs = self.kwargs
)
client.force_login(self.view_user)
class OperatingSystemViewsetInheritedCases(
ViewsetTestCases,
):
pass
self.http_options_response_list = client.options(url)
@pytest.mark.module_itam
class OperatingSystemViewsetPyTest(
ViewsetTestCases,
):
pass