Skip to content

Commit

Permalink
fix queryables provider handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Sep 29, 2024
1 parent b3a7071 commit 9d4cc03
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 18 deletions.
29 changes: 11 additions & 18 deletions pygeoapi/api/itemtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,29 +121,22 @@ def get_collection_queryables(api: API, request: Union[APIRequest, Any],
HTTPStatus.NOT_FOUND, headers, request.format, 'NotFound', msg)

LOGGER.debug('Creating collection queryables')
try:
LOGGER.debug('Loading feature provider')
p = load_plugin('provider', get_provider_by_type(
api.config['resources'][dataset]['providers'], 'feature'))
except ProviderTypeError:

p = None
for pt in ['feature', 'coverage', 'record']:
try:
LOGGER.debug('Loading coverage provider')
LOGGER.debug(f'Loading {pt} provider')
p = load_plugin('provider', get_provider_by_type(
api.config['resources'][dataset]['providers'], 'coverage')) # noqa
api.config['resources'][dataset]['providers'], pt))
break
except ProviderTypeError:
LOGGER.debug('Loading record provider')
p = load_plugin('provider', get_provider_by_type(
api.config['resources'][dataset]['providers'], 'record'))
finally:
msg = 'queryables not available for this collection'
return api.get_exception(
HTTPStatus.BAD_REQUEST, headers, request.format,
'NoApplicableError', msg)
LOGGER.debug(f'Providing type {pt} not found')

except ProviderGenericError as err:
if p is None:
msg = 'queryables not available for this collection'
return api.get_exception(
err.http_status_code, headers, request.format,
err.ogc_exception_code, err.message)
HTTPStatus.BAD_REQUEST, headers, request.format,
'NoApplicableError', msg)

queryables = {
'type': 'object',
Expand Down
8 changes: 8 additions & 0 deletions tests/api/test_itemtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def test_get_collection_queryables(config, api_):
assert 'properties' in queryables
assert len(queryables['properties']) == 5

req = mock_api_request({'f': 'json'})
rsp_headers, code, response = get_collection_queryables(api_, req, 'canada-metadata') # noqa
assert rsp_headers['Content-Type'] == 'application/schema+json'
queryables = json.loads(response)

assert 'properties' in queryables
assert len(queryables['properties']) == 10

# test with provider filtered properties
api_.config['resources']['obs']['providers'][0]['properties'] = ['stn_id']

Expand Down
38 changes: 38 additions & 0 deletions tests/pygeoapi-test-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,44 @@ resources:
name: png
mimetype: image/png

canada-metadata:
type: collection
title:
en: Open Canada sample data
fr: Exemple de donn\u00e9es Canada Ouvert
description:
en: Sample metadata records from open.canada.ca
fr: Exemples d'enregistrements de m\u00e9tadonn\u00e9es sur ouvert.canada.ca
keywords:
en:
- canada
- open data
fr:
- canada
- donn\u00e9es ouvertes
links:
- type: text/html
rel: canonical
title: information
href: https://open.canada.ca/en/open-data
hreflang: en-CA
- type: text/html
rel: alternate
title: informations
href: https://ouvert.canada.ca/fr/donnees-ouvertes
hreflang: fr-CA
extents:
spatial:
bbox: [-180,-90,180,90]
crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
providers:
- type: record
name: TinyDBCatalogue
data: tests/data/open.canada.ca/sample-records.tinydb
id_field: externalId
time_field: created
title_field: title

hello-world:
type: process
processor:
Expand Down

0 comments on commit 9d4cc03

Please sign in to comment.