diff --git a/setup.py b/setup.py index d2ed2fe7..32eddd45 100644 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/tests/partitionedjobs/test_tracking.py b/tests/partitionedjobs/test_tracking.py index 6d57f95b..e8b9d306 100644 --- a/tests/partitionedjobs/test_tracking.py +++ b/tests/partitionedjobs/test_tracking.py @@ -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(), } diff --git a/tests/test_backend.py b/tests/test_backend.py index bb703189..7b37b483 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -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, @@ -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.""" @@ -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) diff --git a/tests/test_connection.py b/tests/test_connection.py index 5d57600c..2cb8cb3e 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -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 @@ -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": [ @@ -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 diff --git a/tests/test_views.py b/tests/test_views.py index 30402b58..041b44b3 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -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.""" @@ -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)