From 29583b1ad37750535c81796af5750a31858ae8bf Mon Sep 17 00:00:00 2001 From: Viktor Bozhinov Date: Thu, 10 Feb 2022 16:22:25 +0000 Subject: [PATCH] test: test logic related to setting of Instrument pid #314 --- .../filters/test_search_api_where_filter.py | 12 ++++++++++++ test/search_api/test_models.py | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/test/search_api/filters/test_search_api_where_filter.py b/test/search_api/filters/test_search_api_where_filter.py index 60576894..fb4d91d5 100644 --- a/test/search_api/filters/test_search_api_where_filter.py +++ b/test/search_api/filters/test_search_api_where_filter.py @@ -16,6 +16,18 @@ class TestSearchAPIWhereFilter: "SELECT o FROM Instrument o WHERE o.name = 'WISH'", id="Regular WHERE filter", ), + pytest.param( + SearchAPIWhereFilter("pid", "1", "eq"), + "Instrument", + "SELECT o FROM Instrument o WHERE o.pid = '1'", + id="Pid instrument value (mapping that maps to multiple ICAT fields)", + ), + pytest.param( + SearchAPIWhereFilter("pid", "pid:1", "eq"), + "Instrument", + "SELECT o FROM Instrument o WHERE o.id = '1'", + id="Id instrument value (mapping that maps to multiple ICAT fields)", + ), pytest.param( SearchAPIWhereFilter("title", "My Dataset 1", "ne"), "Dataset", diff --git a/test/search_api/test_models.py b/test/search_api/test_models.py index e7b9ff07..c8377469 100644 --- a/test/search_api/test_models.py +++ b/test/search_api/test_models.py @@ -73,7 +73,7 @@ INSTRUMENT_ICAT_DATA = { "type": "Test type", - "pid": None, + "pid": "Test pid", "name": "Test name", "id": 1, "modTime": "2000-12-31 00:00:00+00:00", @@ -243,7 +243,7 @@ } INSTRUMENT_PANOSC_DATA = { - "pid": str(INSTRUMENT_ICAT_DATA["id"]), + "pid": INSTRUMENT_ICAT_DATA["pid"], "name": INSTRUMENT_ICAT_DATA["name"], "facility": FACILITY_ICAT_DATA["name"], "datasets": [], @@ -451,9 +451,11 @@ def test_from_icat_instrument_entity_without_data_for_related_entities(self): def test_from_icat_instrument_entity_with_data_for_all_related_entities(self): expected_entity_data = INSTRUMENT_PANOSC_DATA.copy() + expected_entity_data["pid"] = f"pid:{INSTRUMENT_ICAT_DATA['id']}" expected_entity_data["datasets"] = [DATASET_PANOSC_DATA] icat_data = INSTRUMENT_ICAT_DATA.copy() + icat_data["pid"] = None icat_data["facility"] = FACILITY_ICAT_DATA icat_data["datasetInstruments"] = [{"dataset": DATASET_ICAT_DATA.copy()}]