diff --git a/test/icat/test_query.py b/test/icat/test_query.py index 869c6445..de399a18 100644 --- a/test/icat/test_query.py +++ b/test/icat/test_query.py @@ -345,66 +345,6 @@ def test_valid_get_distinct_attributes(self, icat_client): assert test_query.get_distinct_attributes() == ["summary", "name"] - @pytest.mark.parametrize( - "distinct_attrs, result, expected_output", - [ - pytest.param( - ["summary"], - ["Summary 1"], - {"summary": "Summary 1"}, - id="Single attribute", - ), - pytest.param( - ["startDate"], - ( - datetime( - year=2020, - month=1, - day=4, - hour=1, - minute=1, - second=1, - tzinfo=timezone.utc, - ), - ), - {"startDate": "2020-01-04 01:01:01+00:00"}, - id="Single date attribute", - ), - pytest.param( - ["summary", "title"], - ("Summary 1", "Title 1"), - {"summary": "Summary 1", "title": "Title 1"}, - id="Multiple attributes", - ), - pytest.param( - ["summary", "investigationUsers.role"], - ("Summary 1", "PI"), - {"summary": "Summary 1", "investigationUsers": {"role": "PI"}}, - id="Multiple attributes with related attribute", - ), - pytest.param( - ["summary", "investigationUsers.investigation.name"], - ("Summary 1", "Investigation Name 1"), - { - "summary": "Summary 1", - "investigationUsers": { - "investigation": {"name": "Investigation Name 1"}, - }, - }, - id="Multiple attributes with 2-level nested related attribute", - ), - ], - ) - def test_valid_map_distinct_attributes_to_results( - self, icat_client, distinct_attrs, result, expected_output, - ): - test_query = ICATQuery(icat_client, "Investigation") - test_output = test_query.map_distinct_attributes_to_results( - distinct_attrs, result, - ) - - assert test_output == expected_output - def test_include_fields_list_flatten(self, icat_client): included_field_set = { "investigationUsers.investigation.datasets", diff --git a/test/test_map_distinct_attrs.py b/test/test_map_distinct_attrs.py new file mode 100644 index 00000000..c151f9b6 --- /dev/null +++ b/test/test_map_distinct_attrs.py @@ -0,0 +1,63 @@ +from datagateway_api.common.helpers import map_distinct_attributes_to_results +from datetime import datetime, timezone + +import pytest + + +class TestMapDistinctAttrs: + @pytest.mark.parametrize( + "distinct_attrs, result, expected_output", + [ + pytest.param( + ["summary"], + ["Summary 1"], + {"summary": "Summary 1"}, + id="Single attribute", + ), + pytest.param( + ["startDate"], + ( + datetime( + year=2020, + month=1, + day=4, + hour=1, + minute=1, + second=1, + tzinfo=timezone.utc, + ), + ), + {"startDate": "2020-01-04 01:01:01+00:00"}, + id="Single date attribute", + ), + pytest.param( + ["summary", "title"], + ("Summary 1", "Title 1"), + {"summary": "Summary 1", "title": "Title 1"}, + id="Multiple attributes", + ), + pytest.param( + ["summary", "investigationUsers.role"], + ("Summary 1", "PI"), + {"summary": "Summary 1", "investigationUsers": {"role": "PI"}}, + id="Multiple attributes with related attribute", + ), + pytest.param( + ["summary", "investigationUsers.investigation.name"], + ("Summary 1", "Investigation Name 1"), + { + "summary": "Summary 1", + "investigationUsers": { + "investigation": {"name": "Investigation Name 1"}, + }, + }, + id="Multiple attributes with 2-level nested related attribute", + ), + ], + ) + def test_valid_map_distinct_attributes_to_results( + self, distinct_attrs, result, expected_output, + ): + test_output = map_distinct_attributes_to_results(distinct_attrs, result) + + assert test_output == expected_output