From b40297a86476203b6c60c54fed07dc0155dec47d Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Thu, 18 Mar 2021 06:25:39 -0400 Subject: [PATCH] handle datetime errors in config (#659) (#661) --- pygeoapi/api.py | 13 +++++++++---- tests/test_api.py | 5 +++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pygeoapi/api.py b/pygeoapi/api.py index bfd75b2..8b83aa8 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -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') diff --git a/tests/test_api.py b/tests/test_api.py index e27d55d..669ff2f 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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')