Skip to content

Commit

Permalink
fix item queryables provider handling (#1820)
Browse files Browse the repository at this point in the history
* fix queryables provider handling

* fix test
  • Loading branch information
tomkralidis authored Sep 29, 2024
1 parent b3a7071 commit 474cb60
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 21 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
4 changes: 2 additions & 2 deletions tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def test_conformance(config, api_):

assert isinstance(root, dict)
assert 'conformsTo' in root
assert len(root['conformsTo']) == 37
assert len(root['conformsTo']) == 42
assert 'http://www.opengis.net/spec/ogcapi-features-2/1.0/conf/crs' \
in root['conformsTo']

Expand Down Expand Up @@ -604,7 +604,7 @@ def test_describe_collections(config, api_):
collections = json.loads(response)

assert len(collections) == 2
assert len(collections['collections']) == 9
assert len(collections['collections']) == 10
assert len(collections['links']) == 3

rsp_headers, code, response = api_.describe_collections(req, 'foo')
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
2 changes: 1 addition & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_path_basename():
def test_filter_dict_by_key_value(config):
collections = util.filter_dict_by_key_value(config['resources'],
'type', 'collection')
assert len(collections) == 9
assert len(collections) == 10

notfound = util.filter_dict_by_key_value(config['resources'],
'type', 'foo')
Expand Down

0 comments on commit 474cb60

Please sign in to comment.