From 0cbaf495a589fcaa311ebba1921270315ef70ea7 Mon Sep 17 00:00:00 2001 From: Johan Schreurs Date: Fri, 9 Dec 2022 13:53:38 +0100 Subject: [PATCH] Issue #84: A bit of cleanup --- src/openeo_aggregator/backend.py | 4 ++-- tests/test_backend.py | 17 +++++++++-------- tests/test_views.py | 29 +++++------------------------ 3 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/openeo_aggregator/backend.py b/src/openeo_aggregator/backend.py index eaad26e1..afc35092 100644 --- a/src/openeo_aggregator/backend.py +++ b/src/openeo_aggregator/backend.py @@ -652,12 +652,11 @@ def __init__( config: AggregatorConfig ): super(AggregatorSecondaryServices, self).__init__() - self._backends = backends + self._backends = backends self._memoizer = memoizer_from_config(config=config, namespace="SecondaryServices") self._backends.on_connections_change.add(self._memoizer.invalidate) - # TODO Issue #84 Decide which backend based on service type. Will need to remove self._processing for this. self._processing = processing def _get_connection_and_backend_service_id( @@ -804,6 +803,7 @@ def create_service(self, user_id: str, process_graph: dict, service_type: str, a # Instead, properly determine backend based on service type? # See https://github.com/Open-EO/openeo-aggregator/issues/78#issuecomment-1326180557 # and https://github.com/Open-EO/openeo-aggregator/issues/83 + # Should be able to remove this hardcoded workaround once issue #85 has been implemented. if "sentinelhub" in self._backends._backend_urls: backend_id = "sentinelhub" else: diff --git a/tests/test_backend.py b/tests/test_backend.py index 536a1024..94f0f3d2 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -134,7 +134,7 @@ class TestAggregatorSecondaryServices: # TODO: most tests here (the ones that do flask app stuff and auth) # belong under test_views.py - WMTS_SERVICE_TYPE = { + SERVICE_TYPES_ONLT_WMTS = { "WMTS": { "configuration": { "colormap": { @@ -162,7 +162,7 @@ def test_service_types_simple( """Given 2 backends and only 1 backend has a single service type, then the aggregator returns that 1 service type's metadata. """ - single_service_type = self.WMTS_SERVICE_TYPE + single_service_type = self.SERVICE_TYPES_ONLT_WMTS requests_mock.get(backend1 + "/service_types", json=single_service_type) requests_mock.get(backend2 + "/service_types", json={}) processing = AggregatorProcessing(backends=multi_backend_connection, catalog=catalog, config=config) @@ -174,12 +174,13 @@ def test_service_types_simple( def test_service_types_simple_cached( self, multi_backend_connection, config, catalog, backend1, backend2, requests_mock ): - """The service_types call is cached: + """Scenario: The service_types call is cached: When we get the service types several times, the second call that happens before the cache expires, doesn't hit the backend. But the third call that happens that happens after the cache has expired does hit the backend again. """ - single_service_type = self.WMTS_SERVICE_TYPE + # Just need one service type for the test. + single_service_type = self.SERVICE_TYPES_ONLT_WMTS mock_be1 = requests_mock.get(backend1 + "/service_types", json=single_service_type) processing = AggregatorProcessing(backends=multi_backend_connection, catalog=catalog, config=config) implementation = AggregatorSecondaryServices(backends=multi_backend_connection, processing=processing, config=config) @@ -351,7 +352,7 @@ def test_create_service_succeeds( }, status_code=201 ) - requests_mock.get(backend1 + "/service_types", json=self.WMTS_SERVICE_TYPE) + requests_mock.get(backend1 + "/service_types", json=self.SERVICE_TYPES_ONLT_WMTS) processing = AggregatorProcessing(backends=multi_backend_connection, catalog=catalog, config=config) implementation = AggregatorSecondaryServices(backends=multi_backend_connection, processing=processing, config=config) @@ -371,7 +372,7 @@ def test_create_service_raises_serviceunsupportedexception( """When it gets a request for a service type that no backend supports, it raises ServiceUnsupportedException.""" # Set up one service type. Don't want test to succeed because there are no services at all. - requests_mock.get(backend1 + "/service_types", json=self.WMTS_SERVICE_TYPE) + requests_mock.get(backend1 + "/service_types", json=self.SERVICE_TYPES_ONLT_WMTS) non_existent_service_id = "b1-doesnotexist" # check that this requests_mock does not get called @@ -413,7 +414,7 @@ def test_create_service_backend_raises_openeoapiexception( backend1 + "/services", exc=exception_class("Some server error"), ) - requests_mock.get(backend1 + "/service_types", json=self.WMTS_SERVICE_TYPE) + requests_mock.get(backend1 + "/service_types", json=self.SERVICE_TYPES_ONLT_WMTS) processing = AggregatorProcessing(backends=multi_backend_connection, catalog=catalog, config=config) implementation = AggregatorSecondaryServices(backends=multi_backend_connection, processing=processing, config=config) @@ -445,7 +446,7 @@ def test_create_service_backend_reraises( backend1 + "/services", exc=exception_class("Some server error") ) - requests_mock.get(backend1 + "/service_types", json=self.WMTS_SERVICE_TYPE) + requests_mock.get(backend1 + "/service_types", json=self.SERVICE_TYPES_ONLT_WMTS) processing = AggregatorProcessing(backends=multi_backend_connection, catalog=catalog, config=config) implementation = AggregatorSecondaryServices(backends=multi_backend_connection, processing=processing, config=config) diff --git a/tests/test_views.py b/tests/test_views.py index 0cdc06f3..160893ab 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1363,7 +1363,7 @@ def service_metadata_wmts_foo(self): # not setting "created": This is used to test creating a service. ) - WMTS_SERVICE_TYPE = { + SERVICE_TYPES_ONLT_WMTS = { "WMTS": { "configuration": { "colormap": { @@ -1389,27 +1389,8 @@ def test_service_types_simple(self, api100, backend1, backend2, requests_mock): """Given 2 backends but only 1 backend has a single service, then the aggregator returns that 1 service's metadata. """ - single_service_type = { - "WMTS": { - "configuration": { - "colormap": { - "default": "YlGn", - "description": - "The colormap to apply to single band layers", - "type": "string" - }, - "version": { - "default": "1.0.0", - "description": "The WMTS version to use.", - "enum": ["1.0.0"], - "type": "string" - } - }, - "links": [], - "process_parameters": [], - "title": "Web Map Tile Service" - } - } + # Only need a single service type. + single_service_type = self.SERVICE_TYPES_ONLT_WMTS requests_mock.get(backend1 + "/service_types", json=single_service_type) requests_mock.get(backend2 + "/service_types", json={}) @@ -1725,7 +1706,7 @@ def test_create_wmts(self, api100, requests_mock, backend1): }, status_code=201 ) - requests_mock.get(backend1 + "/service_types", json=self.WMTS_SERVICE_TYPE) + requests_mock.get(backend1 + "/service_types", json=self.SERVICE_TYPES_ONLT_WMTS) resp = api100.post('/services', json=post_data).assert_status_code(201) @@ -1822,7 +1803,7 @@ def test_create_wmts_reports_500_server_error(self, api100, requests_mock, backe backend1 + "/services", exc=exception_class("Testing exception handling") ) - requests_mock.get(backend1 + "/service_types", json=self.WMTS_SERVICE_TYPE) + requests_mock.get(backend1 + "/service_types", json=self.SERVICE_TYPES_ONLT_WMTS) resp = api100.post('/services', json=post_data) assert resp.status_code == 500