Skip to content

Commit

Permalink
Issue #78, code review, Removed left-over of test coverage for API ve…
Browse files Browse the repository at this point in the history
…rsion 0.4
  • Loading branch information
JohanKJSchreurs authored and soxofaan committed Nov 24, 2022
1 parent 18aba1f commit 157478f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 34 deletions.
9 changes: 0 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
13 changes: 1 addition & 12 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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": {}}}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
14 changes: 1 addition & 13 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 157478f

Please sign in to comment.