Skip to content

Commit

Permalink
use custom graph in tests and check result
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Sep 23, 2024
1 parent 7dc4fd4 commit fa6b6b7
Show file tree
Hide file tree
Showing 3 changed files with 2,442 additions and 9 deletions.
32 changes: 23 additions & 9 deletions tests/test_shapes.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
"""Plugin tests."""

from contextlib import suppress
from pathlib import Path

import pytest
from cmem.cmempy.dp.proxy.graph import delete, get
from cmem.cmempy.dp.proxy.update import post
from cmem.cmempy.dp.proxy.graph import delete, get, post
from cmem.cmempy.dp.proxy.update import post as post_update
from cmem.cmempy.workspace.projects.project import delete_project, make_new_project
from rdflib import Graph
from rdflib.compare import to_isomorphic

from cmem_plugin_shapes.plugin_shapes import ShapesPlugin
from tests.utils import TestExecutionContext, needs_cmem

from . import __path__

UUID = "5072e1e3e96c40389116a6833d9a3867"
PROJECT_NAME = f"shapes_plugin_test_{UUID}"
GRAPH_IRI = f"https://eccenca.com/shapes_plugin/{UUID}"
RESULT_IRI = f"https://eccenca.com/shapes_plugin/{UUID}/shapes/"
DATA_IRI = f"https://eccenca.com/shapes_plugin/{UUID}/data/"


