Skip to content

Commit 2d2d882

Browse files
EttoreMdouglowe
authored andcommitted
Added tests for ruleset 1
1 parent ac46c75 commit 2d2d882

8 files changed

Lines changed: 402 additions & 80 deletions

File tree

rocrate_validator/profiles/five-safes-crate/may/1_responsible_project.ttl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ five-safes-crate:ResponsibleProject
4343
sh:path schema:funding;
4444
sh:minCount 1 ;
4545
sh:severity sh:Info ;
46-
sh:message """The Responsible Project does not have the property 'funding'.""" ;
46+
sh:message """The Responsible Project does not have the property `funding`.""" ;
4747
] ;
4848

4949
sh:property [
@@ -52,5 +52,5 @@ five-safes-crate:ResponsibleProject
5252
sh:path schema:member;
5353
sh:minCount 1 ;
5454
sh:severity sh:Info ;
55-
sh:message """The Responsible Project does not have the property 'member'.""" ;
55+
sh:message """The Responsible Project does not have the property `member`.""" ;
5656
] .

rocrate_validator/profiles/five-safes-crate/must/1.requesting_agent.ttl renamed to rocrate_validator/profiles/five-safes-crate/must/1_requesting_agent.ttl

File renamed without changes.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
five-safes-crate:RootDataEntityRequiredProperties
2626
a sh:NodeShape ;
27-
sh:name "Root Data Entity" ;
27+
sh:name "RootDataEntity" ;
2828
sh:targetClass ro-crate:RootDataEntity ;
2929

