From 157478fc329cb648a786f0cfa259e3ef735e890e Mon Sep 17 00:00:00 2001 From: Johan Schreurs Date: Mon, 14 Nov 2022 15:15:22 +0100 Subject: [PATCH] Issue #78, code review, Removed left-over of test coverage for API version 0.4 --- tests/conftest.py | 9 --------- tests/test_backend.py | 13 +------------ tests/test_views.py | 14 +------------- 3 files changed, 2 insertions(+), 34 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 39c7dd63..424c52c4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,15 +33,6 @@ def backend2(requests_mock) -> str: return domain -# as "lib_requests_mock": make a distinction with the pytest fixture that has the same name -def set_backend_to_api_version(requests_mock, domain: str, api_version: str) -> str: - """Helper function to make the backend connection use the expected API version.""" - - # TODO: would like a nicer solution to make the backend fixtures match the expected API version. - # Good enough for now tough, just have to remember to call it in your test. - return requests_mock.get(f"{domain}/", json={"api_version": api_version}) - - @pytest.fixture def main_test_oidc_issuer() -> str: """ diff --git a/tests/test_backend.py b/tests/test_backend.py index 3a38070a..0ad4b076 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -15,7 +15,7 @@ from openeo_driver.users.auth import HttpAuthHandler from openeo_driver.errors import ProcessGraphMissingException, ProcessGraphInvalidException, ServiceUnsupportedException from openeo.rest import OpenEoApiError, OpenEoRestError -from .conftest import DEFAULT_MEMOIZER_CONFIG, set_backend_to_api_version +from .conftest import DEFAULT_MEMOIZER_CONFIG TEST_USER = "Mr.Test" @@ -393,7 +393,6 @@ def test_create_service_succeeds( """When it gets a correct params for a new service, it successfully creates it.""" # Set up responses for creating the service in backend 1 - set_backend_to_api_version(requests_mock, backend1, "1.0.0") expected_openeo_id = "wmts-foo" location_backend_1 = backend1 + "/services/" + expected_openeo_id process_graph = {"foo": {"process_id": "foo", "arguments": {}}} @@ -429,8 +428,6 @@ def test_create_service_backend_raises_openeoapiexception( # Set up responses for creating the service in backend 1: # This time the backend raises an error, one that will be reported as a OpenEOApiException. - set_backend_to_api_version(requests_mock, backend1, "1.0.0") - set_backend_to_api_version(requests_mock, backend2, "1.0.0") process_graph = {"foo": {"process_id": "foo", "arguments": {}}} requests_mock.post( backend1 + "/services", @@ -464,7 +461,6 @@ def test_create_service_backend_reraises( # Set up responses for creating the service in backend 1 # This time the backend raises an error, one that will simply be re-raised/passed on as it is. - set_backend_to_api_version(requests_mock, backend1, "1.0.0") process_graph = {"foo": {"process_id": "foo", "arguments": {}}} requests_mock.post( backend1 + "/services", @@ -593,9 +589,6 @@ def test_update_service_succeeds( ): """When it receives an existing service ID and a correct payload, it updates the expected service.""" - set_backend_to_api_version(requests_mock, backend1, "1.0.0") - set_backend_to_api_version(requests_mock, backend2, "1.0.0") - # Also test that it can skip backends that don't have the service mock_get1 = requests_mock.get( backend1 + "/services/wmts-foo", @@ -637,8 +630,6 @@ def test_update_service_service_id_not_found( ): """When the service ID does not exist then the aggregator raises an ServiceNotFoundException.""" - set_backend_to_api_version(requests_mock, backend1, "1.0.0") - set_backend_to_api_version(requests_mock, backend2, "1.0.0") mock_get1 = requests_mock.get( backend1 + "/services/wmts-foo", status_code=404 @@ -679,8 +670,6 @@ def test_update_service_backend_response_is_an_error_status( ): """When the backend response is an error HTTP 400/500 then the aggregator raises an OpenEoApiError.""" - set_backend_to_api_version(requests_mock, backend1, "1.0.0") - set_backend_to_api_version(requests_mock, backend2, "1.0.0") requests_mock.get( backend1 + "/services/wmts-foo", json=service_metadata_wmts_foo.prepare_for_json(), diff --git a/tests/test_views.py b/tests/test_views.py index aafda045..4e2b082d 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -15,7 +15,7 @@ from openeo_driver.backend import ServiceMetadata from openeo_driver.testing import ApiTester, TEST_USER_AUTH_HEADER, TEST_USER, TEST_USER_BEARER_TOKEN, DictSubSet, \ RegexMatcher -from .conftest import assert_dict_subset, get_api100, get_flask_app, set_backend_to_api_version +from .conftest import assert_dict_subset, get_api100, get_flask_app class TestGeneral: @@ -1557,8 +1557,6 @@ def test_remove_service_succeeds( ): """When remove_service is called with an existing service ID, it removes service and returns HTTP 204.""" api100.set_auth_bearer_token(TEST_USER_BEARER_TOKEN) - set_backend_to_api_version(requests_mock, backend1, "1.0.0") - set_backend_to_api_version(requests_mock, backend2, "1.0.0") # Also test that it skips backends that don't have the service2 mock_get1 = requests_mock.get( @@ -1587,8 +1585,6 @@ def test_remove_service_service_id_not_found( ): """When the service ID does not exist then the aggregator raises an ServiceNotFoundException.""" api100.set_auth_bearer_token(TEST_USER_BEARER_TOKEN) - set_backend_to_api_version(requests_mock, backend1, "1.0.0") - set_backend_to_api_version(requests_mock, backend2, "1.0.0") # Neither backend has the service available, and the aggregator should detect this. mock_get1 = requests_mock.get( @@ -1619,8 +1615,6 @@ def test_remove_service_backend_response_is_an_error_status( ): """When the backend response is an error HTTP 400/500 then the aggregator raises an OpenEoApiError.""" api100.set_auth_bearer_token(TEST_USER_BEARER_TOKEN) - set_backend_to_api_version(requests_mock, backend1, "1.0.0") - set_backend_to_api_version(requests_mock, backend2, "1.0.0") # Will find it on the first backend, and it should skip the second backend so we don't add it to backend2. requests_mock.get( @@ -1651,8 +1645,6 @@ def test_update_service_service_succeeds( ): """When it receives an existing service ID and a correct payload, it updates the expected service.""" api100.set_auth_bearer_token(TEST_USER_BEARER_TOKEN) - set_backend_to_api_version(requests_mock, backend1, "1.0.0") - set_backend_to_api_version(requests_mock, backend2, "1.0.0") # Also test that it skips backends that don't have the service. mock_get1 = requests_mock.get( @@ -1688,8 +1680,6 @@ def test_update_service_service_id_not_found( ): """When the service ID does not exist then the aggregator raises an ServiceNotFoundException.""" api100.set_auth_bearer_token(TEST_USER_BEARER_TOKEN) - set_backend_to_api_version(requests_mock, backend1, "1.0.0") - set_backend_to_api_version(requests_mock, backend2, "1.0.0") # Neither backend has the service available, and the aggregator should detect this. mock_get1 = requests_mock.get( @@ -1733,8 +1723,6 @@ def test_update_service_backend_response_is_an_error_status( ): """When the backend response is an error HTTP 400/500 then the aggregator raises an OpenEoApiError.""" api100.set_auth_bearer_token(TEST_USER_BEARER_TOKEN) - set_backend_to_api_version(requests_mock, backend1, "1.0.0") - set_backend_to_api_version(requests_mock, backend2, "1.0.0") requests_mock.get( backend1 + "/services/wmts-foo",