Skip to content

Commit

Permalink
Add Shacl test for the existing, non-scheming DCAT-AP 2 profile
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Jul 15, 2024
1 parent 35bfeff commit 8ce31ec
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ckanext/dcat/tests/test_shacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,33 @@ def test_validate_dcat_ap_2_graph_shapes_recommended():
r = validate(graph, shacl_graph=path)
conforms, results_graph, results_text = r
assert conforms, results_text


@pytest.mark.usefixtures("with_plugins")
@pytest.mark.ckan_config("ckan.plugins", "dcat")
@pytest.mark.ckan_config("ckanext.dcat.rdf.profiles", "euro_dcat_ap_2")
def test_validate_dcat_ap_2_legacy_graph_shapes():

graph = graph_from_dataset("ckan_full_dataset_dcat_ap_2_legacy.json")

# dcat-ap_2.1.1_shacl_shapes.ttl: constraints concerning existance, domain and
# literal range, and cardinalities.
path = _get_shacl_file_path("dcat-ap_2.1.1_shacl_shapes.ttl")
r = validate(graph, shacl_graph=path)
conforms, results_graph, results_text = r
assert conforms, results_text


@pytest.mark.usefixtures("with_plugins")
@pytest.mark.ckan_config("ckan.plugins", "dcat")
@pytest.mark.ckan_config("ckanext.dcat.rdf.profiles", "euro_dcat_ap_2")
def test_validate_dcat_ap_2_legacy_graph_shapes_recommended():

graph = graph_from_dataset("ckan_full_dataset_dcat_ap_2_legacy.json")

# dcat-ap_2.1.1_shacl_shapes_recommended.ttl: constraints concerning existance
# of recommended properties.
path = _get_shacl_file_path("dcat-ap_2.1.1_shacl_shapes_recommended.ttl")
r = validate(graph, shacl_graph=path)
conforms, results_graph, results_text = r
assert conforms, results_text
160 changes: 160 additions & 0 deletions examples/ckan/ckan_full_dataset_dcat_ap_2_legacy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"name": "test-dataset-shacl",
"title": "Test DCAT dataset",
"notes": "Lorem ipsum",
"url": "http://example.org/ds1",
"version": "1.0b",
"tags": [
{
"name": "Tag 1"
},
{
"name": "Tag 2"
}
],
"extras": [
{
"key": "issued",
"value": "2024-05-01"
},
{
"key": "modified",
"value": "2024-05-05"
},
{
"key": "identifier",
"value": "xx-some-dataset-id-yy"
},
{
"key": "frequency",
"value": "monthly"
},
{
"key": "provenance",
"value": "Statement about provenance"
},
{
"key": "dcat_type",
"value": "test-type"
},
{
"key": "version_notes",
"value": "Some version notes"
},
{
"key": "access_rights",
"value": "Statement about access rights"
},
{
"key": "alternate_identifier",
"value": "[\"alt-id-1\",\"alt-id-2\"]"
},
{
"key": "theme",
"value": "[\"https://example.org/uri/theme1\",\"https://example.org/uri/theme2\",\"https://example.org/uri/theme3\"]"
},
{
"key": "language",
"value": "[\"en\",\"ca\",\"es\"]"
},
{
"key": "documentation",
"value": "[\"https://example.org/some-doc.html\"]"
},
{
"key": "conforms_to",
"value": "[\"Standard1\",\"Standard2\"]"
},
{
"key": "is_referenced_by",
"value": "[\"https://doi.org/10.1038/sdata.2018.22\",\"test_isreferencedby\"]"
},
{
"key": "applicable_legislation",
"value": "[\"http://data.europa.eu/eli/reg_impl/2023/138/oj\",\"http://data.europa.eu/eli/reg_impl/2023/138/oj_alt\"]"
},
{
"key": "contact_name",
"value": "Contact 1"
},
{
"key": "contact_email",
"value": "[email protected]"
},
{
"key": "publisher_name",
"value": "Test Publisher"
},
{
"key": "publisher_email",
"value": "[email protected]"
},
{
"key": "publisher_url",
"value": "https://example.org"
},
{
"key": "publisher_type",
"value": "public_body"
},
{
"key": "temporal_start",
"value": "1905-03-01"
},
{
"key": "temporal_end",
"value": "2013-01-05"
},
{
"key": "temporal_resolution",
"value": "PT15M"
},
{
"key": "spatial",
"value": "{\"type\":\"Polygon\",\"coordinates\":[[[11.9936,54.0486],[11.9936,54.2466],[12.3045,54.2466],[12.3045,54.0486],[11.9936,54.0486]]]}"
},
{
"key": "spatial_text",
"value": "Tarragona"
},
{
"key": "spatial_uri",
"value": "https://sws.geonames.org/6361390/"
},
{
"key": "spatial_bbox",
"value": "{\"type\":\"Polygon\",\"coordinates\":[[[11.9936,54.0486],[11.9936,54.2466],[12.3045,54.2466],[12.3045,54.0486],[11.9936,54.0486]]]}"
},
{
"key": "spatial_centroid",
"value": "{\"type\":\"Point\",\"coordinates\":[1.26639,41.12386]}"
},
{
"key": "spatial_resolution_in_meters",
"value": 1.5
}
],
"resources": [
{
"name": "Resource 1",
"description": "Some description",
"url": "https://example.com/data.csv",
"format": "CSV",
"availability": "http://publications.europa.eu/resource/authority/planned-availability/EXPERIMENTAL",
"compress_format": "http://www.iana.org/assignments/media-types/application/gzip",
"package_format": "http://publications.europa.eu/resource/authority/file-type/TAR",
"size": 12323,
"hash": "4304cf2e751e6053c90b1804c89c0ebb758f395a",
"hash_algorithm": "http://spdx.org/rdf/terms#checksumAlgorithm_sha1",
"status": "http://purl.org/adms/status/Completed",
"access_url": "https://example.com/data.csv",
"download_url": "https://example.com/data.csv",
"issued": "2024-05-01T01:20:33",
"modified": "2024-05-05T09:33:20",
"license": "http://creativecommons.org/licenses/by/3.0/",
"rights": "Some stament about rights",
"language": "[\"en\",\"ca\",\"es\"]",
"access_services": "[{\"title\": \"Access Service 1\", \"endpoint_description\": \"https://example.org/endpoint_description\", \"endpoint_url\": [\"https://example.org/access_service/1\", \"https://example.org/access_service/2\"], \"serves_dataset\": [\"https://example.org/dataset/1\", \"https://example.org/dataset/2\"]}]"
}
]
}

0 comments on commit 8ce31ec

Please sign in to comment.