From b20b426432efcd515b6d45b89e5ad384f665da46 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 17 Jun 2024 14:10:12 +0930 Subject: [PATCH] test(itam): tests for device type history entries !27 #15 --- .../test_device_type_core_history.py | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 app/itam/tests/device_type/test_device_type_core_history.py diff --git a/app/itam/tests/device_type/test_device_type_core_history.py b/app/itam/tests/device_type/test_device_type_core_history.py new file mode 100644 index 00000000..99ffe140 --- /dev/null +++ b/app/itam/tests/device_type/test_device_type_core_history.py @@ -0,0 +1,72 @@ + +import pytest +import unittest +import requests + +from django.test import TestCase, Client + +from access.models import Organization + +from core.models.history import History +from core.tests.abstract.history_entry import HistoryEntry +from core.tests.abstract.history_entry_parent_model import HistoryEntryParentItem + + +from itam.models.device import DeviceType + + + +class DeviceTypeHistory(TestCase, HistoryEntry, HistoryEntryParentItem): + + + model = DeviceType + + + @classmethod + def setUpTestData(self): + """ Setup Test """ + + organization = Organization.objects.create(name='test_org') + + self.organization = organization + + self.item_create = self.model.objects.create( + name = 'test_item_' + self.model._meta.model_name, + organization = self.organization + ) + + + self.history_create = History.objects.get( + action = History.Actions.ADD[0], + item_pk = self.item_create.pk, + item_class = self.model._meta.model_name, + ) + + self.item_change = self.item_create + self.item_change.name = 'test_item_' + self.model._meta.model_name + '_changed' + self.item_change.save() + + self.field_after_expected_value = '{"name": "test_item_' + self.model._meta.model_name + '_changed"}' + + self.history_change = History.objects.get( + action = History.Actions.UPDATE[0], + item_pk = self.item_change.pk, + item_class = self.model._meta.model_name, + ) + + self.item_delete = self.model.objects.create( + name = 'test_item_delete_' + self.model._meta.model_name, + organization = self.organization + ) + + self.item_delete.delete() + + self.history_delete = History.objects.filter( + item_pk = self.item_delete.pk, + item_class = self.model._meta.model_name, + ) + + self.history_delete_children = History.objects.filter( + item_parent_pk = self.item_delete.pk, + item_parent_class = self.model._meta.model_name, + )