Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Nov 8, 2024
1 parent 05b4f94 commit 0a34aff
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion tests/utils/datatypes/datatype_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit 0a34aff

Please sign in to comment.