Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use same format handling in collection coverage as elsewhere #1412

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions pygeoapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@
F_GZIP = 'gzip'
F_PNG = 'png'
F_MVT = 'mvt'
F_NETCDF = 'NetCDF'

#: Formats allowed for ?f= requests (order matters for complex MIME types)
FORMAT_TYPES = OrderedDict((
(F_HTML, 'text/html'),
(F_JSONLD, 'application/ld+json'),
(F_JSON, 'application/json'),
(F_PNG, 'image/png'),
(F_MVT, 'application/vnd.mapbox-vector-tile')
(F_MVT, 'application/vnd.mapbox-vector-tile'),
(F_NETCDF, 'application/x-netcdf'),
))

#: Locale used for system responses (e.g. exceptions)
Expand Down Expand Up @@ -2433,11 +2435,10 @@ def get_collection_coverage(self, request: Union[APIRequest, Any],
"""

query_args = {}
format_ = F_JSON
format_ = request.format or F_JSON

# Force response content type and language (en-US only) headers
headers = request.get_response_headers(SYSTEM_LOCALE,
FORMAT_TYPES[F_JSON],
**self.api_headers)

LOGGER.debug('Loading provider')
Expand Down Expand Up @@ -2499,10 +2500,7 @@ def get_collection_coverage(self, request: Union[APIRequest, Any],
'InvalidParameterValue', msg)

query_args['datetime_'] = datetime_

if 'f' in request.params:
# Format explicitly set using a query parameter
query_args['format_'] = format_ = request.format
query_args['format_'] = format_

properties = request.params.get('properties')
if properties:
Expand Down
14 changes: 12 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,8 +1449,11 @@ def test_get_collection_coverage(config, api_):
rsp_headers, code, response = api_.get_collection_coverage(
req, 'gdps-temperature')

assert code == HTTPStatus.OK
assert rsp_headers['Content-Type'] == 'application/prs.coverage+json'
# NOTE: This test used to assert the code to be 200 OK,
# but it requested HTML, which is not available,
# so it should be 400 Bad Request
assert code == HTTPStatus.BAD_REQUEST
assert rsp_headers['Content-Type'] == 'text/html'

req = mock_request({'subset': 'Lat(5:10),Long(5:10)'})
rsp_headers, code, response = api_.get_collection_coverage(
Expand Down Expand Up @@ -1487,6 +1490,13 @@ def test_get_collection_coverage(config, api_):
assert code == HTTPStatus.OK
assert isinstance(response, bytes)

req = mock_request(HTTP_ACCEPT='application/x-netcdf')
rsp_headers, code, response = api_.get_collection_coverage(
req, 'cmip5')

assert code == HTTPStatus.OK
assert rsp_headers['Content-Type'] == 'application/x-netcdf'

# req = mock_request({
# 'subset': 'time("2006-07-01T06:00:00":"2007-07-01T06:00:00")'
# })
Expand Down
Loading