Skip to content

Commit

Permalink
fix[data builder]: Access doi value directly in literature
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Vagliano
  • Loading branch information
Lorenzovagliano committed Jan 14, 2025
1 parent 0afd2ac commit bfa6e57
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions inspire_schemas/builders/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def add_literature(self, doi=None, record=None):
"""Add literature.
:param doi: doi of the literature
:type doi: dict
:type doi: str
:param record: dictionary with ``$ref`` pointing to proper record.
:type record: dict
Expand All @@ -311,6 +311,7 @@ def add_literature(self, doi=None, record=None):
}

if doi:
literature_dict['doi'] = doi
doi_dict = {"value": doi}
literature_dict['doi'] = doi_dict

self._append_to('literature', literature_dict)
4 changes: 3 additions & 1 deletion tests/integration/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ def test_data_builder(data_data):

literatures = data_data['literature']
for literature in literatures:
builder.add_literature(literature.get("doi"), literature.get('record'))
doi_value = literature.get("doi", {}).get("value")
record = literature.get("record")
builder.add_literature(doi_value, record)
assert builder.record['literature'] == literatures

urls = data_data['urls']
Expand Down
11 changes: 7 additions & 4 deletions tests/unit/test_data_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,13 @@ def test_add_literature():

result = builder.record.get("literature")
expected = [
{
"doi": doi,
"record": record,
}
{
"doi":
{
"value":"10.1234/example.doi"
},
"record": record
}
]

assert result == expected

0 comments on commit bfa6e57

Please sign in to comment.