@pytest.fixture()
Expand All @@ -24,29 +30,37 @@ def remove_import() -> None:
PREFIX owl: <http://www.w3.org/2002/07/owl#>
DELETE DATA {{
GRAPH <https://vocab.eccenca.com/shacl/> {{
<https://vocab.eccenca.com/shacl/> owl:imports <{GRAPH_IRI}> .
<https://vocab.eccenca.com/shacl/> owl:imports <{RESULT_IRI}> .
}}
}}
"""
post(query=query)
post_update(query=query)

with suppress(Exception):
delete_project(PROJECT_NAME)
make_new_project(PROJECT_NAME)

res = post(DATA_IRI, Path(__path__[0]) / "test_shapes_data.ttl", replace=False)
if res.status_code != 204: # noqa: PLR2004
raise ValueError(f"Response {res.status_code}: {res.url}")

request.addfinalizer(lambda: delete_project(PROJECT_NAME))
request.addfinalizer(lambda: remove_import)
request.addfinalizer(lambda: delete(GRAPH_IRI)) # noqa: PT021
request.addfinalizer(lambda: delete(DATA_IRI))
request.addfinalizer(lambda: delete(RESULT_IRI)) # noqa: PT021


@needs_cmem
def test_workflow_execution(_setup: pytest.FixtureRequest) -> None: # noqa: PT019
"""Test plugin execution"""
ShapesPlugin(
data_graph_iri="https://vocab.eccenca.com/shacl/",
shapes_graph_iri=GRAPH_IRI,
data_graph_iri=DATA_IRI,
shapes_graph_iri=RESULT_IRI,
overwrite=False,
import_shapes=True,
).execute(inputs=None, context=TestExecutionContext(project_id=PROJECT_NAME))

get(GRAPH_IRI, owl_imports_resolution=False)
result = Graph().parse(data=get(RESULT_IRI, owl_imports_resolution=False).text)
test = Graph().parse(Path(__path__[0]) / "test_shapes.ttl", format="turtle")

assert to_isomorphic(result) == to_isomorphic(test)
145 changes: 145 additions & 0 deletions tests/test_shapes.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
@prefix ns1: <https://vocab.eccenca.com/shui/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/> a ns1:ShapeCatalog ;
rdfs:label "Shapes for https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/data/" .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/2503aa63-32a0-56b1-9754-365f9fbe3c75> a sh:NodeShape ;
rdfs:label "5072e1e3e96c40389116a6833d9a3867_vocabProductCategory"@en ;
sh:name "5072e1e3e96c40389116a6833d9a3867_vocabProductCategory"@en ;
sh:property <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/0a797858-fe68-5b31-9128-bebc16a75629>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/73b69787-81ea-563e-8e09-9c84cad4cf2b>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/bee2a79a-5486-5f1f-ace2-cb3df6ed92c3>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/d0e9e696-d3f2-5966-a62f-d8358cbde741> ;
sh:targetClass <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabProductCategory> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/5614091f-4111-58b3-8e9d-328147d87c7d> a sh:NodeShape ;
rdfs:label "5072e1e3e96c40389116a6833d9a3867_vocabPrice"@en ;
sh:name "5072e1e3e96c40389116a6833d9a3867_vocabPrice"@en ;
sh:property <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/4e35b298-ea31-5e27-9573-989f12da6102>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/4ea28beb-9bfc-5dae-b640-1f990ff22853>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/73b69787-81ea-563e-8e09-9c84cad4cf2b>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/bee2a79a-5486-5f1f-ace2-cb3df6ed92c3>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/d0e9e696-d3f2-5966-a62f-d8358cbde741>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/dc394b44-356f-5e00-bf31-1b956e7ef295> ;
sh:targetClass <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabPrice> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/76fed008-e683-5ff1-8778-2e74539c1e67> a sh:NodeShape ;
rdfs:label "Entity (prov:)"@en ;
sh:name "Entity (prov:)"@en ;
sh:property <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/1170f50d-e0e6-5793-85c0-92314cb7c01d>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/73b69787-81ea-563e-8e09-9c84cad4cf2b>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/d0e9e696-d3f2-5966-a62f-d8358cbde741> ;
sh:targetClass prov:Entity .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/83aeb1bd-7e33-54e7-93b1-0878979e0695> a sh:NodeShape ;
rdfs:label "5072e1e3e96c40389116a6833d9a3867_vocabService"@en ;
sh:name "5072e1e3e96c40389116a6833d9a3867_vocabService"@en ;
sh:property <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/4da3a2af-1676-57cb-b886-987b327367c6>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/559162af-75c4-5a7d-abca-11c5e20f1d50>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/61fe4339-86be-54af-aa31-2e1de259c7b4>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/73b69787-81ea-563e-8e09-9c84cad4cf2b>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/7415de09-2560-510f-add9-80a0c36bc284>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/b21fa2e4-92a0-52df-a04b-2e5d5132bef9>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/bee2a79a-5486-5f1f-ace2-cb3df6ed92c3>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/d0e9e696-d3f2-5966-a62f-d8358cbde741>,
<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/d7999f52-f438-550e-910b-57aadd396f2d> ;
sh:targetClass <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabService> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/f3ee9328-d5d1-5260-9736-ef083efd9362> a sh:NodeShape ;
rdfs:label "Dataset (eccdi:)"@en ;
sh:name "Dataset (eccdi:)"@en ;
sh:property <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/73b69787-81ea-563e-8e09-9c84cad4cf2b> ;
sh:targetClass <https://vocab.eccenca.com/di/Dataset> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/0a797858-fe68-5b31-9128-bebc16a75629> a sh:PropertyShape ;
rdfs:label "← 5072e1e3e96c40389116a6833d9a3867_vocabhasCategory"@en ;
sh:name "← 5072e1e3e96c40389116a6833d9a3867_vocabhasCategory"@en ;
sh:nodeKind sh:IRI ;
sh:path <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabhasCategory> ;
ns1:inversePath true .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/1170f50d-e0e6-5793-85c0-92314cb7c01d> a sh:PropertyShape ;
rdfs:label "← was derived from (prov:)"@en ;
sh:name "← was derived from (prov:)"@en ;
sh:nodeKind sh:IRI ;
sh:path prov:wasDerivedFrom ;
ns1:inversePath true .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/4da3a2af-1676-57cb-b886-987b327367c6> a sh:PropertyShape ;
rdfs:label "5072e1e3e96c40389116a6833d9a3867_vocabeligibleFor"@en ;
sh:name "5072e1e3e96c40389116a6833d9a3867_vocabeligibleFor"@en ;
sh:nodeKind sh:IRI ;
sh:path <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabeligibleFor> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/4e35b298-ea31-5e27-9573-989f12da6102> a sh:PropertyShape ;
rdfs:label "5072e1e3e96c40389116a6833d9a3867_vocabcurrency"@en ;
sh:name "5072e1e3e96c40389116a6833d9a3867_vocabcurrency"@en ;
sh:nodeKind sh:Literal ;
sh:path <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabcurrency> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/4ea28beb-9bfc-5dae-b640-1f990ff22853> a sh:PropertyShape ;
rdfs:label "← 5072e1e3e96c40389116a6833d9a3867_vocabprice"@en ;
sh:name "← 5072e1e3e96c40389116a6833d9a3867_vocabprice"@en ;
sh:nodeKind sh:IRI ;
sh:path <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabprice> ;
ns1:inversePath true .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/559162af-75c4-5a7d-abca-11c5e20f1d50> a sh:PropertyShape ;
rdfs:label "5072e1e3e96c40389116a6833d9a3867_vocabhasCategory"@en ;
sh:name "5072e1e3e96c40389116a6833d9a3867_vocabhasCategory"@en ;
sh:nodeKind sh:IRI ;
sh:path <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabhasCategory> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/61fe4339-86be-54af-aa31-2e1de259c7b4> a sh:PropertyShape ;
rdfs:label "5072e1e3e96c40389116a6833d9a3867_vocabprice"@en ;
sh:name "5072e1e3e96c40389116a6833d9a3867_vocabprice"@en ;
sh:nodeKind sh:IRI ;
sh:path <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabprice> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/7415de09-2560-510f-add9-80a0c36bc284> a sh:PropertyShape ;
rdfs:label "5072e1e3e96c40389116a6833d9a3867_vocabname"@en ;
sh:name "5072e1e3e96c40389116a6833d9a3867_vocabname"@en ;
sh:nodeKind sh:Literal ;
sh:path <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabname> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/b21fa2e4-92a0-52df-a04b-2e5d5132bef9> a sh:PropertyShape ;
rdfs:label "5072e1e3e96c40389116a6833d9a3867_vocabid"@en ;
sh:name "5072e1e3e96c40389116a6833d9a3867_vocabid"@en ;
sh:nodeKind sh:Literal ;
sh:path <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabid> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/d7999f52-f438-550e-910b-57aadd396f2d> a sh:PropertyShape ;
rdfs:label "5072e1e3e96c40389116a6833d9a3867_vocabhasProductManager"@en ;
sh:name "5072e1e3e96c40389116a6833d9a3867_vocabhasProductManager"@en ;
sh:nodeKind sh:IRI ;
sh:path <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabhasProductManager> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/dc394b44-356f-5e00-bf31-1b956e7ef295> a sh:PropertyShape ;
rdfs:label "5072e1e3e96c40389116a6833d9a3867_vocabamount"@en ;
sh:name "5072e1e3e96c40389116a6833d9a3867_vocabamount"@en ;
sh:nodeKind sh:Literal ;
sh:path <https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/vocabamount> .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/bee2a79a-5486-5f1f-ace2-cb3df6ed92c3> a sh:PropertyShape ;
rdfs:label "was derived from (prov:)"@en ;
sh:name "was derived from (prov:)"@en ;
sh:nodeKind sh:IRI ;
sh:path prov:wasDerivedFrom .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/d0e9e696-d3f2-5966-a62f-d8358cbde741> a sh:PropertyShape ;
rdfs:label "label (rdfs:)"@en ;
sh:name "label (rdfs:)"@en ;
sh:nodeKind sh:Literal ;
sh:path rdfs:label .

<https://eccenca.com/shapes_plugin/5072e1e3e96c40389116a6833d9a3867/shapes/73b69787-81ea-563e-8e09-9c84cad4cf2b> a sh:PropertyShape ;
rdfs:label "type (rdf:)"@en ;
sh:name "type (rdf:)"@en ;
sh:nodeKind sh:IRI ;
sh:path rdf:type .

Loading

0 comments on commit fa6b6b7

Please sign in to comment.