forked from ChelseaKR/ctdl-validate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_break_the_gate.py
More file actions
67 lines (49 loc) · 2.59 KB
/
Copy pathtest_break_the_gate.py
File metadata and controls
67 lines (49 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Break the gate on purpose before trusting it.
Discipline these tests encode: a gate is only trusted after deliberately
corrupting a known-good payload and confirming the gate catches the
corruption. Each test starts from the clean framework fixture (proven clean
first), breaks exactly one thing, and asserts the specific catch.
"""
from __future__ import annotations
import copy
from typing import Any
import pytest
from ctdl_validate import Severity, validate_document
from .conftest import load_fixture
@pytest.fixture()
def clean_payload() -> Any:
payload = load_fixture("clean_framework.json")
assert validate_document(payload) == [], "gate test requires a proven-clean baseline"
return copy.deepcopy(payload)
def test_stripping_ce_prefix_from_a_ctid_is_caught(clean_payload: Any) -> None:
node = clean_payload["@graph"][1]
node["ceterms:ctid"] = node["ceterms:ctid"].removeprefix("ce-")
findings = validate_document(clean_payload)
assert any(f.code == "CTID_BARE_UUID" and f.severity is Severity.ERROR for f in findings)
def test_pointing_ispartof_at_a_wrong_identifier_is_caught(clean_payload: Any) -> None:
node = clean_payload["@graph"][2]
node["ceasn:isPartOf"] = (
"https://credentialengineregistry.org/resources/ce-82566cee-17f3-4a6e-8f59-b45273aac457"
)
findings = validate_document(clean_payload)
assert any(f.code == "ISPARTOF_FRAMEWORK_MISMATCH" for f in findings)
def test_breaking_an_inverse_pair_is_caught(clean_payload: Any) -> None:
# Competency 2 stops pointing back at its parent; hasChild still points at it.
node = clean_payload["@graph"][2]
node["ceasn:isChildOf"] = (
"https://credentialengineregistry.org/resources/ce-9e492574-07fc-4154-b7f2-898425f4f3a3"
)
findings = validate_document(clean_payload)
assert any(f.code == "INVERSE_MISMATCH" and f.severity is Severity.ERROR for f in findings)
def test_retyping_the_framework_is_caught(clean_payload: Any) -> None:
# The framework becomes an Organization: isPartOf/isTopChildOf ranges break.
clean_payload["@graph"][0]["@type"] = "ceterms:Organization"
findings = validate_document(clean_payload)
assert any(f.code == "RANGE_VIOLATION" and f.severity is Severity.ERROR for f in findings)
def test_corrupting_a_registry_uri_is_caught(clean_payload: Any) -> None:
node = clean_payload["@graph"][0]
node["@id"] = "https://credentialengineregistry.org/resources/not-a-ctid-at-all"
findings = validate_document(clean_payload)
assert any(
f.code == "REGISTRY_URI_MALFORMED" and f.severity is Severity.ERROR for f in findings
)