Skip to content

Commit 5eff111

Browse files
committed
test(profiles): ✅ assert invalid-JSON file descriptor reporting and fail-fast abort
1 parent 05c7b25 commit 5eff111

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

tests/integration/profiles/ro-crate-1.2/test_metadata_document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_not_json():
4949
False,
5050
profile_identifier="ro-crate-1.2",
5151
expected_triggered_requirements=["File Descriptor JSON format"],
52-
expected_triggered_issues=['RO-Crate file descriptor "ro-crate-metadata.json" is not in the correct format'],
52+
expected_triggered_issues=['RO-Crate file descriptor "ro-crate-metadata.json" is not valid JSON'],
5353
)
5454

5555

tests/integration/profiles/ro-crate/test_file_descriptor_format.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import logging
1616

17-
from rocrate_validator import models
17+
from rocrate_validator import models, services
1818
from tests.ro_crates import InvalidFileDescriptor, ValidROC
1919
from tests.shared import do_entity_test
2020

@@ -32,8 +32,44 @@ def test_missing_file_descriptor():
3232

3333

3434
def test_not_valid_json_format():
35-
"""Test a RO-Crate with an invalid JSON file descriptor format."""
36-
do_entity_test(paths.invalid_json_format, models.Severity.REQUIRED, False, ["File Descriptor JSON format"], [])
35+
"""
36+
Test a RO-Crate with an invalid JSON file descriptor format.
37+
38+
The validator must emit an ad-hoc issue reporting that the file descriptor is
39+
not valid JSON, including the position of the parsing error.
40+
"""
41+
do_entity_test(
42+
paths.invalid_json_format,
43+
models.Severity.REQUIRED,
44+
False,
45+
["File Descriptor JSON format"],
46+
['RO-Crate file descriptor "ro-crate-metadata.json" is not valid JSON'],
47+
)
48+
49+
50+
def test_not_valid_json_format_aborts_validation():
51+
"""
52+
An unparsable JSON file descriptor must abort the validation (fail-fast).
53+
54+
Since the metadata cannot be read, no further check can run meaningfully, so the
55+
only reported failure must be the JSON-format one (no false positives).
56+
"""
57+
result = services.validate(
58+
models.ValidationSettings(
59+
rocrate_uri=models.URI(paths.invalid_json_format),
60+
requirement_severity=models.Severity.REQUIRED,
61+
)
62+
)
63+
assert not result.passed(), "An invalid-JSON crate must not pass validation"
64+
65+
failed_requirements = [r.name for r in result.failed_requirements]
66+
assert failed_requirements == ["File Descriptor JSON format"], (
67+
f"Only the JSON-format requirement should fail, got: {failed_requirements}"
68+
)
69+
70+
issues = [i.message for i in result.get_issues(models.Severity.REQUIRED) if i.message]
71+
assert len(issues) == 1, f"Exactly one issue expected, got: {issues}"
72+
assert "is not valid JSON" in issues[0]
3773

3874

3975
def test_not_valid_jsonld_format_missing_context():

0 commit comments

Comments
 (0)