1313# limitations under the License.
1414
1515import logging
16+ import rdflib
1617
1718from rocrate_validator .models import Severity
18- from tests .ro_crates import Invalid5sROC
19+ from tests .ro_crates import ValidROC
1920from tests .shared import do_entity_test
2021
2122# set up logging
@@ -26,8 +27,21 @@ def test_5src_root_data_entity_no_source_organization():
2627 """\
2728 Test a Five Safes Crate where the Root Data Entity it does not reference a sourceOrganization.
2829 """
30+ def remove_source_org (graph ):
31+ SCHEMA = rdflib .Namespace ("http://schema.org/" )
32+ target_subject = rdflib .URIRef ("./" )
33+ target_predicate = SCHEMA .sourceOrganization
34+ target_object = None
35+
36+ for s , p , o in graph .triples ((target_subject , target_predicate , target_object )):
37+ print (f"Removing: { s } , { p } , { o } " )
38+
39+ graph .remove ((target_subject , target_predicate , target_object ))
40+
41+ return graph
42+
2943 do_entity_test (
30- rocrate_path = Invalid5sROC ().root_data_entity_no_source_organization ,
44+ rocrate_path = ValidROC ().five_safes_crate_result ,
3145 requirement_severity = Severity .REQUIRED ,
3246 expected_validation_result = False ,
3347 expected_triggered_requirements = ["Five Safes Crate Root Data Entity REQUIRED properties" ],
@@ -36,15 +50,31 @@ def test_5src_root_data_entity_no_source_organization():
3650 SHOULD link to a Contextual Entity in the RO-Crate Metadata File with a name."""
3751 ],
3852 profile_identifier = "five-safes-crate" ,
53+ rocrate_entity_mod_function = remove_source_org ,
3954 )
4055
4156
4257def test_5src_root_data_entity_source_organization_not_entity ():
4358 """\
4459 Test a Five Safes Crate where the Root Data Entity it does not reference a sourceOrganization.
4560 """
61+ def replace_source_org (graph ):
62+ SCHEMA = rdflib .Namespace ("http://schema.org/" )
63+ target_subject = rdflib .URIRef ("./" )
64+ target_predicate = SCHEMA .sourceOrganization
65+ original_object = None
66+ new_object = rdflib .Literal ('Investigation of cancer (TRE72 project 81)' )
67+
68+ for s , p , o in graph .triples ((target_subject , target_predicate , original_object )):
69+ print (f"Replacing: { s } , { p } , { o } " )
70+
71+ graph .remove ((target_subject , target_predicate , original_object ))
72+ graph .add ((target_subject , target_predicate , new_object ))
73+
74+ return graph
75+
4676 do_entity_test (
47- rocrate_path = Invalid5sROC ().root_data_entity_source_organization_not_entity ,
77+ rocrate_path = ValidROC ().five_safes_crate_result ,
4878 requirement_severity = Severity .REQUIRED ,
4979 expected_validation_result = False ,
5080 expected_triggered_requirements = ["Five Safes Crate Root Data Entity REQUIRED properties" ],
@@ -53,4 +83,5 @@ def test_5src_root_data_entity_source_organization_not_entity():
5383 SHOULD link to a Contextual Entity in the RO-Crate Metadata File with a name."""
5484 ],
5585 profile_identifier = "five-safes-crate" ,
86+ rocrate_entity_mod_function = replace_source_org ,
5687 )
0 commit comments