Skip to content

Commit

Permalink
Issue #84: Made a test slightly stricter, and updated some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanKJSchreurs committed Dec 9, 2022
1 parent 0cbaf49 commit 425d4f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 9 additions & 6 deletions src/openeo_aggregator/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,6 @@ def _get_connection_and_backend_service_id(

def service_types(self) -> dict:
"""https://openeo.org/documentation/1.0/developers/api/reference.html#operation/list-service-types"""
# TODO: implement household data to cache useful data for selecting backend based on service and backend's capabilities.

cached_info = self._memoizer.get_or_call(key=("_get_service_types",), callback=self._get_service_types)
# Convert the cached results back to the format that service_types should return.
return {name: data["service_type"] for name, data, in cached_info.items()}
Expand All @@ -689,21 +687,21 @@ def _find_backend_id_for_service_type(self, service_type: str) -> Optional[str]:
return cached_info.get(service_type, {}).get("backend_id")

def _get_service_types(self) -> dict:
"""Returns a dict that maps the service name to a dict that contains 2 items:
"""Returns a dict that maps the service name to another dict that contains 2 items:
1) the backend_id that provides this secondary service
2) the service_types for self.service_types.
For example:
{'WMTS':
{'backend_id': 'b1',
'service_type': // contains what backend b1 returned for service type WMTS.
{'backend_id': 'b1',
'service_type': // contains what backend b1 returned for service type WMTS.
{'configuration':
...
}
}
'WMS':
{'backend_id': 'b2',
'service_type':
'service_type':
{'configuration':
...
}
Expand All @@ -724,6 +722,8 @@ def _get_service_types(self) -> dict:
https://github.com/Open-EO/openeo-aggregator/issues/83
https://github.com/Open-EO/openeo-aggregator/issues/84
"""

# TODO: Issue #85 data about backend capabilities could be added to the service_types data structure as well.
service_types = {}

# TODO: Instead of merge: prefix each type with backend-id? #83
Expand Down Expand Up @@ -799,6 +799,9 @@ def create_service(self, user_id: str, process_graph: dict, service_type: str, a
"""
# TODO: configuration is not used. What to do with it?

# TODO: Strictly speaking it would be better to override _create_service instead of create_service
# but for now we override create_service so we can keep the special case for the "sentinelhub" backend.

# TODO: hardcoded/forced "SentinelHub only" support for now.
# Instead, properly determine backend based on service type?
# See https://github.com/Open-EO/openeo-aggregator/issues/78#issuecomment-1326180557
Expand Down
8 changes: 5 additions & 3 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,15 @@ 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.
# At least 1 service type must be present.
# We don't want test to succeed erroneously simply because there are no services at all.
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
# Check that this requests_mock does not get called.
location_backend_1 = backend1 + "/services/" + non_existent_service_id
process_graph = {"foo": {"process_id": "foo", "arguments": {}}}
requests_mock.post(
mock_post = requests_mock.post(
backend1 + "/services",
headers={
"OpenEO-Identifier": "wmts-foo",
Expand All @@ -398,6 +399,7 @@ def test_create_service_raises_serviceunsupportedexception(
api_version="1.0.0",
configuration={}
)
assert not mock_post.called


@pytest.mark.parametrize("exception_class", [OpenEoApiError, OpenEoRestError])
Expand Down

0 comments on commit 425d4f3

Please sign in to comment.