Skip to content

Commit

Permalink
CITE fixes and setup (#330)
Browse files Browse the repository at this point in the history
* add CITE testing setup

* fix item link relations, handle invalid limit/startindex parameters

* ignore all generated OpenAPI files

* update config and steps

* update config
  • Loading branch information
tomkralidis authored Jan 6, 2020
1 parent 55d6b8f commit c9abac2
Show file tree
Hide file tree
Showing 6 changed files with 1,390 additions and 9 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ ENV/
.mypy_cache/

# pygeoapi artifacts
local.config.yml
local.openapi.yml
openapi.yml
*.openapi.yml

# misc
*.swp
Expand Down
37 changes: 31 additions & 6 deletions pygeoapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,21 +343,21 @@ def describe_collections(self, headers_, format_, dataset=None):
LOGGER.debug('Adding JSON and HTML link relations')
collection['links'].append({
'type': 'application/geo+json',
'rel': 'item',
'rel': 'items',
'title': 'Features as GeoJSON',
'href': '{}/collections/{}/items?f=json'.format(
self.config['server']['url'], k)
})
collection['links'].append({
'type': 'application/ld+json',
'rel': 'item',
'rel': 'items',
'title': 'Features as RDF (GeoJSON-LD)',
'href': '{}/collections/{}/items?f=jsonld'.format(
self.config['server']['url'], k)
})
collection['links'].append({
'type': 'text/html',
'rel': 'item',
'rel': 'items',
'title': 'Features as HTML',
'href': '{}/collections/{}/items?f=html'.format(
self.config['server']['url'], k)
Expand Down Expand Up @@ -495,8 +495,17 @@ def get_collection_items(self, headers, args, dataset, pathinfo=None):
}
LOGGER.error(exception)
return headers_, 400, json.dumps(exception)
except TypeError:
except (TypeError) as err:
LOGGER.warning(err)
startindex = 0
except ValueError as err:
LOGGER.warning(err)
exception = {
'code': 'InvalidParameterValue',
'description': 'startindex value should be an integer'
}
LOGGER.error(exception)
return headers_, 400, json.dumps(exception)

LOGGER.debug('Processing limit parameter')
try:
Expand All @@ -510,8 +519,17 @@ def get_collection_items(self, headers, args, dataset, pathinfo=None):
}
LOGGER.error(exception)
return headers_, 400, json.dumps(exception)
except TypeError:
except TypeError as err:
LOGGER.warning(err)
limit = int(self.config['server']['limit'])
except ValueError as err:
LOGGER.warning(err)
exception = {
'code': 'InvalidParameterValue',
'description': 'limit value should be an integer'
}
LOGGER.error(exception)
return headers_, 400, json.dumps(exception)

resulttype = args.get('resulttype') or 'results'

Expand Down Expand Up @@ -607,7 +625,14 @@ def get_collection_items(self, headers, args, dataset, pathinfo=None):

LOGGER.debug('processing property parameters')
for k, v in args.items():
if k not in reserved_fieldnames and k in p.fields.keys():
if k not in reserved_fieldnames and k not in p.fields.keys():
exception = {
'code': 'InvalidParameterValue',
'description': 'unknown query parameter'
}
LOGGER.error(exception)
return headers_, 400, json.dumps(exception)
elif k not in reserved_fieldnames and k in p.fields.keys():
LOGGER.debug('Add property filter {}={}'.format(k, v))
properties.append((k, v))

Expand Down
17 changes: 17 additions & 0 deletions tests/cite/ogcapi-features/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# CITE testing for OGC API - Features

## Test data

Test data used is a subset of the [Canadian National Water Data Archive](https://www.canada.ca/en/environment-climate-change/services/water-overview/quantity/monitoring/survey/data-products-services/national-archive-hydat.html)
as extracted from the [MSC Geomet OGC API](https://eccc-msc.github.io/open-data/msc-geomet/web-services_en/#ogc-api-features).

## Running

```bash
# install pygeoapi as per https://pygeoapi.io/#install-in-5-minutes
cd tests/cite/ogcapi-features
. cite.env
python ../../load_es_data.py ./canada-hydat-daily-mean-02hc003.json IDENTIFIER
pygeoapi generate-openapi-document -c $PYGEOAPI_CONFIG > $PYGEOAPI_OPENAPI
gunicorn pygeoapi.flask_app:APP -b 0.0.0.0:5001 --access-logfile '-'
```
Loading

0 comments on commit c9abac2

Please sign in to comment.