Skip to content

Commit 8afb37b

Browse files
author
notactuallyfinn
committed
split test_api_e2e.py into multiple files
1 parent 45459fc commit 8afb37b

9 files changed

Lines changed: 919 additions & 817 deletions

File tree

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# SPDX-FileCopyrightText: 2026 German Aerospace Center (DLR)
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# SPDX-FileContributor: Michael Fritzsche
6+
7+
import sys
8+
9+
import pytest
10+
11+
from hermes.commands import cli
12+
from hermes.model import context_manager, SoftwareMetadata
13+
14+
15+
@pytest.mark.parametrize(
16+
"process_result, res",
17+
[
18+
2 * (
19+
SoftwareMetadata({
20+
"@type": ["http://schema.org/SoftwareSourceCode"],
21+
"http://schema.org/description": [{"@value": "for testing"}],
22+
"http://schema.org/name": [{"@value": "Test"}]
23+
}),
24+
),
25+
2 * (
26+
SoftwareMetadata({
27+
"@type": ["http://schema.org/SoftwareSourceCode"],
28+
"http://schema.org/applicationCategory": [{"@id": "Testing"}],
29+
"http://schema.org/author": [
30+
{
31+
"@list": [
32+
{
33+
"@id": "_:author_1",
34+
"@type": ["http://schema.org/Person"],
35+
"http://schema.org/email": [{"@value": "test.testi@test.testi"}],
36+
"http://schema.org/familyName": [{"@value": "Testi"}],
37+
"http://schema.org/givenName": [{"@value": "Test"}]
38+
}
39+
]
40+
}
41+
],
42+
"http://schema.org/codeRepository": [{"@id": "https://github.com/softwarepub/hermes"}],
43+
"http://schema.org/contributor": [
44+
{
45+
"@id": "_:contributor_1",
46+
"@type": ["http://schema.org/Person"],
47+
"http://schema.org/email": [{"@value": "test.testi@test.testi"}],
48+
"http://schema.org/familyName": [{"@value": "Testi"}],
49+
"http://schema.org/givenName": [{"@value": "Test"}]
50+
}
51+
],
52+
"http://schema.org/dateCreated": [{"@type": "http://schema.org/Date", "@value": "2026-01-16"}],
53+
"http://schema.org/dateModified": [{"@type": "http://schema.org/Date", "@value": "2026-01-16"}],
54+
"http://schema.org/datePublished": [{"@type": "http://schema.org/Date", "@value": "2026-01-16"}],
55+
"http://schema.org/description": [{"@value": "for testing"}],
56+
"http://schema.org/funder": [
57+
{
58+
"@type": ["http://schema.org/Organization"],
59+
"http://schema.org/name": [{"@value": "TestsTests"}]
60+
}
61+
],
62+
"http://schema.org/keywords": [{"@value": "testing"}, {"@value": "more testing"}],
63+
"http://schema.org/license": [
64+
{"@id": "https://spdx.org/licenses/Adobe-2006"},
65+
{"@id": "https://spdx.org/licenses/Abstyles"},
66+
{"@id": "https://spdx.org/licenses/AGPL-1.0-only"}
67+
],
68+
"http://schema.org/name": [{"@value": "Test"}],
69+
"http://schema.org/operatingSystem": [{"@value": "Windows"}],
70+
"http://schema.org/programmingLanguage": [{"@value": "Python"}, {"@value": "Python 3"}],
71+
"http://schema.org/relatedLink": [{"@id": "https://docs.software-metadata.pub/en/latest"}],
72+
"http://schema.org/releaseNotes": [{"@value": "get it now"}],
73+
"http://schema.org/version": [{"@value": "1.1.1"}],
74+
"https://codemeta.github.io/terms/developmentStatus": [{"@id": "abandoned"}],
75+
"https://codemeta.github.io/terms/funding": [{"@value": "none :("}],
76+
"https://codemeta.github.io/terms/isSourceCodeOf": [{"@id": "HERMES"}],
77+
"https://codemeta.github.io/terms/issueTracker": [
78+
{"@id": "https://github.com/softwarepub/hermes/issues"}
79+
],
80+
"https://codemeta.github.io/terms/referencePublication": [{"@id": "https://arxiv.org/abs/2201.09015"}]
81+
}),
82+
),
83+
]
84+
)
85+
def test_do_nothing_curate(tmp_path, monkeypatch, process_result, res):
86+
monkeypatch.chdir(tmp_path)
87+
88+
manager = context_manager.HermesContext(tmp_path)
89+
manager.prepare_step("process")
90+
with manager["result"] as cache:
91+
cache["expanded"] = process_result.ld_value
92+
cache["context"] = {"@context": process_result.full_context}
93+
manager.finalize_step("process")
94+
95+
config_file = tmp_path / "hermes.toml"
96+
config_file.write_text("")
97+
98+
orig_argv = sys.argv[:]
99+
sys.argv = ["hermes", "curate", "--path", str(tmp_path), "--config", str(config_file)]
100+
result = {}
101+
try:
102+
monkeypatch.setattr(context_manager.HermesContext.__init__, "__defaults__", (tmp_path.cwd(),))
103+
cli.main()
104+
except SystemExit as e:
105+
if e.code != 0:
106+
raise e
107+
finally:
108+
manager.prepare_step("curate")
109+
result = SoftwareMetadata.load_from_cache(manager, "result")
110+
manager.finalize_step("curate")
111+
sys.argv = orig_argv
112+
113+
assert result.data_dict == res.data_dict
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SPDX-FileCopyrightText: 2026 German Aerospace Center (DLR)
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# SPDX-FileContributor: Michael Fritzsche
6+
7+
import json
8+
import sys
9+
10+
import pytest
11+
12+
from hermes.commands import cli
13+
from hermes.model import context_manager, SoftwareMetadata
14+
15+
16+
@pytest.mark.parametrize(
17+
"metadata",
18+
[
19+
SoftwareMetadata({
20+
"@type": ["http://schema.org/SoftwareSourceCode"],
21+
"http://schema.org/description": [{"@value": "for testing"}],
22+
"http://schema.org/name": [{"@value": "Test"}]
23+
}),
24+
]
25+
)
26+
def test_file_deposit(tmp_path, monkeypatch, metadata):
27+
monkeypatch.chdir(tmp_path)
28+
29+
manager = context_manager.HermesContext(tmp_path)
30+
manager.prepare_step("curate")
31+
with manager["result"] as cache:
32+
cache["codemeta"] = metadata.compact()
33+
manager.finalize_step("curate")
34+
35+
config_file = tmp_path / "hermes.toml"
36+
config_file.write_text("[deposit]\ntarget = \"file\"")
37+
38+
orig_argv = sys.argv[:]
39+
sys.argv = ["hermes", "deposit", "--path", str(tmp_path), "--config", str(config_file)]
40+
result = {}
41+
try:
42+
monkeypatch.setattr(context_manager.HermesContext.__init__, "__defaults__", (tmp_path.cwd(),))
43+
cli.main()
44+
except SystemExit as e:
45+
if e.code != 0:
46+
raise e
47+
finally:
48+
with open("codemeta.json", "r") as cache:
49+
result = SoftwareMetadata(json.load(cache))
50+
sys.argv = orig_argv
51+
52+
assert result == metadata

