Skip to content

Commit e5bd352

Browse files
committed
Added tests for ruleset 2. Also addressed Eli's comments on the PR.
1 parent 27f8555 commit e5bd352

File tree

8 files changed

+169
-211
lines changed

8 files changed

+169
-211
lines changed

rocrate_validator/profiles/five-safes-crate/must/1_funder.ttl

Lines changed: 0 additions & 36 deletions
This file was deleted.

rocrate_validator/profiles/five-safes-crate/must/1_root_data_entity_metadata.ttl

Lines changed: 0 additions & 38 deletions
This file was deleted.

rocrate_validator/profiles/five-safes-crate/must/2_requesting_agent.ttl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ five-safes-crate:CreateActionHasAgent
5959
sh:class schema:Organization ;
6060
sh:nodeKind sh:IRI ;
6161
sh:severity sh:Violation ;
62-
sh:message "The affiliation (if any) of a CreateAction's agent MUST be a schema:Organization and be an IRI." ;
62+
sh:message "The affiliation of a CreateAction's agent MUST be a schema:Organization and be an IRI." ;
6363
] .

rocrate_validator/profiles/five-safes-crate/should/2_requesting_agent.ttl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,4 @@ five-safes-crate:PersonAgentHasAffiliation
4646
sh:minCount 1 ;
4747
sh:severity sh:Warning ;
4848
sh:message "The agent of a CreateAction entity SHOULD have an affiliation" ;
49-
] ;
50-
51-
# If the agent has an affiliation, validate the affiliation node's IRI
52-
sh:property [
53-
a sh:PropertyShape ;
54-
sh:name "Affiliation IRI" ;
55-
sh:path schema:affiliation ;
56-
sh:nodeKind sh:IRI ;
57-
sh:or (
58-
[ sh:pattern "^https://ror\\.org/0[0-9a-hjkmnp-tv-z]{6}[0-9]{2}$" ; sh:flags "i"]
59-
[ sh:pattern "^https://isni\\.org/isni/\\d{15}[\\dX]$" ; sh:flags "i"]
60-
[ sh:pattern "^https://(?:www\\.)?wikidata\\.org/entity/Q\\d+$" ; sh:flags "i"]
61-
) ;
62-
sh:severity sh:Warning ;
63-
sh:message "Affiliation Organization @id SHOULD be a permalink (ROR/ISNI/Wikidata)." ;
6449
] .
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Copyright (c) 2024-2025 CRS4
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import logging
16+
17+
from rocrate_validator.models import Severity
18+
from tests.ro_crates import ValidROC
19+
from tests.shared import do_entity_test, SPARQL_PREFIXES
20+
21+
# set up logging
22+
logger = logging.getLogger(__name__)
23+
24+
25+
# ----- MUST fails tests
26+
27+
28+
def test_createaction_does_not_have_agent():
29+
"""
30+
Test a Five Safes Crate where CreateAction does not have the property agent.
31+
(We remove the property agent from the CreateAction entity)
32+
"""
33+
sparql = (
34+
SPARQL_PREFIXES
35+
+ """
36+
DELETE {
37+
?action schema:agent ?agent .
38+
}
39+
WHERE {
40+
?action schema:agent ?agent ;
41+
a schema:CreateAction .
42+
?agent a schema:Person .
43+
}
44+
"""
45+
)
46+
47+
do_entity_test(
48+
rocrate_path=ValidROC().five_safes_crate_request,
49+
requirement_severity=Severity.REQUIRED,
50+
expected_validation_result=False,
51+
expected_triggered_requirements=["CreateAction"],
52+
expected_triggered_issues=[
53+
"CreateAction MUST have at least one schema:agent that is an IRI."
54+
],
55+
profile_identifier="five-safes-crate",
56+
rocrate_entity_mod_sparql=sparql,
57+
)
58+
59+
60+
def test_createaction_agent_is_not_person():
61+
"""
62+
Test a Five Safes Crate where CreateAction has an agent that is not of type schema:Person.
63+
(We replace the CreateAction's agent with an entity that has no type).
64+
"""
65+
sparql = (
66+
SPARQL_PREFIXES
67+
+ """
68+
DELETE {
69+
?action schema:agent ?agent .
70+
}
71+
INSERT {
72+
?action schema:agent <#not-a-person> .
73+
}
74+
WHERE {
75+
?action schema:agent ?agent ;
76+
a schema:CreateAction .
77+
?agent a schema:Person .
78+
}
79+
"""
80+
)
81+
82+
do_entity_test(
83+
rocrate_path=ValidROC().five_safes_crate_request,
84+
requirement_severity=Severity.REQUIRED,
85+
expected_validation_result=False,
86+
expected_triggered_requirements=["CreateAction"],
87+
expected_triggered_issues=[
88+
"Each CreateAction agent MUST be typed as schema:Person and be an IRI."
89+
],
90+
profile_identifier="five-safes-crate",
91+
rocrate_entity_mod_sparql=sparql,
92+
)
93+
94+
95+
def test_agent_affiliation_not_organization():
96+
"""
97+
Test a Five Safes Crate where the agent of CreateAction has an affiliation
98+
that is not of type schema:Organization.
99+
(We rereplace the agent's affiliation with an entity that has no type)
100+
"""
101+
sparql = (
102+
SPARQL_PREFIXES
103+
+ """
104+
DELETE {
105+
?agent schema:affiliation ?aff .
106+
}
107+
INSERT {
108+
?agent schema:affiliation <#not-an-organization> .
109+
}
110+
WHERE {
111+
?agent schema:affiliation ?aff ;
112+
a schema:Person .
113+
?aff a schema:Organization .
114+
?action a schema:CreateAction ;
115+
schema:agent ?agent .
116+
}
117+
"""
118+
)
119+
120+
do_entity_test(
121+
rocrate_path=ValidROC().five_safes_crate_request,
122+
requirement_severity=Severity.REQUIRED,
123+
expected_validation_result=False,
124+
expected_triggered_requirements=["CreateAction"],
125+
expected_triggered_issues=[
126+
"The affiliation of a CreateAction's agent MUST be a schema:Organization and be an IRI."
127+
],
128+
profile_identifier="five-safes-crate",
129+
rocrate_entity_mod_sparql=sparql,
130+
)
131+
132+
133+
# ----- SHOULD warning tests
134+
135+
136+
def test_5src_agent_does_not_have_affiliation():
137+
"""
138+
Test a Five Safes Crate where the agent of CreteAction does not have an affiliatin.
139+
(We remove the triplet ?agent schema:affiliation ?org from the RO-Crate graph)
140+
"""
141+
sparql = (
142+
SPARQL_PREFIXES
143+
+ """
144+
DELETE {
145+
?agent schema:affiliation ?org .
146+
}
147+
WHERE {
148+
?agent schema:affiliation ?org ;
149+
a schema:Person .
150+
?action a schema:CreateAction ;
151+
schema:agent ?agent .
152+
}
153+
"""
154+
)
155+
156+
do_entity_test(
157+
rocrate_path=ValidROC().five_safes_crate_request,
158+
requirement_severity=Severity.RECOMMENDED,
159+
expected_validation_result=False,
160+
expected_triggered_requirements=["Agent of CreateAction"],
161+
expected_triggered_issues=[
162+
"The agent of a CreateAction entity SHOULD have an affiliation"
163+
],
164+
profile_identifier="five-safes-crate",
165+
rocrate_entity_mod_sparql=sparql,
166+
)

tests/integration/profiles/five-safes-crate/test_5src_funding.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

tests/integration/profiles/five-safes-crate/test_5src_root_data_entity_metadata.py

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)