Skip to content

Commit

Permalink
authors: fix get id function
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalEgn authored and drjova committed Feb 6, 2024
1 parent 16a9df9 commit ff59976
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ def get_ids(data):
author_record = AuthorsRecord.get_record_by_pid_value(
get_recid_from_ref(data["record"])
)
bai = get_first_value_for_schema(
author_record.get("ids", []), "INSPIRE BAI"
)
if bai:
ids_from_lit_record.append({"schema": "INSPIRE BAI", "value": bai})
except (PIDDoesNotExistError, KeyError):
return missing
bai = get_first_value_for_schema(author_record.get("ids", []), "INSPIRE BAI")
if bai:
ids_from_lit_record.append({"schema": "INSPIRE BAI", "value": bai})
pass
return ids_from_lit_record or missing

@pre_dump
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,56 @@ def test_first_author():
result = schema.dumps(dump).data

assert expected == orjson.loads(result)


def test_authors_ids():
schema = AuthorSchemaV1()

dump = {
"full_name": "Castle, Frank",
"ids": [
{"value": "0000-0002-6152-062X", "schema": "ORCID"},
],
}
expected = {
"full_name": "Castle, Frank",
"first_name": "Frank",
"last_name": "Castle",
"ids": [
{"value": "0000-0002-6152-062X", "schema": "ORCID"},
],
}
result = schema.dumps(dump).data
assert expected == orjson.loads(result)

dump = {
"full_name": "Castle, Frank",
"ids": [{"value": "G.Aad.1", "schema": "INSPIRE BAI"}],
}
expected = {
"full_name": "Castle, Frank",
"first_name": "Frank",
"last_name": "Castle",
"ids": [{"value": "G.Aad.1", "schema": "INSPIRE BAI"}],
}
result = schema.dumps(dump).data
assert expected == orjson.loads(result)

dump = {
"full_name": "Castle, Frank",
"ids": [
{"value": "0000-0002-6152-062X", "schema": "ORCID"},
{"value": "G.Aad.1", "schema": "INSPIRE BAI"},
],
}
expected = {
"full_name": "Castle, Frank",
"first_name": "Frank",
"last_name": "Castle",
"ids": [
{"value": "0000-0002-6152-062X", "schema": "ORCID"},
{"value": "G.Aad.1", "schema": "INSPIRE BAI"},
],
}
result = schema.dumps(dump).data
assert expected == orjson.loads(result)

0 comments on commit ff59976

Please sign in to comment.