Skip to content

Commit

Permalink
test_ValueIRIUpdater_2_props
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Sep 11, 2024
1 parent ea17ff1 commit e0fcaa0
Showing 1 changed file with 65 additions and 6 deletions.
71 changes: 65 additions & 6 deletions tests/test_oap_update_iris.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
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
from dsp_permissions_scripts.utils.dsp_client import DspClient


@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",
Expand All @@ -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#",
Expand Down Expand Up @@ -61,18 +94,44 @@ 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"
IRIUpdater.from_string(res_iri, dsp_client).update_iri(new_scope)
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

0 comments on commit e0fcaa0

Please sign in to comment.