Skip to content

Commit

Permalink
test: unit test from_icat Parameter entity creation #265
Browse files Browse the repository at this point in the history
  • Loading branch information
VKTB committed Jan 17, 2022
1 parent f2845e3 commit faed594
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/search_api/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,49 @@ def test_from_icat_member_entity_with_data_for_all_related_entities(self):
)

assert member_entity.dict(by_alias=True) == expected_entity_data

def test_from_icat_parameter_entity_without_data_for_related_entities(self):
icat_data = INVESTIGATION_PARAMETER_ICAT_DATA.copy()
icat_data["type"] = PARAMETER_TYPE_ICAT_DATA

parameter_entity = models.Parameter.from_icat(icat_data, [])

assert parameter_entity.dict(by_alias=True) == PARAMETER_PANOSC_DATA

def test_from_icat_parameter_entity_with_investigation_parameter_data(self):
expected_entity_data = PARAMETER_PANOSC_DATA.copy()
expected_entity_data["dataset"] = DATASET_PANOSC_DATA
expected_entity_data["document"] = DOCUMENT_PANOSC_DATA

icat_data = INVESTIGATION_PARAMETER_ICAT_DATA.copy()
icat_data["type"] = PARAMETER_TYPE_ICAT_DATA
icat_data["investigation"] = INVESTIGATION_ICAT_DATA.copy()
icat_data["investigation"]["type"] = INVESTIGATION_TYPE_ICAT_DATA
icat_data["investigation"]["keywords"] = [KEYWORD_ICAT_DATA]
icat_data["investigation"]["investigationInstruments"] = [
{"instrument": INSTRUMENT_ICAT_DATA.copy()},
{"instrument": INSTRUMENT_ICAT_DATA.copy()},
]
icat_data["investigation"]["investigationInstruments"][0]["instrument"][
"datasetInstruments"
] = [{"dataset": DATASET_ICAT_DATA}, {"dataset": DATASET_ICAT_DATA}]
icat_data["investigation"]["investigationInstruments"][1]["instrument"][
"datasetInstruments"
] = []

parameter_entity = models.Parameter.from_icat(icat_data, ["dataset"])

assert parameter_entity.dict(by_alias=True) == expected_entity_data

def test_from_icat_parameter_entity_with_dataset_parameter_data(self):
expected_entity_data = PARAMETER_PANOSC_DATA.copy()
expected_entity_data["value"] = DATASET_PARAMETER_ICAT_DATA["stringValue"]
expected_entity_data["dataset"] = DATASET_PANOSC_DATA

icat_data = DATASET_PARAMETER_ICAT_DATA.copy()
icat_data["dataset"] = DATASET_ICAT_DATA
icat_data["type"] = PARAMETER_TYPE_ICAT_DATA

parameter_entity = models.Parameter.from_icat(icat_data, ["dataset"])

assert parameter_entity.dict(by_alias=True) == expected_entity_data

0 comments on commit faed594

Please sign in to comment.