3030
sh:property [
@@ -42,5 +42,5 @@ five-safes-crate:RootDataEntityRequiredProperties
4242
sh:path schema:sourceOrganization ;
4343
sh:class schema:Project ;
4444
sh:severity sh:Violation ;
45-
sh:message """The `sourceOrganization` property of the Root Data Entity MUST point to a Project entity.""" ;
45+
sh:message """The `sourceOrganization` property of the RootDataEntity MUST point to a Project entity.""" ;
4646
] .
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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_5src_agent_memberOf_not_project():
29+
"""
30+
Test a Five Safes Crate where an agent's `memberOf` does NOT reference a schema:Project.
31+
(We replace the referenced Project with a plain literal.)
32+
"""
33+
sparql = (
34+
SPARQL_PREFIXES
35+
+ """
36+
DELETE {
37+
?agent schema:memberOf ?org .
38+
}
39+
INSERT {
40+
?agent schema:memberOf "Not a project (literal replacement)"
41+
}
42+
WHERE {
43+
?action a schema:CreateAction ;
44+
schema:agent ?agent .
45+
?agent schema:memberOf ?org .
46+
?org a schema:Project .
47+
}
48+
"""
49+
)
50+
51+
do_entity_test(
52+
rocrate_path=ValidROC().five_safes_crate_request,
53+
requirement_severity=Severity.REQUIRED,
54+
expected_validation_result=False,
55+
expected_triggered_requirements=["Requesting Agent"],
56+
expected_triggered_issues=[
57+
"The 'memberOf' property of an agent MUST be of type Project."
58+
],
59+
profile_identifier="five-safes-crate",
60+
rocrate_entity_mod_sparql=sparql,
61+
)
62+
63+
64+
def test_5src_agent_memberOf_project_not_in_root():
65+
"""
66+
Test a Five Safes Crate where NONE of the Projects referenced by Agent->memberOf are included
67+
in the set of Projects referenced by RootDataEntity->sourceOrganization.
68+
(We replace an agent's memberOf with a new Project that the root does not reference.)
69+
"""
70+
sparql = (
71+
SPARQL_PREFIXES
72+
+ """
73+
DELETE {
74+
?agent schema:memberOf ?org .
75+
}
76+
INSERT {
77+
# assign the agent to a new Project that is not referenced by the Root Data Entity
78+
?agent schema:memberOf <./missing-project> .
79+
<./missing-project> a schema:Project .
80+
}
81+
WHERE {
82+
# locate a CreateAction -> agent -> memberOf that currently points to a Project
83+
?action a schema:CreateAction ;
84+
schema:agent ?agent .
85+
86+
?agent schema:memberOf ?org .
87+
?org a schema:Project .
88+
}
89+
"""
90+
)
91+
92+
do_entity_test(
93+
rocrate_path=ValidROC().five_safes_crate_request,
94+
requirement_severity=Severity.REQUIRED,
95+
expected_validation_result=False,
96+
expected_triggered_requirements=["Agent Project Intersection"],
97+
expected_triggered_issues=[
98+
"""At least one Project referenced by Agent -> memberOf MUST be included in the set of Projects referenced by RootDataEntity -> sourceOrganization."""
99+
],
100+
profile_identifier="five-safes-crate",
101+
rocrate_entity_mod_sparql=sparql,
102+
)
103+
104+
105+
# ----- SHOULD warns tests
106+
def test_5src_agent_memberOf_missing_warning():
107+
"""
108+
Test a Five Safes Crate where the Requesting Agent does NOT have the 'memberOf' property.
109+
This should trigger the SHACL warning: the Requesting Agent SHOULD have a `memberOf` property.
110+
"""
111+
sparql = (
112+
SPARQL_PREFIXES
113+
+ """
114+
DELETE {
115+
?agent schema:memberOf ?org .
116+
}
117+
WHERE {
118+
?action a schema:CreateAction ;
119+
schema:agent ?agent .
120+
?agent schema:memberOf ?org .
121+
}
122+
"""
123+
)
124+
125+
do_entity_test(
126+
rocrate_path=ValidROC().five_safes_crate_request,
127+
requirement_severity=Severity.RECOMMENDED,
128+
expected_validation_result=False, # or True if warnings are not treated as failures
129+
expected_triggered_requirements=["Requesting Agent"],
130+
expected_triggered_issues=[
131+
"The Requesting Agent SHOULD have a `memberOf` property."
132+
],
133+
profile_identifier="five-safes-crate",
134+
rocrate_entity_mod_sparql=sparql,
135+
)
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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_5src_responsible_project_funding_not_grant():
29+
"""
30+
Test a Five Safes Crate where a Responsible Project's `funding` property
31+
is NOT of type schema:Grant.
32+
(We replace the funding reference with a literal.)
33+
"""
34+
sparql = (
35+
SPARQL_PREFIXES
36+
+ """
37+
DELETE {
38+
?project schema:funding ?grant .
39+
}
40+
INSERT {
41+
?project schema:funding "Not a grant (literal replacement)" .
42+
}
43+
WHERE {
44+
?action a schema:CreateAction ;
45+
schema:agent ?agent .
46+
?agent schema:memberOf ?project .
47+
?project schema:funding ?grant .
48+
?grant a schema:Grant .
49+
}
50+
"""
51+
)
52+
53+
do_entity_test(
54+
rocrate_path=ValidROC().five_safes_crate_request,
55+
requirement_severity=Severity.REQUIRED,
56+
expected_validation_result=False,
57+
expected_triggered_requirements=["Responsible Project"],
58+
expected_triggered_issues=[
59+
"The property 'funding' of the Responsible Project MUST be of type schema:Grant."
60+
],
61+
profile_identifier="five-safes-crate",
62+
rocrate_entity_mod_sparql=sparql,
63+
)
64+
65+
66+
def test_5src_responsible_project_member_not_organization():
67+
"""
68+
Test a Five Safes Crate where a Responsible Project's `member` property
69+
is NOT of type schema:Organization.
70+
(We replace the member reference with a literal.)
71+
"""
72+
sparql = (
73+
SPARQL_PREFIXES
74+
+ """
75+
DELETE {
76+
?project schema:member ?org .
77+
}
78+
INSERT {
79+
?project schema:member "Not an organization (literal replacement)" .
80+
}
81+
WHERE {
82+
?action a schema:CreateAction ;
83+
schema:agent ?agent .
84+
?agent schema:memberOf ?project .
85+
?project schema:member ?org .
86+
?org a schema:Organization .
87+
}
88+
"""
89+
)
90+
91+
do_entity_test(
92+
rocrate_path=ValidROC().five_safes_crate_request,
93+
requirement_severity=Severity.REQUIRED,
94+
expected_validation_result=False,
95+
expected_triggered_requirements=["Responsible Project"],
96+
expected_triggered_issues=[
97+
"The property 'member' of the Responsible Project MUST be of type schema:Organization."
98+
],
99+
profile_identifier="five-safes-crate",
100+
rocrate_entity_mod_sparql=sparql,
101+
)
102+
103+
104+
# ---- MAY warns tests
105+
106+
107+
def test_5src_responsible_project_missing_funding_property():
108+
"""
109+
Test a Five Safes Crate where a Responsible Project does NOT have the `funding` property.
110+
This should trigger the SHACL info: 'The Responsible Project does not have the property `funding`.'
111+
"""
112+
sparql = (
113+
SPARQL_PREFIXES
114+
+ """
115+
DELETE {
116+
?project schema:funding ?f .
117+
}
118+
WHERE {
119+
?action a schema:CreateAction ;
120+
schema:agent ?agent .
121+
?agent schema:memberOf ?project .
122+
?project schema:funding ?f .
123+
}
124+
"""
125+
)
126+
127+
do_entity_test(
128+
rocrate_path=ValidROC().five_safes_crate_request,
129+
requirement_severity=Severity.OPTIONAL,
130+
expected_validation_result=False, # or True if Info is not treated as failure
131+
expected_triggered_requirements=["Responsible Project"],
132+
expected_triggered_issues=[
133+
"The Responsible Project does not have the property `funding`."
134+
],
135+
profile_identifier="five-safes-crate",
136+
rocrate_entity_mod_sparql=sparql,
137+
)
138+
139+
140+
def test_5src_responsible_project_missing_member_property():
141+
"""
142+
Test a Five Safes Crate where a Responsible Project does NOT have the `member` property.
143+
This should trigger the SHACL info: 'The Responsible Project does not have the property `member`.'
144+
"""
145+
sparql = (
146+
SPARQL_PREFIXES
147+
+ """
148+
DELETE {
149+
?project schema:member ?m .
150+
}
151+
WHERE {
152+
?action a schema:CreateAction ;
153+
schema:agent ?agent .
154+
?agent schema:memberOf ?project .
155+
?project schema:member ?m .
156+
}
157+
"""
158+
)
159+
160+
do_entity_test(
161+
rocrate_path=ValidROC().five_safes_crate_request,
162+
requirement_severity=Severity.OPTIONAL,
163+
expected_validation_result=False, # or True if Info is treated as failure
164+
expected_triggered_requirements=["Responsible Project"],
165+
expected_triggered_issues=[
166+
"The Responsible Project does not have the property `member`."
167+
],
168+
profile_identifier="five-safes-crate",
169+
rocrate_entity_mod_sparql=sparql,
170+
)

0 commit comments

Comments
 (0)