diff --git a/pygeoapi/api.py b/pygeoapi/api.py index c1b924c18..3cfbea700 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -107,6 +107,7 @@ 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(( @@ -114,7 +115,8 @@ (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) @@ -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') @@ -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: diff --git a/tests/test_api.py b/tests/test_api.py index cd6070ad2..863b3fee9 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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( @@ -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")' # })