Skip to content

Commit

Permalink
fix test_search_model_mocked
Browse files Browse the repository at this point in the history
  • Loading branch information
rababerladuseladim committed Sep 22, 2023
1 parent 0944fbe commit 4a045cf
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions mex/common/models/extracted_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,28 @@ def set_identifiers(cls, values: dict[str, Any]) -> dict[str, Any]:

# validate ID in primary source and primary source ID
if identifier_in_primary_source := values.get("identifierInPrimarySource"):
identifier_in_primary_source = str(identifier_in_primary_source)
if isinstance(identifier_in_primary_source, list):
if len(identifier_in_primary_source) == 1:
identifier_in_primary_source = str(identifier_in_primary_source[0])
else:
raise ValueError(
f"Expected one value for identifierInPrimarySource, got {len(identifier_in_primary_source)}"
)
else:
identifier_in_primary_source = str(identifier_in_primary_source)
else:
raise ValueError("Missing value for `identifierInPrimarySource`.")

if had_primary_source := values.get("hadPrimarySource"):
had_primary_source = PrimarySourceID(had_primary_source)
if isinstance(had_primary_source, list):
if len(had_primary_source) == 1:
had_primary_source = PrimarySourceID(had_primary_source[0])
else:
raise ValueError(
f"Expected one value for hadPrimarySource, got {len(had_primary_source)}"
)
else:
had_primary_source = PrimarySourceID(had_primary_source)
else:
raise ValueError("Missing value for `hadPrimarySource`.")

Expand All @@ -88,11 +104,25 @@ def set_identifiers(cls, values: dict[str, Any]) -> dict[str, Any]:
if identifier := values.get("identifier"):
if identity is None:
raise ValueError("Identifier not found by identity provider.")
if isinstance(identifier, list):
if len(identifier) == 1:
identifier = identifier[0]
else:
raise ValueError(
f"Expected one value for Identifier, got {len(identifier)}"
)
if identity.identifier != str(identifier):
raise ValueError("Identifier cannot be set manually to new value.")

# validate stable target ID
if stable_target_id := values.get("stableTargetId"):
if isinstance(stable_target_id, list):
if len(stable_target_id) == 1:
stable_target_id = stable_target_id[0]
else:
raise ValueError(
f"Expected one value for stableTargetId, got {len(stable_target_id)}"
)
if (
identity is None
and stable_target_id != MEX_PRIMARY_SOURCE_STABLE_TARGET_ID
Expand Down

0 comments on commit 4a045cf

Please sign in to comment.