Skip to content

Commit ed0916b

Browse files
author
notactuallyfinn
committed
fixed bugs in invenio.py
1 parent 4f6cc9d commit ed0916b

2 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/hermes/commands/deposit/invenio.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ def upload_artifacts(self) -> None:
442442
if self.command.args.file:
443443
files = *self.config.files, *[f[0] for f in self.command.args.file]
444444
else:
445-
files = tuple(*self.config.files)
445+
files = tuple(self.config.files)
446+
446447
for path_arg in files:
447448
path = Path(path_arg)
448449

@@ -511,11 +512,17 @@ def _codemeta_to_invenio_deposition(self) -> dict:
511512
creator = {}
512513
if len(affils := [name for affil in author["affiliation"] for name in affil["legalname"]]) != 0:
513514
creator["affiliation"] = affils
514-
given_names_str = " ".join(author["givenName"])
515-
names = [f"{family_name}, {given_names_str}" for family_name in author["familyName"]]
516-
names.extend(author["names"])
517-
if len(names) != 0:
518-
creator["name"] = names
515+
if len(author["familyName"]) > 1:
516+
raise HermesValidationError(f"Author has too many family names: {author.to_python()}")
517+
if len(author["familyName"]) == 1:
518+
given_names_str = " ".join(author["givenName"])
519+
name = f"{author["familyName"][0]}, {given_names_str}"
520+
elif len(author["name"]) != 1:
521+
raise HermesValidationError(f"Author has too many names: {author.to_python()}")
522+
else:
523+
name = author["name"][0]
524+
if len(name) != 0:
525+
creator["name"] = name
519526
if (id := author.get("@id", None)) is not None:
520527
creator["orcid"] = id.replace("https://orcid.org/", "")
521528
if creator:

test/hermes_test/model/test_api_e2e.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def test_cff_harvest(tmp_path, monkeypatch, cff, res):
205205

206206
# FIXME: update to compare the SoftwareMetadata objects instead of the data_dicts (in multiple places)
207207
# after merge with refactor/data-model and/or refactor/423-implement-public-api
208-
assert result.data_dict == res.data_dict
208+
assert result == res
209209

210210

211211
@pytest.mark.parametrize(
@@ -363,7 +363,7 @@ def test_codemeta_harvest(tmp_path, monkeypatch, codemeta, res):
363363
finally:
364364
sys.argv = orig_argv
365365

366-
assert result.data_dict == res.data_dict
366+
assert result == res
367367

368368

369369
@pytest.mark.parametrize(
@@ -402,7 +402,7 @@ def test_file_deposit(tmp_path, monkeypatch, deposit, res):
402402
finally:
403403
sys.argv = orig_argv
404404

405-
assert result.data_dict == res.data_dict
405+
assert result == res
406406

407407

408408
@pytest.mark.parametrize(
@@ -432,12 +432,12 @@ def test_invenio_deposit(tmp_path, monkeypatch, sandbox_auth, metadata):
432432

433433
config_file = tmp_path / "hermes.toml"
434434
config_file.write_text(f"""[deposit]
435-
target = \"invenio\"
435+
target = "invenio"
436436
[deposit.invenio]
437-
site_url = \"https://sandbox.zenodo.org\"
438-
access_right = \"closed\"
439-
auth_token = \"{sandbox_auth}\"
440-
file = []
437+
site_url = "https://sandbox.zenodo.org"
438+
access_right = "closed"
439+
auth_token = "{sandbox_auth}"
440+
files = ["hermes.toml"]
441441
[deposit.invenio.api_paths]
442442
licenses = "api/vocabularies/licenses"
443443
""")
@@ -455,9 +455,7 @@ def test_invenio_deposit(tmp_path, monkeypatch, sandbox_auth, metadata):
455455
finally:
456456
sys.argv = orig_argv
457457

458-
assert result.data_dict == metadata.data_dict
458+
assert result == metadata
459459

460-
# TODO:
461-
# - handle get() on Softwaremetadata objects in invenio.py
462-
# - Sophie genaueres bezüglich Zeiten für Arbeitszeiterhöhung und -zeitraumerweiterung schicken
460+
# TODO: handle get() on Softwaremetadata objects in invenio.py
463461

0 commit comments

Comments
 (0)