diff --git a/test/webapi/ows/coverages/test_context.py b/test/webapi/ows/coverages/test_context.py index 8c61b249d..64d550c6c 100644 --- a/test/webapi/ows/coverages/test_context.py +++ b/test/webapi/ows/coverages/test_context.py @@ -20,7 +20,6 @@ # DEALINGS IN THE SOFTWARE. - import unittest from typing import Optional, Union, Mapping, Any @@ -31,13 +30,12 @@ def get_coverages_ctx( - server_config: Optional[Union[str, Mapping[str, Any]]] = None + server_config: Optional[Union[str, Mapping[str, Any]]] = None ) -> CoveragesContext: return get_api_ctx("ows.coverages", CoveragesContext, server_config) class CoveragesContextTest(unittest.TestCase): - def test_ctx_ok(self): ctx = get_coverages_ctx() self.assertIsInstance(ctx.server_ctx, Context) diff --git a/test/webapi/ows/coverages/test_controllers.py b/test/webapi/ows/coverages/test_controllers.py index 7974a8572..8254a67d6 100644 --- a/test/webapi/ows/coverages/test_controllers.py +++ b/test/webapi/ows/coverages/test_controllers.py @@ -29,31 +29,32 @@ import rioxarray from test.webapi.ows.coverages.test_context import get_coverages_ctx -from xcube.webapi.ows.coverages.controllers import get_coverage_as_json, \ - get_coverage_data +from xcube.webapi.ows.coverages.controllers import ( + get_coverage_as_json, + get_coverage_data, +) class CoveragesControllersTest(unittest.TestCase): - def test_get_coverage_as_json(self): - result = get_coverage_as_json(get_coverages_ctx().datasets_ctx, - 'demo') + result = get_coverage_as_json(get_coverages_ctx().datasets_ctx, 'demo') self.assertIsInstance(result, dict) path = Path(__file__).parent / 'expected.json' # with open(path, mode="w") as fp: # json.dump(result, fp, indent=2) with open(path, mode="r") as fp: - expected_result = json.load(fp) + expected_result = json.load(fp) self.assertEqual(expected_result, result) def test_get_coverage_data_tiff(self): query = dict( bbox=['52,1,51,2'], datetime=['2017-01-25'], - properties=['conc_chl'] + properties=['conc_chl'], + ) + result = get_coverage_data( + get_coverages_ctx().datasets_ctx, 'demo', query, 'image/tiff' ) - result = get_coverage_data(get_coverages_ctx().datasets_ctx, - 'demo', query, 'image/tiff') with BytesIO(result) as fh: da = rioxarray.open_rasterio(fh) self.assertIsInstance(da, xr.DataArray) @@ -65,10 +66,14 @@ def test_get_coverage_data_netcdf(self): query = dict( bbox=['52,1,51,2'], datetime=['2017-01-25'], - properties=['conc_chl,kd489'] + properties=['conc_chl,kd489'], + ) + result = get_coverage_data( + get_coverages_ctx().datasets_ctx, + 'demo', + query, + 'application/netcdf', ) - result = get_coverage_data(get_coverages_ctx().datasets_ctx, - 'demo', query, 'application/netcdf') # We can't read this directly from memory: the netcdf4 engine only # reads from filesystem paths, the h5netcdf engine (which can read # from memory) isn't an xcube dependency, and the scipy engine only @@ -83,6 +88,14 @@ def test_get_coverage_data_netcdf(self): self.assertEqual(list(ds.data_vars), ['conc_chl', 'kd489']) self.assertEqual( list(ds.variables), - ['lat', 'lat_bnds', 'lon', 'lon_bnds', 'time', 'time_bnds', - 'conc_chl', 'kd489'] + [ + 'lat', + 'lat_bnds', + 'lon', + 'lon_bnds', + 'time', + 'time_bnds', + 'conc_chl', + 'kd489', + ], ) diff --git a/test/webapi/ows/coverages/test_routes.py b/test/webapi/ows/coverages/test_routes.py index bd5592ec3..cf7521708 100644 --- a/test/webapi/ows/coverages/test_routes.py +++ b/test/webapi/ows/coverages/test_routes.py @@ -23,7 +23,6 @@ class CoveragesRoutesTest(RoutesTestCase): - def test_fetch_coverage(self): response = self.fetch('/catalog/collections/demo/coverage?f=text/json') self.assertResponseOK(response) @@ -33,11 +32,15 @@ def test_fetch_domainset(self): self.assertResponseOK(response) def test_fetch_rangetype(self): - response = self.fetch('/catalog/collections/{collectionId}/coverage/rangetype') + response = self.fetch( + '/catalog/collections/{collectionId}/coverage/rangetype' + ) self.assertResponseOK(response) def test_fetch_metadata(self): - response = self.fetch('/catalog/collections/{collectionId}/coverage/metadata') + response = self.fetch( + '/catalog/collections/{collectionId}/coverage/metadata' + ) self.assertResponseOK(response) def test_fetch_rangeset(self): diff --git a/xcube/webapi/ows/coverages/context.py b/xcube/webapi/ows/coverages/context.py index 3ce9a1b4c..6ea47818b 100644 --- a/xcube/webapi/ows/coverages/context.py +++ b/xcube/webapi/ows/coverages/context.py @@ -27,11 +27,11 @@ class CoveragesContext(ResourcesContext): - def __init__(self, server_ctx: Context): super().__init__(server_ctx) - self._datasets_ctx = server_ctx.get_api_ctx('datasets', - cls=DatasetsContext) + self._datasets_ctx = server_ctx.get_api_ctx( + 'datasets', cls=DatasetsContext + ) @property def datasets_ctx(self) -> DatasetsContext: