Skip to content

Commit 8cc39c9

Browse files
committed
Added tests for rules implemented so far.
1 parent 50b67ef commit 8cc39c9

1 file changed

Lines changed: 261 additions & 0 deletions

File tree

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
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
20+
21+
# set up logging
22+
logger = logging.getLogger(__name__)
23+
24+
25+
# ----- MUST fails tests
26+
27+
28+
def test_5src_workflow_object_with_no_name():
29+
sparql = """
30+
PREFIX schema: <http://schema.org/>
31+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
32+
33+
DELETE {
34+
?this schema:name ?name .
35+
}
36+
WHERE {
37+
?this rdf:type schema:CreateAction ;
38+
schema:name ?name .
39+
<./> schema:mentions ?this .
40+
}
41+
"""
42+
43+
do_entity_test(
44+
rocrate_path=ValidROC().five_safes_crate_request,
45+
requirement_severity=Severity.REQUIRED,
46+
expected_validation_result=False,
47+
expected_triggered_requirements=None,
48+
expected_triggered_issues=None,
49+
profile_identifier="five-safes-crate",
50+
rocrate_entity_mod_sparql=sparql,
51+
)
52+
53+
54+
def test_5src_workflow_object_with_name_not_string():
55+
sparql = """
56+
PREFIX schema: <http://schema.org/>
57+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
58+
59+
DELETE {
60+
?this schema:name ?name .
61+
}
62+
INSERT {
63+
?this schema:name 123 .
64+
}
65+
WHERE {
66+
?this rdf:type schema:CreateAction ;
67+
schema:name ?name .
68+
<./> schema:mentions ?this .
69+
}
70+
"""
71+
72+
do_entity_test(
73+
rocrate_path=ValidROC().five_safes_crate_request,
74+
requirement_severity=Severity.REQUIRED,
75+
expected_validation_result=False,
76+
expected_triggered_requirements=None,
77+
expected_triggered_issues=None,
78+
profile_identifier="five-safes-crate",
79+
rocrate_entity_mod_sparql=sparql,
80+
)
81+
82+
83+
def test_5src_workflow_object_with_not_long_enough_name():
84+
sparql = """
85+
PREFIX schema: <http://schema.org/>
86+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
87+
88+
DELETE {
89+
?this schema:name ?name .
90+
}
91+
INSERT {
92+
?this schema:name "Too short" .
93+
}
94+
WHERE {
95+
?this rdf:type schema:CreateAction ;
96+
schema:name ?name .
97+
<./> schema:mentions ?this .
98+
}
99+
"""
100+
101+
do_entity_test(
102+
rocrate_path=ValidROC().five_safes_crate_request,
103+
requirement_severity=Severity.REQUIRED,
104+
expected_validation_result=False,
105+
expected_triggered_requirements=None,
106+
expected_triggered_issues=None,
107+
profile_identifier="five-safes-crate",
108+
rocrate_entity_mod_sparql=sparql,
109+
)
110+
111+
112+
def test_5src_workflow_object_has_no_start_time_if_begun():
113+
sparql = """
114+
PREFIX schema: <http://schema.org/>
115+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
116+
117+
DELETE {
118+
?s schema:startTime ?o .
119+
}
120+
WHERE {
121+
?s rdf:type schema:CreateAction;
122+
schema:actionStatus ?status .
123+
FILTER(?status IN (
124+
"http://schema.org/CompletedActionStatus",
125+
"http://schema.org/FailedActionStatus",
126+
"http://schema.org/ActiveActionStatus"
127+
))
128+
}
129+
"""
130+
131+
do_entity_test(
132+
rocrate_path=ValidROC().five_safes_crate_request,
133+
requirement_severity=Severity.REQUIRED,
134+
expected_validation_result=False,
135+
expected_triggered_requirements=None,
136+
expected_triggered_issues=None,
137+
profile_identifier="five-safes-crate",
138+
rocrate_entity_mod_sparql=sparql,
139+
)
140+
141+
142+
def test_5src_workflow_object_has_no_properly_formatted_start_time_if_begun():
143+
sparql = """
144+
PREFIX schema: <http://schema.org/>
145+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
146+
147+
DELETE {
148+
?s schema:startTime ?o .
149+
}
150+
INSERT {
151+
?s schema:startTime "1st Dec '25 @ 10:00:00" .
152+
}
153+
WHERE {
154+
?s rdf:type schema:CreateAction ;
155+
schema:actionStatus ?status .
156+
FILTER(?status IN (
157+
"http://schema.org/CompletedActionStatus",
158+
"http://schema.org/FailedActionStatus",
159+
"http://schema.org/ActiveActionStatus"
160+
))
161+
}
162+
"""
163+
164+
do_entity_test(
165+
rocrate_path=ValidROC().five_safes_crate_request,
166+
requirement_severity=Severity.REQUIRED,
167+
expected_validation_result=False,
168+
expected_triggered_requirements=None,
169+
expected_triggered_issues=None,
170+
profile_identifier="five-safes-crate",
171+
rocrate_entity_mod_sparql=sparql,
172+
)
173+
174+
175+
def test_5src_workflow_object_has_no_end_time_if_ended():
176+
sparql = """
177+
PREFIX schema: <http://schema.org/>
178+
PREFIX shp: <https://w3id.org/shp#>
179+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
180+
181+
DELETE {
182+
?s schema:endTime ?o .
183+
}
184+
WHERE {
185+
?s rdf:type schema:CreateAction ;
186+
schema:actionStatus ?status .
187+
FILTER(?status IN (
188+
"http://schema.org/CompletedActionStatus",
189+
"http://schema.org/FailedActionStatus"
190+
))
191+
}
192+
"""
193+
194+
do_entity_test(
195+
rocrate_path=ValidROC().five_safes_crate_request,
196+
requirement_severity=Severity.REQUIRED,
197+
expected_validation_result=False,
198+
expected_triggered_requirements=None,
199+
expected_triggered_issues=None,
200+
profile_identifier="five-safes-crate",
201+
rocrate_entity_mod_sparql=sparql,
202+
)
203+
204+
205+
def test_5src_workflow_object_has_no_properly_formatted_end_time_if_ended():
206+
sparql = """
207+
PREFIX schema: <http://schema.org/>
208+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
209+
210+
DELETE {
211+
?s schema:endTime ?o .
212+
}
213+
INSERT {
214+
?s schema:endTime "1st Dec '25 @ 10:00:00" .
215+
}
216+
WHERE {
217+
?s rdf:type schema:CreateAction ;
218+
schema:actionStatus ?status .
219+
FILTER(?status IN (
220+
"http://schema.org/CompletedActionStatus",
221+
"http://schema.org/FailedActionStatus"
222+
))
223+
}
224+
"""
225+
226+
do_entity_test(
227+
rocrate_path=ValidROC().five_safes_crate_request,
228+
requirement_severity=Severity.REQUIRED,
229+
expected_validation_result=False,
230+
expected_triggered_requirements=None,
231+
expected_triggered_issues=None,
232+
profile_identifier="five-safes-crate",
233+
rocrate_entity_mod_sparql=sparql,
234+
)
235+
236+
237+
# ----- SHOULD fails tests
238+
239+
240+
def test_5src_workflow_object_not_mentioned_by_root_data_entity():
241+
sparql = """
242+
PREFIX schema: <http://schema.org/>
243+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
244+
245+
DELETE {
246+
<./> schema:mentions ?o .
247+
}
248+
WHERE {
249+
?o rdf:type schema:CreateAction .
250+
}
251+
"""
252+
253+
do_entity_test(
254+
rocrate_path=ValidROC().five_safes_crate_request,
255+
requirement_severity=Severity.RECOMMENDED,
256+
expected_validation_result=False,
257+
expected_triggered_requirements=None,
258+
expected_triggered_issues=None,
259+
profile_identifier="five-safes-crate",
260+
rocrate_entity_mod_sparql=sparql,
261+
)

0 commit comments

Comments
 (0)