Skip to content

Commit

Permalink
Update SPARQL tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webb-ben committed Sep 10, 2024
1 parent 5eaf681 commit fab1de6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docker/pygeoapi.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ resources:
- subject: '?subject'
predicate: '<http://dbpedia.org/property/leaderName>'
object: '?leader'
filter:
- 'FILTER (isIRI(?leader) || (isLiteral(?leader) && (!bound(datatype(?leader)) || datatype(?leader) = xsd:string)))'

populated:
type: collection
Expand Down
7 changes: 5 additions & 2 deletions pygeoapi_plugins/provider/sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions tests/test_sparql_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def config():
'predicate': 'dbpedia2:leaderName',
'object': '?leader'
}
],
'filter': [
'FILTER (isIRI(?leader) || (isLiteral(?leader) && (!bound(datatype(?leader)) || datatype(?leader) = xsd:string)))'
]
}
}
Expand All @@ -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
Expand Down

0 comments on commit fab1de6

Please sign in to comment.