From 1c8f641dd445ba958b274bfe59b6d983b0926623 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 3 Aug 2025 11:55:00 +0930 Subject: [PATCH] refactor(itim): ViewSet Unit Test Suite re-written to Pytest for model ClusterType ref: #932 #929 --- .../test_unit_cluster_types_viewset.py | 89 +++++++++++++------ 1 file changed, 63 insertions(+), 26 deletions(-) diff --git a/app/itim/tests/unit/cluster_types/test_unit_cluster_types_viewset.py b/app/itim/tests/unit/cluster_types/test_unit_cluster_types_viewset.py index a8cd49b9..8575e133 100644 --- a/app/itim/tests/unit/cluster_types/test_unit_cluster_types_viewset.py +++ b/app/itim/tests/unit/cluster_types/test_unit_cluster_types_viewset.py @@ -1,46 +1,83 @@ 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_type import ViewSet +from itim.viewsets.cluster_type import ( + ClusterType, + ViewSet, +) -@pytest.mark.skip(reason = 'see #895, tests being refactored') @pytest.mark.model_clustertype -@pytest.mark.module_itim -class ClusterTypesViewsetList( +class ViewsetTestCases( ModelViewSetInheritedCases, - TestCase, ): - viewset = ViewSet - route_name = 'v2:_api_clustertype' + @pytest.fixture( scope = 'function' ) + def viewset(self): + return ViewSet - @classmethod - def setUpTestData(self): - """Setup Test - - 1. make list request - """ + @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': [ + 'organization' + ] + }, + 'model': { + 'value': ClusterType + }, + '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), + } + } - super().setUpTestData() + +class ClusterTypeViewsetInheritedCases( + ViewsetTestCases, +): + pass - client = Client() - - url = reverse( - self.route_name + '-list', - kwargs = self.kwargs - ) - client.force_login(self.view_user) +@pytest.mark.module_itim +class ClusterTypeViewsetPyTest( + ViewsetTestCases, +): - self.http_options_response_list = client.options(url) + pass