Skip to content

Commit 96861ec

Browse files
author
notactuallyfinn
committed
adjusted invenio.py and its test a bit
1 parent 382e2c3 commit 96861ec

3 files changed

Lines changed: 45 additions & 22 deletions

File tree

src/hermes/commands/deposit/invenio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ def _codemeta_to_invenio_deposition(self) -> dict:
513513

514514
creators = []
515515
for author in metadata.get("author", []):
516+
if not "Person" in author.get("@type", []):
517+
continue
516518
creator = {}
517519
if len(
518520
affils := [

src/hermes/commands/deposit/invenio_rdm.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
# SPDX-FileContributor: Oliver Bertuch
77
# SPDX-FileContributor: Michael Meinel
88

9-
import typing as t
10-
119
from requests import HTTPError
10+
from typing import Union
1211

1312
from hermes.commands.deposit.invenio import InvenioClient, InvenioDepositPlugin, InvenioResolver
1413

@@ -27,7 +26,7 @@ def get_licenses(self):
2726
class InvenioRDMResolver(InvenioResolver):
2827
invenio_client_class = InvenioRDMClient
2928

30-
def resolve_license_id(self, license_url: t.Optional[str]) -> t.Optional[dict]:
29+
def resolve_license_id(self, license_url: Union[str, None]) -> Union[dict, None]:
3130
"""Deliberately try to resolve the license URL to a valid InvenioRDM license information record from the
3231
vocabulary.
3332
@@ -47,6 +46,12 @@ def resolve_license_id(self, license_url: t.Optional[str]) -> t.Optional[dict]:
4746
except HTTPError:
4847
pass
4948

49+
# FIXME: Why not get all license_cross_refs and then use a query parameter like this:
50+
# ?q=props.url:("license_url" OR "license_cross_ref[1]" OR ...)&size=1000
51+
# That would be able to replace _search_license_info.
52+
# FIXME: Some licenses in valid_licenses["hits"]["hits"]["props"]["url"] are only http although
53+
# https://spdx.org/licenses/license.json lists them in crossRef as https
54+
5055
# If the easy "mapping" did not work, we really need to "search" for the correct license ID.
5156
response = self.client.get_licenses()
5257
response.raise_for_status()
@@ -65,6 +70,7 @@ def resolve_license_id(self, license_url: t.Optional[str]) -> t.Optional[dict]:
6570
if license_info is not None:
6671
break
6772
else:
73+
# FIXME: Why is this only raised here and not always when license_info is None?
6874
raise RuntimeError(f"Could not resolve license URL {license_url} to a valid identifier.")
6975

7076
return license_info
@@ -73,7 +79,7 @@ def resolve_license_id(self, license_url: t.Optional[str]) -> t.Optional[dict]:
7379
def _extract_license_id_from_response(data: dict) -> str:
7480
return data["id"]
7581

76-
def _search_license_info(self, _url: str, valid_licenses: dict) -> t.Optional[dict]:
82+
def _search_license_info(self, _url: str, valid_licenses: dict) -> Union[dict, None]:
7783
for license_info in valid_licenses['hits']['hits']:
7884
try:
7985
if license_info['props']['url'] == _url:

test/hermes_test/model/test_api_e2e.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def sandbox_auth():
172172
"http://schema.org/license": [{"@id": "https://spdx.org/licenses/Apache-2.0"}],
173173
"http://schema.org/name": [{"@value": "Test"}],
174174
"http://schema.org/url": [
175-
{"@id": 'https://arxiv.org/abs/2201.09015'},
175+
{"@id": "https://arxiv.org/abs/2201.09015"},
176176
{"@id": "https://docs.software-metadata.pub/en/latest"}
177177
],
178178
"http://schema.org/version": [{"@value": "9.0.1"}]
@@ -398,30 +398,45 @@ def test_file_deposit(tmp_path, monkeypatch, metadata):
398398
if e.code != 0:
399399
raise e
400400
finally:
401-
with open('codemeta.json', 'r') as cache:
401+
with open("codemeta.json", "r") as cache:
402402
result = SoftwareMetadata(json.load(cache))
403403
sys.argv = orig_argv
404404

405405
assert result == metadata
406406

407407

408408
@pytest.mark.parametrize(
409-
"metadata",
409+
"metadata, invenio_metadata",
410410
[
411-
SoftwareMetadata({
412-
"@type": ["http://schema.org/SoftwareSourceCode"],
413-
"http://schema.org/description": [{"@value": "for testing"}],
414-
"http://schema.org/name": [{"@value": "Test"}],
415-
"http://schema.org/author": [{
416-
"@type": "http://schema.org/Person",
417-
"http://schema.org/familyName": [{"@value": "Test"}],
418-
"http://schema.org/givenName": [{"@value": "Testi"}]
419-
}],
420-
"http://schema.org/license": [{"@id": "https://spdx.org/licenses/apache-2.0"}]
421-
}),
411+
(
412+
SoftwareMetadata({
413+
"@type": ["http://schema.org/SoftwareSourceCode"],
414+
"http://schema.org/description": [{"@value": "for testing"}],
415+
"http://schema.org/name": [{"@value": "Test"}],
416+
"http://schema.org/author": [{
417+
"@type": "http://schema.org/Person",
418+
"http://schema.org/familyName": [{"@value": "Test"}],
419+
"http://schema.org/givenName": [{"@value": "Testi"}]
420+
}],
421+
"http://schema.org/license": [{"@id": "https://spdx.org/licenses/Apache-2.0"}]
422+
}),
423+
{
424+
"upload_type": "software",
425+
"publication_date": "2026-02-02",
426+
"title": "Test",
427+
"creators": [{"name": "Test, Testi"}],
428+
"description": "for testing",
429+
"access_right": "closed",
430+
"license": "apache-2.0",
431+
"prereserve_doi": True,
432+
"related_identifiers": [
433+
{"identifier": "10.5281/zenodo.13311079", "relation": "isCompiledBy", "scheme": "doi"}
434+
]
435+
}
436+
)
422437
]
423438
)
424-
def test_invenio_deposit(tmp_path, monkeypatch, sandbox_auth, metadata):
439+
def test_invenio_deposit(tmp_path, monkeypatch, sandbox_auth, metadata, invenio_metadata):
425440
monkeypatch.chdir(tmp_path)
426441

427442
manager = context_manager.HermesContext(tmp_path)
@@ -453,10 +468,10 @@ def test_invenio_deposit(tmp_path, monkeypatch, sandbox_auth, metadata):
453468
raise e
454469
finally:
455470
manager.prepare_step("deposit")
456-
with manager["deposit"] as cache:
457-
result = cache["result"]
471+
with manager["invenio"] as cache:
472+
result = cache["deposit"]
458473
manager.finalize_step("deposit")
459474
sys.argv = orig_argv
460475

461476
# TODO: compare to actually expected value
462-
assert result == {}
477+
assert result == invenio_metadata

0 commit comments

Comments
 (0)