From fab1de611f6ca66ce1ca0389c2c59759e724a287 Mon Sep 17 00:00:00 2001 From: Benjamin Webb <40066515+webb-ben@users.noreply.github.com> Date: Tue, 10 Sep 2024 19:22:21 -0400 Subject: [PATCH] Update SPARQL tests --- docker/pygeoapi.config.yml | 2 ++ pygeoapi_plugins/provider/sparql.py | 7 +++++-- tests/test_sparql_provider.py | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docker/pygeoapi.config.yml b/docker/pygeoapi.config.yml index 2a49023..e43bc27 100644 --- a/docker/pygeoapi.config.yml +++ b/docker/pygeoapi.config.yml @@ -107,6 +107,8 @@ resources: - subject: '?subject' predicate: '' object: '?leader' + filter: + - 'FILTER (isIRI(?leader) || (isLiteral(?leader) && (!bound(datatype(?leader)) || datatype(?leader) = xsd:string)))' populated: type: collection diff --git a/pygeoapi_plugins/provider/sparql.py b/pygeoapi_plugins/provider/sparql.py index 8af5c8b..f51f3ae 100644 --- a/pygeoapi_plugins/provider/sparql.py +++ b/pygeoapi_plugins/provider/sparql.py @@ -191,8 +191,11 @@ def get(self, identifier, **kwargs): subj, _subj = self._clean_subj(feature['properties'], self.bind) values = self._sparql(subj) - feature['properties'] = self._combine(feature['properties'], - values.get(_subj)) + try: + feature['properties'] = self._combine( + feature['properties'], values.get(_subj)) + except AttributeError: + LOGGER.warning('Unable to add SPARQL context') return feature diff --git a/tests/test_sparql_provider.py b/tests/test_sparql_provider.py index fbdf67a..2b2f184 100644 --- a/tests/test_sparql_provider.py +++ b/tests/test_sparql_provider.py @@ -59,6 +59,9 @@ def config(): 'predicate': 'dbpedia2:leaderName', 'object': '?leader' } + ], + 'filter': [ + 'FILTER (isIRI(?leader) || (isLiteral(?leader) && (!bound(datatype(?leader)) || datatype(?leader) = xsd:string)))' ] } } @@ -85,9 +88,9 @@ def test_query(config): feature = p.get('0') assert feature['id'] == '0' assert feature['properties']['city'] == 'Berlin' - assert feature['properties']['datasets'][0]['population'] == '3677472' + assert feature['properties']['population'] == '3677472' assert ( - feature['properties']['datasets'][0]['country'] + feature['properties']['country'] == 'http://dbpedia.org/resource/Germany' ) # noqa assert feature['geometry']['coordinates'][0] == 13.405