From 38c9cccf307add935c609c64198fb1e1c0e4a68f Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 3 Aug 2025 11:32:08 +0930 Subject: [PATCH] refactor(itim): Remove old test suites no longer required model Cluster ref: #932 closes #928 --- .../tests/unit/cluster/test_cluster_api_v2.py | 491 ------------------ .../test_cluster_item_ticket_api_v2.py | 99 ---- 2 files changed, 590 deletions(-) delete mode 100644 app/itim/tests/unit/cluster/test_cluster_api_v2.py delete mode 100644 app/itim/tests/unit/cluster/test_cluster_item_ticket_api_v2.py diff --git a/app/itim/tests/unit/cluster/test_cluster_api_v2.py b/app/itim/tests/unit/cluster/test_cluster_api_v2.py deleted file mode 100644 index eb7638bc..00000000 --- a/app/itim/tests/unit/cluster/test_cluster_api_v2.py +++ /dev/null @@ -1,491 +0,0 @@ -import pytest - -from django.contrib.auth.models import Permission, User -from django.contrib.contenttypes.models import ContentType -from django.shortcuts import reverse -from django.test import Client, TestCase - -from rest_framework.relations import Hyperlink - -from access.models.tenant import Tenant as Organization -from access.models.team import Team -from access.models.team_user import TeamUsers - -from api.tests.abstract.api_fields import APITenancyObject - -from itam.models.device import Device - -from itim.models.clusters import Cluster, ClusterType - - - -@pytest.mark.model_cluster -@pytest.mark.module_itim -class ClusterAPI( - TestCase, - APITenancyObject -): - - model = Cluster - - @classmethod - def setUpTestData(self): - """Setup Test - - 1. Create an organization for user and item - 2. Create an item - - """ - - self.organization = Organization.objects.create(name='test_org') - - node = Device.objects.create( - organization = self.organization, - name = 'node', - ) - - device = Device.objects.create( - organization = self.organization, - name = 'device', - is_virtual = True, - ) - - cluster_type = ClusterType.objects.create( - organization = self.organization, - name = 'cluster_type' - ) - - parent_cluster = Cluster.objects.create( - organization = self.organization, - name = 'two' - ) - - self.item = self.model.objects.create( - organization = self.organization, - name = 'one', - cluster_type = cluster_type, - config = dict({"one": "two"}), - parent_cluster = parent_cluster, - model_notes = 'a note' - ) - - self.item.devices.set([ device ]) - - self.item.nodes.set([ node ]) - - - self.url_view_kwargs = {'pk': self.item.id} - - view_permissions = Permission.objects.get( - codename = 'view_' + self.model._meta.model_name, - content_type = ContentType.objects.get( - app_label = self.model._meta.app_label, - model = self.model._meta.model_name, - ) - ) - - view_team = Team.objects.create( - team_name = 'view_team', - organization = self.organization, - ) - - view_team.permissions.set([view_permissions]) - - self.view_user = User.objects.create_user(username="test_user_view", password="password") - teamuser = TeamUsers.objects.create( - team = view_team, - user = self.view_user - ) - - client = Client() - url = reverse('v2:_api_cluster-detail', kwargs=self.url_view_kwargs) - - - client.force_login(self.view_user) - response = client.get(url) - - self.api_data = response.data - - - def test_api_field_exists_config(self): - """ Test for existance of API Field - - config field must exist - """ - - assert 'config' in self.api_data - - - def test_api_field_type_config(self): - """ Test for type for API Field - - config field must be dict - """ - - assert type(self.api_data['config']) is dict - - - def test_api_field_exists_rendered_config(self): - """ Test for existance of API Field - - rendered_config field must exist - """ - - assert 'rendered_config' in self.api_data - - - def test_api_field_type_rendered_config(self): - """ Test for type for API Field - - rendered_config field must be dict - """ - - assert type(self.api_data['rendered_config']) is dict - - - def test_api_field_exists_resources(self): - """ Test for existance of API Field - - resources field must exist - """ - - assert 'resources' in self.api_data - - - def test_api_field_type_resources(self): - """ Test for type for API Field - - resources field must be dict - """ - - assert type(self.api_data['resources']) is str - - - - def test_api_field_exists_nodes(self): - """ Test for existance of API Field - - nodes field must exist - """ - - assert 'nodes' in self.api_data - - - def test_api_field_type_nodes(self): - """ Test for type for API Field - - nodes field must be dict - """ - - assert type(self.api_data['nodes'][0]) is dict - - - def test_api_field_exists_nodes_id(self): - """ Test for existance of API Field - - nodes.id field must exist - """ - - assert 'id' in self.api_data['nodes'][0] - - - def test_api_field_type_nodes_id(self): - """ Test for type for API Field - - nodes.id field must be int - """ - - assert type(self.api_data['nodes'][0]['id']) is int - - - def test_api_field_exists_nodes_display_name(self): - """ Test for existance of API Field - - nodes.display_name field must exist - """ - - assert 'display_name' in self.api_data['nodes'][0] - - - def test_api_field_type_nodes_display_name(self): - """ Test for type for API Field - - nodes.display_name field must be str - """ - - assert type(self.api_data['nodes'][0]['display_name']) is str - - - def test_api_field_exists_nodes_url(self): - """ Test for existance of API Field - - nodes.url field must exist - """ - - assert 'url' in self.api_data['nodes'][0] - - - def test_api_field_type_nodes_url(self): - """ Test for type for API Field - - nodes.url field must be Hyperlink - """ - - assert type(self.api_data['nodes'][0]['url']) is Hyperlink - - - - def test_api_field_exists_devices(self): - """ Test for existance of API Field - - devices field must exist - """ - - assert 'devices' in self.api_data - - - def test_api_field_type_devices(self): - """ Test for type for API Field - - devices field must be list - """ - - assert type(self.api_data['devices']) is list - - - def test_api_field_exists_devices_id(self): - """ Test for existance of API Field - - devices.id field must exist - """ - - assert 'id' in self.api_data['devices'][0] - - - def test_api_field_type_devices_id(self): - """ Test for type for API Field - - devices.id field must be int - """ - - assert type(self.api_data['devices'][0]['id']) is int - - - def test_api_field_exists_devices_display_name(self): - """ Test for existance of API Field - - devices.display_name field must exist - """ - - assert 'display_name' in self.api_data['devices'][0] - - - def test_api_field_type_devices_display_name(self): - """ Test for type for API Field - - devices.display_name field must be str - """ - - assert type(self.api_data['devices'][0]['display_name']) is str - - - def test_api_field_exists_devices_url(self): - """ Test for existance of API Field - - devices.url field must exist - """ - - assert 'url' in self.api_data['devices'][0] - - - def test_api_field_type_devices_url(self): - """ Test for type for API Field - - devices.url field must be Hyperlink - """ - - assert type(self.api_data['devices'][0]['url']) is Hyperlink - - - - def test_api_field_exists_cluster_type(self): - """ Test for existance of API Field - - cluster_type field must exist - """ - - assert 'cluster_type' in self.api_data - - - def test_api_field_type_cluster_type(self): - """ Test for type for API Field - - cluster_type field must be dict - """ - - assert type(self.api_data['cluster_type']) is dict - - - def test_api_field_exists_cluster_type_id(self): - """ Test for existance of API Field - - cluster_type.id field must exist - """ - - assert 'id' in self.api_data['cluster_type'] - - - def test_api_field_type_cluster_type_id(self): - """ Test for type for API Field - - cluster_type.id field must be int - """ - - assert type(self.api_data['cluster_type']['id']) is int - - - def test_api_field_exists_cluster_type_display_name(self): - """ Test for existance of API Field - - cluster_type.display_name field must exist - """ - - assert 'display_name' in self.api_data['cluster_type'] - - - def test_api_field_type_cluster_type_display_name(self): - """ Test for type for API Field - - cluster_type.display_name field must be str - """ - - assert type(self.api_data['cluster_type']['display_name']) is str - - - def test_api_field_exists_cluster_type_url(self): - """ Test for existance of API Field - - cluster_type.url field must exist - """ - - assert 'url' in self.api_data['cluster_type'] - - - def test_api_field_type_cluster_type_url(self): - """ Test for type for API Field - - cluster_type.url field must be Hyperlink - """ - - assert type(self.api_data['cluster_type']['url']) is Hyperlink - - - - def test_api_field_exists_parent_cluster(self): - """ Test for existance of API Field - - parent_cluster field must exist - """ - - assert 'parent_cluster' in self.api_data - - - def test_api_field_type_parent_cluster(self): - """ Test for type for API Field - - parent_cluster field must be dict - """ - - assert type(self.api_data['parent_cluster']) is dict - - - def test_api_field_exists_parent_cluster_id(self): - """ Test for existance of API Field - - parent_cluster.id field must exist - """ - - assert 'id' in self.api_data['parent_cluster'] - - - def test_api_field_type_parent_cluster_id(self): - """ Test for type for API Field - - parent_cluster.id field must be int - """ - - assert type(self.api_data['parent_cluster']['id']) is int - - - def test_api_field_exists_parent_cluster_display_name(self): - """ Test for existance of API Field - - parent_cluster.display_name field must exist - """ - - assert 'display_name' in self.api_data['parent_cluster'] - - - def test_api_field_type_parent_cluster_display_name(self): - """ Test for type for API Field - - parent_cluster.display_name field must be str - """ - - assert type(self.api_data['parent_cluster']['display_name']) is str - - - def test_api_field_exists_parent_cluster_url(self): - """ Test for existance of API Field - - parent_cluster.url field must exist - """ - - assert 'url' in self.api_data['parent_cluster'] - - - def test_api_field_type_parent_cluster_url(self): - """ Test for type for API Field - - parent_cluster.url field must be Hyperlink - """ - - assert type(self.api_data['parent_cluster']['url']) is Hyperlink - - - - def test_api_field_exists_urls_tickets(self): - """ Test for existance of API Field - - _urls.tickets field must exist - """ - - assert 'tickets' in self.api_data['_urls'] - - - def test_api_field_type_urls_tickets(self): - """ Test for type for API Field - - _urls.tickets field must be str - """ - - assert type(self.api_data['_urls']['tickets']) is str - - - - def test_api_field_exists_urls_external_links(self): - """ Test for existance of API Field - - _urls.external_links field must exist - """ - - assert 'external_links' in self.api_data['_urls'] - - - def test_api_field_type_urls_external_links(self): - """ Test for type for API Field - - _urls.external_links field must be str - """ - - assert type(self.api_data['_urls']['external_links']) is str diff --git a/app/itim/tests/unit/cluster/test_cluster_item_ticket_api_v2.py b/app/itim/tests/unit/cluster/test_cluster_item_ticket_api_v2.py deleted file mode 100644 index a87e03ad..00000000 --- a/app/itim/tests/unit/cluster/test_cluster_item_ticket_api_v2.py +++ /dev/null @@ -1,99 +0,0 @@ -import pytest - -from django.shortcuts import reverse -from django.test import Client, TestCase - -from core.tests.abstract.test_item_ticket_api_v2 import ItemTicketAPI - -from core.models.ticket.ticket_linked_items import TicketLinkedItem - -from itim.models.clusters import Cluster - - - -@pytest.mark.skip( reason = 'this ticket model is depreciated' ) -@pytest.mark.model_cluster -@pytest.mark.module_itim -class ClusterItemTicketAPI( - ItemTicketAPI, - TestCase, -): - """Test Cases for Item Tickets - - Args: - APITenancyObject (class): Base class for ALL field checks - """ - - item_type = TicketLinkedItem.Modules.CLUSTER - - item_class = 'cluster' - - item_model = Cluster - - - @classmethod - def setUpTestData(self): - """Setup Test - - 1. Create an organization for user and item - 2. Create an item - - """ - - super().setUpTestData() - - - self.linked_item = self.item_model.objects.create( - organization = self.organization, - name = 'dev' - ) - - - - self.item = self.model.objects.create( - organization = self.organization, - ticket = self.ticket, - - # Item attributes - - item = self.linked_item.id, - item_type = self.item_type, - ) - - - - self.url_view_kwargs = { - 'item_class': self.item_class, - 'item_id': self.item.id, - 'pk': self.item.id, - } - - - client = Client() - url = reverse('v2:_api_v2_item_tickets-detail', kwargs=self.url_view_kwargs) - - - client.force_login(self.view_user) - response = client.get(url) - - self.api_data = response.data - - - - def test_api_field_value_item_id(self): - """ Test for existance of API Field - - item.id field must exist - """ - - assert self.api_data['item']['id'] == self.linked_item.id - - - - def test_api_field_value_item_type(self): - """ Test for type for API Field - - item_type field must be int - """ - - assert self.api_data['item_type'] == self.item_type