test/hermes_test/commands/deposit/test_invenio.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import click
1313
import pytest
1414

15-
pytest.skip("FIXME: Re-enable test after data model refactoring is done.", allow_module_level=True)
16-
1715
from hermes.commands.deposit import invenio
1816
from hermes.error import MisconfigurationError
1917

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# SPDX-FileCopyrightText: 2026 German Aerospace Center (DLR)
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# SPDX-FileContributor: Michael Fritzsche
6+
7+
from datetime import date
8+
from pathlib import Path
9+
import sys
10+
11+
import pytest
12+
13+
from hermes.commands import cli
14+
from hermes.model import context_manager
15+
from hermes.model.api import SoftwareMetadata
16+
17+
18+
@pytest.fixture
19+
def sandbox_auth():
20+
path = Path("./../auth.txt")
21+
if not path.exists():
22+
pytest.skip("Local auth token file does not exist.")
23+
with path.open() as f:
24+
yield f.read()
25+
26+
27+
@pytest.mark.parametrize(
28+
"metadata, invenio_metadata",
29+
[
30+
(
31+
SoftwareMetadata({
32+
"@type": ["http://schema.org/SoftwareSourceCode"],
33+
"http://schema.org/description": [{"@value": "for testing"}],
34+
"http://schema.org/name": [{"@value": "Test"}],
35+
"http://schema.org/author": [{
36+
"@type": "http://schema.org/Person",
37+
"http://schema.org/familyName": [{"@value": "Test"}],
38+
"http://schema.org/givenName": [{"@value": "Testi"}]
39+
}],
40+
"http://schema.org/license": [{"@id": "https://spdx.org/licenses/Apache-2.0"}]
41+
}),
42+
{
43+
"upload_type": "software",
44+
"publication_date": date.today().isoformat(),
45+
"title": "Test",
46+
"creators": [{"name": "Test, Testi"}],
47+
"description": "for testing",
48+
"access_right": "closed",
49+
"license": "apache-2.0",
50+
"prereserve_doi": True,
51+
"related_identifiers": [
52+
{"identifier": "10.5281/zenodo.13311079", "relation": "isCompiledBy", "scheme": "doi"}
53+
]
54+
}
55+
)
56+
]
57+
)
58+
def test_invenio_deposit(tmp_path, monkeypatch, sandbox_auth, metadata, invenio_metadata):
59+
monkeypatch.chdir(tmp_path)
60+
61+
manager = context_manager.HermesContext(tmp_path)
62+
manager.prepare_step("curate")
63+
with manager["result"] as cache:
64+
cache["codemeta"] = metadata.compact()
65+
manager.finalize_step("curate")
66+
67+
(tmp_path / "test.txt").write_text("Test, oh wonderful test!\n")
68+
69+
config_file = tmp_path / "hermes.toml"
70+
config_file.write_text(f"""[deposit]
71+
target = "invenio"
72+
[deposit.invenio]
73+
site_url = "https://sandbox.zenodo.org"
74+
access_right = "closed"
75+
auth_token = "{sandbox_auth}"
76+
files = ["test.txt"]
77+
[deposit.invenio.api_paths]
78+
licenses = "api/vocabularies/licenses"
79+
""")
80+
81+
orig_argv = sys.argv[:]
82+
sys.argv = ["hermes", "deposit", "--path", str(tmp_path), "--config", str(config_file), "--initial"]
83+
result = {}
84+
try:
85+
monkeypatch.setattr(context_manager.HermesContext.__init__, "__defaults__", (tmp_path.cwd(),))
86+
cli.main()
87+
except SystemExit as e:
88+
if e.code != 0:
89+
raise e
90+
finally:
91+
manager.prepare_step("deposit")
92+
with manager["invenio"] as cache:
93+
result = cache["deposit"]
94+
manager.finalize_step("deposit")
95+
sys.argv = orig_argv
96+
97+
assert result == invenio_metadata

0 commit comments

Comments
 (0)