Skip to content

Commit

Permalink
test: unit test from_icat Member entity creation #265
Browse files Browse the repository at this point in the history
  • Loading branch information
VKTB committed Jan 17, 2022
1 parent 0d0a1e4 commit f2845e3
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/search_api/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,42 @@ def test_from_icat_instrument_entity_with_data_for_all_related_entities(self):
instrument_entity = models.Instrument.from_icat(icat_data, ["datasets"])

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

def test_from_icat_member_entity_without_data_for_related_entities(self):
member_entity = models.Member.from_icat(INVESTIGATION_USER_ICAT_DATA, [])

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

def test_from_icat_member_entity_with_data_for_mandatory_related_entities(self):
expected_entity_data = MEMBER_PANOSC_DATA.copy()
expected_entity_data["document"] = DOCUMENT_PANOSC_DATA

icat_data = INVESTIGATION_USER_ICAT_DATA.copy()
icat_data["investigation"] = INVESTIGATION_ICAT_DATA.copy()
icat_data["investigation"]["type"] = INVESTIGATION_TYPE_ICAT_DATA
icat_data["investigation"]["keywords"] = [KEYWORD_ICAT_DATA]

member_entity = models.Member.from_icat(icat_data, ["document"])

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

def test_from_icat_member_entity_with_data_for_all_related_entities(self):
expected_entity_data = MEMBER_PANOSC_DATA.copy()
expected_entity_data["document"] = DOCUMENT_PANOSC_DATA
expected_entity_data["person"] = PERSON_PANOSC_DATA
expected_entity_data["affiliation"] = AFFILIATION_PANOSC_DATA

icat_data = INVESTIGATION_USER_ICAT_DATA.copy()
icat_data["investigation"] = INVESTIGATION_ICAT_DATA.copy()
icat_data["investigation"]["type"] = INVESTIGATION_TYPE_ICAT_DATA
icat_data["investigation"]["keywords"] = [KEYWORD_ICAT_DATA]
icat_data["user"] = USER_ICAT_DATA.copy()
icat_data["user"]["dataPublicationUsers"] = [
{"affiliations": [AFFILIATION_ICAT_DATA]},
]

member_entity = models.Member.from_icat(
icat_data, ["document", "person", "affiliation"],
)

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

0 comments on commit f2845e3

Please sign in to comment.