From 13cdc03b729b9ba7876bc1d92dcef6aa8e005cf0 Mon Sep 17 00:00:00 2001 From: seitenbau-govdata Date: Thu, 28 Sep 2023 16:28:21 +0200 Subject: [PATCH 1/2] Improves access service tests --- .../tests/test_euro_dcatap_2_profile_parse.py | 59 +++++++++++++++++++ .../test_euro_dcatap_2_profile_serialize.py | 45 ++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/ckanext/dcat/tests/test_euro_dcatap_2_profile_parse.py b/ckanext/dcat/tests/test_euro_dcatap_2_profile_parse.py index 750d29d8..52f6a54c 100644 --- a/ckanext/dcat/tests/test_euro_dcatap_2_profile_parse.py +++ b/ckanext/dcat/tests/test_euro_dcatap_2_profile_parse.py @@ -431,6 +431,65 @@ def test_parse_distribution_access_service_literal(self): self._run_parse_access_service(expected_access_services) + def test_dataset_distribution_access_service_list_values_only(self): + + data = ''' + + + + + Das ist eine deutsche Beschreibung der Distribution + Download WFS Naturräume Geest und Marsch (GML) + + + + + + + + + + + ''' + + p = RDFParser(profiles=DCAT_AP_PROFILES) + + p.parse(data) + + datasets = [d for d in p.datasets()] + + assert len(datasets) == 1 + + dataset = datasets[0] + + # Resources + assert len(dataset['resources']) == 1 + + resource = dataset['resources'][0] + + # Access services + access_service_list = json.loads(resource.get('access_services')) + assert len(access_service_list) == 1 + + access_service = access_service_list[0] + + # List + endpoint_url_list = access_service.get('endpoint_url') + print(access_service) + assert len(endpoint_url_list) == 1 + assert 'http://publications.europa.eu/webapi/rdf/sparql' in endpoint_url_list + + serves_dataset_list = access_service.get('serves_dataset') + assert len(serves_dataset_list) == 1 + assert 'http://example.org' in serves_dataset_list + def _build_access_services_graph_from_list(self, access_service_list): """ Creates an access service graph based on the given list. diff --git a/ckanext/dcat/tests/test_euro_dcatap_2_profile_serialize.py b/ckanext/dcat/tests/test_euro_dcatap_2_profile_serialize.py index da356d2b..4d016e23 100644 --- a/ckanext/dcat/tests/test_euro_dcatap_2_profile_serialize.py +++ b/ckanext/dcat/tests/test_euro_dcatap_2_profile_serialize.py @@ -542,6 +542,51 @@ def test_access_services_absent(self): assert len(object_list) == 0 assert 'access_services' not in dataset['resources'][0] + def test_access_services_list_values_only(self): + + resource = { + 'id': 'c041c635-054f-4431-b647-f9186926d021', + 'package_id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6', + 'name': 'Distribution name', + 'access_services': json.dumps([ + { + 'endpoint_url': ['http://publications.europa.eu/webapi/rdf/sparql'], + 'serves_dataset': ['http://data.europa.eu/88u/dataset/eu-whoiswho-the-official-directory-of-the-european-union'] + } + ]) + } + + dataset = { + 'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6', + 'name': 'test-dataset', + 'title': 'Test DCAT dataset', + 'resources': [ + resource + ] + } + + s = RDFSerializer(profiles=DCAT_AP_PROFILES) + g = s.g + + dataset_ref = s.graph_from_dataset(dataset) + + assert len([t for t in g.triples((dataset_ref, DCAT.distribution, None))]) == 1 + + distribution = self._triple(g, dataset_ref, DCAT.distribution, None)[2] + + assert len([t for t in g.triples((distribution, DCAT.accessService, None))]) == 1 + + # Access services + access_service_object = self._triple(g, distribution, DCAT.accessService, None)[2] + + access_services = json.loads(resource['access_services']) + + # Lists + self._assert_values_list(g, access_service_object, DCAT.endpointURL, + self._get_typed_list(access_services[0].get('endpoint_url'), URIRef)) + self._assert_values_list(g, access_service_object, DCAT.servesDataset, + self._get_typed_list(access_services[0].get('serves_dataset'), URIRef)) + def _assert_simple_value(self, graph, object, predicate, value): """ Checks if a triple with the given value is present in the graph From 47a16334aaf25be4c15e85663d564cdb0415daaf Mon Sep 17 00:00:00 2001 From: seitenbau-govdata Date: Mon, 2 Oct 2023 15:11:40 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d9227a6..995d61dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased](https://github.com/ckan/ckanext-dcat/compare/v1.5.1...HEAD) +* Improve access service tests (#258) +* Fix missing access service items when parsing dataset (#256) ## [v1.5.1](https://github.com/ckan/ckanext-dcat/compare/v1.5.0...v1.5.1) - 2023-06-20