Skip to content

Commit

Permalink
handle datetime errors in config (#659) (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis authored Mar 18, 2021
1 parent e2e2b7d commit b40297a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pygeoapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2556,10 +2556,15 @@ def validate_datetime(resource_def, datetime_=None):

te = resource_def['temporal']

if te['begin'] is not None and te['begin'].tzinfo is None:
te['begin'] = te['begin'].replace(tzinfo=pytz.UTC)
if te['end'] is not None and te['end'].tzinfo is None:
te['end'] = te['end'].replace(tzinfo=pytz.UTC)
try:
if te['begin'] is not None and te['begin'].tzinfo is None:
te['begin'] = te['begin'].replace(tzinfo=pytz.UTC)
if te['end'] is not None and te['end'].tzinfo is None:
te['end'] = te['end'].replace(tzinfo=pytz.UTC)
except AttributeError:
msg = 'Configured times should be RFC3339'
LOGGER.error(msg)
raise ValueError(msg)

if '/' in datetime_: # envelope
LOGGER.debug('detected time range')
Expand Down
5 changes: 5 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,11 @@ def test_get_collection_items(config, api_):

assert code == 200

rsp_headers, code, response = api_.get_collection_items(
req_headers, {'datetime': '2005-04-22'}, 'lakes')

assert code == 400

rsp_headers, code, response = api_.get_collection_items(
req_headers, {'skipGeometry': 'true'}, 'obs')

Expand Down

0 comments on commit b40297a

Please sign in to comment.