From 0a34aff3653e140f6a652f14994a243f70ecb227 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 8 Nov 2024 08:19:53 -0500 Subject: [PATCH] Add test --- tests/utils/datatypes/datatype_tests.py | 44 ++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/tests/utils/datatypes/datatype_tests.py b/tests/utils/datatypes/datatype_tests.py index 44b8ee9e980..cac6b44650f 100644 --- a/tests/utils/datatypes/datatype_tests.py +++ b/tests/utils/datatypes/datatype_tests.py @@ -17,10 +17,11 @@ """ import uuid +from unittest import mock from arches.app.datatypes.base import BaseDataType from arches.app.datatypes.datatypes import DataTypeFactory -from arches.app.models.models import Language +from arches.app.models.models import Language, Node from arches.app.models.tile import Tile from tests.base_test import ArchesTestCase @@ -246,3 +247,44 @@ def test_pre_structure_tile_data(self): self.assertIsNotNone(tile1.data[nodeid]) self.assertTrue("url_label" in tile1.data[nodeid]) self.assertFalse(tile1.data[nodeid]["url_label"]) + + +class ResourceInstanceListDataTypeTests(ArchesTestCase): + mock_display_value = {"@display_value": "mock display value"} + + @mock.patch( + "arches.app.datatypes.base.BaseDataType.compile_json", + return_value=mock_display_value, + ) + def test_to_json(self, _mock): + ri_list = DataTypeFactory().get_instance("resource-instance-list") + node = Node(pk=uuid.uuid4()) + resource_1_id = uuid.uuid4() + resource_2_id = uuid.uuid4() + tile = Tile( + { + "resourceinstance_id": uuid.uuid4(), + "nodegroup_id": str(node.pk), + "tileid": "", + "data": { + str(node.pk): [ + { + "resourceId": str(resource_1_id), + "ontologyProperty": "", + "inverseOntologyProperty": "", + }, + { + "resourceId": str(resource_2_id), + "ontologyProperty": "", + "inverseOntologyProperty": "", + }, + ] + }, + } + ) + + # TODO: remove mock, fix underlying functionality to not + # requery for Resource objects yet again in get_display_value(). + with self.assertNumQueries(1): + json = ri_list.to_json(tile, node) + self.assertEqual(json, self.mock_display_value)