Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions rocrate_validator/profiles/five-safes-crate/should/10_outputs.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (c) 2025 eScience Lab, The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

@prefix ro: <./> .
@prefix ro-crate: <https://github.com/crs4/rocrate-validator/profiles/ro-crate/> .
@prefix five-safes-crate: <https://github.com/eScienceLab/rocrate-validator/profiles/five-safes-crate/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix validator: <https://github.com/crs4/rocrate-validator/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .



five-safes-crate:CreateActionHasResultIfActionCompleted
a sh:NodeShape ;
sh:name "CreateAction" ;
sh:description "`CreateAction` with CompletedActionStatus SHOULD have the `schema:result` property." ;

sh:target [
a sh:SPARQLTarget ;
sh:name "Result" ;
sh:description "`CreateAction` with CompletedActionStatus SHOULD have the `schema:result` property." ;
sh:prefixes ro-crate:sparqlPrefixes ;
sh:select """
SELECT ?this WHERE {
?this a schema:CreateAction ;
schema:actionStatus "http://schema.org/CompletedActionStatus" .
}
"""
] ;


sh:property [
a sh:PropertyShape ;
sh:name "Result" ;
sh:path schema:result ;
sh:minCount 1 ;
sh:severity sh:Warning ;
sh:message "`CreateAction` with CompletedActionStatus SHOULD have the `schema:result` property." ;
] .


five-safes-crate:CreateActionResultOutputsHaveAllowedTypes
a sh:NodeShape ;
sh:name "Output" ;
sh:description "Result SHOULD have a `@type` among an allowed set of values." ;
sh:target [
a sh:SPARQLTarget ;
sh:select """
PREFIX schema: <http://schema.org/>
SELECT ?this
WHERE {
?createAction a schema:CreateAction .
?createAction schema:result ?this .
}
""" ;
] ;
sh:message "Result SHOULD have a `@type` among an allowed set of values." ;
sh:severity sh:Warning ;
sh:or (
[
sh:class schema:MediaObject;
]
[
sh:class schema:Dataset;
]
[
sh:class schema:Collection;
]
[
sh:class schema:DigitalDocument;
]
[
sh:class schema:PropertyValue;
]
) .

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright (c) 2024-2025 CRS4
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging

from rocrate_validator.models import Severity
from tests.ro_crates import ValidROC
from tests.shared import do_entity_test, SPARQL_PREFIXES

# set up logging
logger = logging.getLogger(__name__)


# ----- SHOULD fails tests


def test_completed_createaction_does_not_have_result():
"""
Test a Five Safes Crate where `CreateAction` has `CompletedActionStatus` but
does not have the property `result`.
(We remove `result` from `CreateAction` if this has `CompletedActionStatus`)
"""
sparql = (
SPARQL_PREFIXES
+ """
DELETE {
?action schema:result ?o .
}
WHERE {
?action a schema:CreateAction ;
schema:actionStatus "http://schema.org/CompletedActionStatus" ;
schema:result ?o
}
"""
)

do_entity_test(
rocrate_path=ValidROC().five_safes_crate_result,
requirement_severity=Severity.RECOMMENDED,
expected_validation_result=False,
expected_triggered_requirements=["CreateAction"],
expected_triggered_issues=[
"`CreateAction` with CompletedActionStatus SHOULD have the `schema:result` property."
],
profile_identifier="five-safes-crate",
rocrate_entity_mod_sparql=sparql,
)


def test_result_output_does_not_have_allowed_type():
"""
Test a Five Safes Crate where the result output does not have a type that
is among those allowed.
(We remove the output entity and replace it with one that is of a wrong type)"""
sparql = (
SPARQL_PREFIXES
+ """
DELETE {
?result a ?oldType .
}
INSERT {
?result a schema:Person .
}
WHERE {
?action a schema:CreateAction ;
schema:result ?result .
?result a ?oldType .
}
"""
)

do_entity_test(
rocrate_path=ValidROC().five_safes_crate_result,
requirement_severity=Severity.RECOMMENDED,
expected_validation_result=False,
expected_triggered_requirements=["Output"],
expected_triggered_issues=[
"Result SHOULD have a `@type` among an allowed set of values."
],
profile_identifier="five-safes-crate",
rocrate_entity_mod_sparql=sparql,
)