diff --git a/tests/test_oap_update_iris.py b/tests/test_oap_update_iris.py index d10b3df..5c301e8 100644 --- a/tests/test_oap_update_iris.py +++ b/tests/test_oap_update_iris.py @@ -8,6 +8,7 @@ from dsp_permissions_scripts.models.group import PROJECT_ADMIN from dsp_permissions_scripts.models.scope import PermissionScope from dsp_permissions_scripts.oap import update_iris +from dsp_permissions_scripts.oap.oap_model import ValueOap from dsp_permissions_scripts.oap.update_iris import IRIUpdater from dsp_permissions_scripts.oap.update_iris import ResourceIRIUpdater from dsp_permissions_scripts.oap.update_iris import ValueIRIUpdater @@ -15,7 +16,7 @@ @pytest.fixture() -def res_dict() -> dict[str, Any]: +def res_dict_2_props() -> dict[str, Any]: return { "knora-api:lastModificationDate": {"@value": "2024-09-10T18:07:10.753289758Z", "@type": "xsd:dateTimeStamp"}, "knora-api:hasPermissions": "CR knora-admin:ProjectAdmin|V knora-admin:UnknownUser", @@ -26,6 +27,38 @@ def res_dict() -> dict[str, Any]: "@type": "knora-api:TextValue", "@id": "http://rdfh.ch/4123/QDdiwk_3Rk--N2dzsSPOdw/values/FWSVNZFJRai8-4OQu5pU8Q", }, + "testonto:hasOtherText": { + "knora-api:hasPermissions": "CR knora-admin:ProjectAdmin|V knora-admin:UnknownUser", + "@type": "knora-api:TextValue", + "@id": "http://rdfh.ch/4123/QDdiwk_3Rk--N2dzsSPOdw/values/4bf-72HPTXSUdTxY8udGew", + }, + "@context": { + "knora-api": "http://api.knora.org/ontology/knora-api/v2#", + "testonto": "http://0.0.0.0:3333/ontology/4123/testonto/v2#", + "xsd": "http://www.w3.org/2001/XMLSchema#", + }, + } + + +@pytest.fixture() +def res_dict_2_vals() -> dict[str, Any]: + return { + "knora-api:lastModificationDate": {"@value": "2024-09-10T18:07:10.753289758Z", "@type": "xsd:dateTimeStamp"}, + "knora-api:hasPermissions": "CR knora-admin:ProjectAdmin|V knora-admin:UnknownUser", + "@type": "testonto:CompoundThing", + "@id": "http://rdfh.ch/4123/QDdiwk_3Rk--N2dzsSPOdw", + "testonto:hasSimpleText": [ + { + "knora-api:hasPermissions": "CR knora-admin:ProjectAdmin|V knora-admin:UnknownUser", + "@type": "knora-api:TextValue", + "@id": "http://rdfh.ch/4123/QDdiwk_3Rk--N2dzsSPOdw/values/4bf-72HPTXSUdTxY8udGew", + }, + { + "knora-api:hasPermissions": "CR knora-admin:ProjectAdmin|V knora-admin:UnknownUser", + "@type": "knora-api:TextValue", + "@id": "http://rdfh.ch/4123/QDdiwk_3Rk--N2dzsSPOdw/values/FWSVNZFJRai8-4OQu5pU8Q", + }, + ], "@context": { "knora-api": "http://api.knora.org/ontology/knora-api/v2#", "testonto": "http://0.0.0.0:3333/ontology/4123/testonto/v2#", @@ -61,8 +94,8 @@ def test_factory_with_invalid_iri() -> None: IRIUpdater.from_string(inv, dsp_client) -def test_ResourceIRIUpdater(res_dict: dict[str, Any]) -> None: - dsp_client = Mock(spec_set=DspClient, get=Mock(return_value=res_dict)) +def test_ResourceIRIUpdater(res_dict_2_props: dict[str, Any]) -> None: + dsp_client = Mock(spec_set=DspClient, get=Mock(return_value=res_dict_2_props)) update_iris.update_permissions_for_resource = Mock() # type: ignore[attr-defined] new_scope = PermissionScope.create(D=[PROJECT_ADMIN]) res_iri = "http://rdfh.ch/4123/2ETqDXKeRrS5JSd6TxFO5g" @@ -70,9 +103,35 @@ def test_ResourceIRIUpdater(res_dict: dict[str, Any]) -> None: dsp_client.get.assert_called_once_with("/v2/resources/http%3A%2F%2Frdfh.ch%2F4123%2F2ETqDXKeRrS5JSd6TxFO5g") update_iris.update_permissions_for_resource.assert_called_once_with( # type: ignore[attr-defined] resource_iri=res_iri, - lmd=res_dict["knora-api:lastModificationDate"], - resource_type=res_dict["@type"], - context=res_dict["@context"] | {"knora-admin": KNORA_ADMIN_ONTO_NAMESPACE}, + lmd=res_dict_2_props["knora-api:lastModificationDate"], + resource_type=res_dict_2_props["@type"], + context=res_dict_2_props["@context"] | {"knora-admin": KNORA_ADMIN_ONTO_NAMESPACE}, scope=new_scope, dsp_client=dsp_client, ) + + +def test_ValueIRIUpdater_2_props(res_dict_2_props: dict[str, Any]) -> None: + dsp_client = Mock(spec_set=DspClient, get=Mock(return_value=res_dict_2_props)) + update_iris.update_permissions_for_value = Mock() # type: ignore[attr-defined] + val_oap = ValueOap( + scope=PermissionScope.create(D=[PROJECT_ADMIN]), + property="testonto:hasOtherText", + value_type="knora-api:TextValue", + value_iri="http://rdfh.ch/4123/QDdiwk_3Rk--N2dzsSPOdw/values/4bf-72HPTXSUdTxY8udGew", + resource_iri="http://rdfh.ch/4123/QDdiwk_3Rk--N2dzsSPOdw", + ) + IRIUpdater.from_string(val_oap.value_iri, dsp_client).update_iri(val_oap.scope) + dsp_client.get.assert_called_once_with("/v2/resources/http%3A%2F%2Frdfh.ch%2F4123%2FQDdiwk_3Rk--N2dzsSPOdw") + update_iris.update_permissions_for_value.assert_called_once_with( # type: ignore[attr-defined] + resource_iri="http://rdfh.ch/4123/QDdiwk_3Rk--N2dzsSPOdw", + value=val_oap, + resource_type=res_dict_2_props["@type"], + context=res_dict_2_props["@context"] | {"knora-admin": KNORA_ADMIN_ONTO_NAMESPACE}, + dsp_client=dsp_client, + ) + + +# test with 2 properties +# test with 2 values in the same property +# test IRI that is not contained in the resource