Skip to content

Commit

Permalink
Fix compatibility with openeo 0.27.0
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Jan 17, 2024
1 parent f895542 commit e64d608
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
install_requires=[
"requests",
"attrs",
"openeo>=0.25.0",
"openeo>=0.27.0",
"openeo_driver>=0.75.0.dev",
"flask~=2.0",
"gunicorn~=20.0",
Expand Down
4 changes: 2 additions & 2 deletions tests/partitionedjobs/test_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ def test_create_error(self, pjob, zk_db, zk_tracker, flask_request, dummy1, dumm
assert set(subjobs.keys()) == {"0000", "0001"}
assert zk_db.get_sjob_status(user_id=john, pjob_id=pjob_id, sjob_id="0000") == {
"status": "error",
"message": approx_str_prefix("Create failed: [500] unknown: nope"),
"message": approx_str_prefix('Create failed: [500] {"message": "nope"}'),
"timestamp": approx_now(),
}
assert zk_db.get_sjob_status(user_id=john, pjob_id=pjob_id, sjob_id="0001") == {
"status": "error",
"message": approx_str_prefix("Create failed: [500] unknown: meh"),
"message": approx_str_prefix('Create failed: [500] {"message": "meh"}'),
"timestamp": approx_now(),
}

Expand Down
12 changes: 9 additions & 3 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,13 @@ def test_create_service_raises_serviceunsupportedexception(
assert mock_get_capabilities.called
assert mock_service_types.called

@pytest.mark.parametrize("exception_class", [OpenEoApiError, OpenEoRestError])
@pytest.mark.parametrize(
"exception_factory",
[
lambda m: OpenEoApiError(http_status_code=500, code="Internal", message=m),
OpenEoRestError,
],
)
def test_create_service_backend_raises_openeoapiexception(
self,
flask_app,
Expand All @@ -671,7 +677,7 @@ def test_create_service_backend_raises_openeoapiexception(
catalog,
backend1,
requests_mock,
exception_class,
exception_factory,
mbldr,
):
"""When the backend raises a general exception the aggregator raises an OpenEOApiException."""
Expand All @@ -686,7 +692,7 @@ def test_create_service_backend_raises_openeoapiexception(
process_graph = {"foo": {"process_id": "foo", "arguments": {}}}
mock_post = requests_mock.post(
backend1 + "/services",
exc=exception_class("Some server error"),
exc=exception_factory("Some server error"),
)
mock_service_types = requests_mock.get(backend1 + "/service_types", json=self.SERVICE_TYPES_ONLT_WMTS)

Expand Down
22 changes: 18 additions & 4 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,20 @@ def get_me(request: requests.Request, context):
with pytest.raises(OpenEoApiError, match=r"\[401\] AuthenticationRequired: Unauthorized"):
con.get("/me")

@pytest.mark.parametrize("exception", [Exception, ValueError, OpenEoApiError])
@pytest.mark.parametrize(
"exception",
[
Exception,
ValueError,
OpenEoApiError(http_status_code=500, code="Internal", message="Nope"),
],
)
def test_basic_auth_from_request_failure(self, requests_mock, exception):
requests_mock.get("https://foo.test/", json={"api_version": "1.0.0"})
con = BackendConnection(id="foo", url="https://foo.test", configured_oidc_providers=[])
request = flask.Request(environ={"HTTP_AUTHORIZATION": "Bearer basic//l3tm31n"})
assert con.auth is None
with pytest.raises(exception):
with pytest.raises(exception.__class__ if isinstance(exception, Exception) else exception):
with con.authenticated_from_request(request=request):
assert isinstance(con.auth, BearerAuth)
raise exception
Expand Down Expand Up @@ -112,7 +119,14 @@ def get_me(request: requests.Request, context):
with pytest.raises(OpenEoApiError, match=r"\[401\] AuthenticationRequired: Unauthorized"):
con.get("/me")

@pytest.mark.parametrize("exception", [Exception, ValueError, OpenEoApiError])
@pytest.mark.parametrize(
"exception",
[
Exception,
ValueError,
OpenEoApiError(http_status_code=500, code="Internal", message="Nope"),
],
)
def test_oidc_auth_from_request_failure(self, requests_mock, configured_oidc_providers, exception):
requests_mock.get("https://foo.test/", json={"api_version": "1.0.0"})
requests_mock.get("https://foo.test/credentials/oidc", json={"providers": [
Expand All @@ -122,7 +136,7 @@ def test_oidc_auth_from_request_failure(self, requests_mock, configured_oidc_pro
con = BackendConnection(id="foo", url="https://foo.test", configured_oidc_providers=configured_oidc_providers)
request = flask.Request(environ={"HTTP_AUTHORIZATION": "Bearer oidc/egi/l3tm31n"})
assert con.auth is None
with pytest.raises(exception):
with pytest.raises(exception.__class__ if isinstance(exception, Exception) else exception):
with con.authenticated_from_request(request=request):
assert isinstance(con.auth, BearerAuth)
raise exception
Expand Down
17 changes: 9 additions & 8 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2467,10 +2467,14 @@ def test_create_wmts_reports_400_client_error(self, api100, requests_mock, backe
assert resp.status_code == 400

# OpenEoApiError, OpenEoRestError: more general errors we can expect to lead to a HTTP 500 server error.
@pytest.mark.parametrize("exception_class", [OpenEoApiError, OpenEoRestError])
def test_create_wmts_reports_500_server_error(
self, api100, requests_mock, backend1, exception_class, mbldr
):
@pytest.mark.parametrize(
"exception_factory",
[
lambda m: OpenEoApiError(http_status_code=500, code="Internal", message=m),
OpenEoRestError,
],
)
def test_create_wmts_reports_500_server_error(self, api100, requests_mock, backend1, exception_factory, mbldr):
"""When the backend raises exceptions that are typically a server error / HTTP 500, then
we expect the aggregator to return a HTTP 500 status code."""

Expand All @@ -2490,10 +2494,7 @@ def test_create_wmts_reports_500_server_error(
"title": "My Service",
"description": "Service description"
}
requests_mock.post(
backend1 + "/services",
exc=exception_class("Testing exception handling")
)
requests_mock.post(backend1 + "/services", exc=exception_factory("Testing exception handling"))
requests_mock.get(backend1 + "/service_types", json=self.SERVICE_TYPES_ONLT_WMTS)

resp = api100.post('/services', json=post_data)
Expand Down

0 comments on commit e64d608

Please sign in to comment.