Skip to content

Commit

Permalink
Issue #18/EP-4049 more hardening for listing collections and jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Oct 20, 2021
1 parent ae9ab51 commit 738615a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package_dir={"": "src"},
install_requires=[
"requests",
"openeo>=0.8.3a3.*",
"openeo>=0.9.1a2.*",
"openeo_driver>=0.14.6a1.*",
"flask~=2.0",
"gunicorn~=20.0",
Expand Down
4 changes: 2 additions & 2 deletions src/openeo_aggregator/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _get_collection_metadata(self, collection_id: str) -> dict:
con = self.backends.get_connection(backend_id=bid)
try:
by_backend[bid] = con.describe_collection(name=collection_id)
except OpenEoApiError as e:
except OpenEoClientException as e:
# TODO: user warning https://github.com/Open-EO/openeo-api/issues/412
_log.warning(f"Failed collection metadata for {collection_id!r} at {con.id}", exc_info=True)
# TODO: avoid caching of final result? (#2)
Expand Down Expand Up @@ -432,7 +432,7 @@ def get_user_jobs(self, user_id: str) -> List[BatchJobMetadata]:
with con.authenticated_from_request(request=flask.request):
try:
backend_jobs = con.list_jobs()
except OpenEoApiError as e:
except OpenEoClientException as e:
# TODO: user warning https://github.com/Open-EO/openeo-api/issues/412
_log.warning(f"Failed to get job listing from backend {con.id!r}: {e!r}")
backend_jobs = []
Expand Down
12 changes: 7 additions & 5 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ def test_collections_resilience(
assert set(c["id"] for c in res["collections"]) == expected
# TODO: test caching of results

def test_collection_full_metadata_resilience(self, api100, requests_mock, backend1, backend2):
@pytest.mark.parametrize("status_code", [204, 303, 404, 500])
def test_collection_full_metadata_resilience(self, api100, requests_mock, backend1, backend2, status_code):
requests_mock.get(backend1 + "/collections", json={"collections": [{"id": "S1"}, {"id": "S2"}]})
requests_mock.get(backend2 + "/collections", json={"collections": [{"id": "S3"}]})
requests_mock.get(backend1 + "/collections/S1", json={"id": "S1", "title": "b1 S1"})
requests_mock.get(backend1 + "/collections/S2", status_code=404, text="down")
requests_mock.get(backend2 + "/collections/S3", status_code=404, text="down")
requests_mock.get(backend1 + "/collections/S2", status_code=status_code, text="down")
requests_mock.get(backend2 + "/collections/S3", status_code=status_code, text="down")

res = api100.get("/collections/S1").assert_status_code(200).json
assert res == DictSubSet({"id": "S1", "title": "b1 S1"})
Expand Down Expand Up @@ -586,12 +587,13 @@ def test_list_jobs(self, api100, requests_mock, backend1, backend2):
{"id": "b2-job05", "status": "running", "created": "2021-06-05T12:34:56Z"},
]

def test_list_jobs_failing_backend(self, api100, requests_mock, backend1, backend2, caplog):
@pytest.mark.parametrize("status_code", [204, 303, 404, 500])
def test_list_jobs_failing_backend(self, api100, requests_mock, backend1, backend2, caplog, status_code):
requests_mock.get(backend1 + "/jobs", json={"jobs": [
{"id": "job03", "status": "running", "created": "2021-06-03T12:34:56Z"},
{"id": "job08", "status": "running", "created": "2021-06-08T12:34:56Z"},
]})
requests_mock.get(backend2 + "/jobs", status_code=404, json={"code": "nope", "message": "and nope"})
requests_mock.get(backend2 + "/jobs", status_code=status_code, json={"code": "nope", "message": "and nope"})
api100.set_auth_bearer_token(token=TEST_USER_BEARER_TOKEN)
res = api100.get("/jobs").assert_status_code(200).json
assert res["jobs"] == [
Expand Down

0 comments on commit 738615a

Please sign in to comment.