Skip to content

Commit

Permalink
Issue #84: A bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanKJSchreurs committed Dec 9, 2022
1 parent d32dbaf commit 0cbaf49
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/openeo_aggregator/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 9 additions & 8 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
29 changes: 5 additions & 24 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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={})

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0cbaf49

Please sign in to comment.