From 9bfd638b5c4b309b5274a85cdc669778cd7d8743 Mon Sep 17 00:00:00 2001 From: Stefaan Lippens Date: Thu, 5 Oct 2023 11:37:34 +0200 Subject: [PATCH] fixup! Issue 28 Finetune parallelized `/jobs` requests --- src/openeo_aggregator/backend.py | 2 +- tests/test_views.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/openeo_aggregator/backend.py b/src/openeo_aggregator/backend.py index cffc8163..7f405d7e 100644 --- a/src/openeo_aggregator/backend.py +++ b/src/openeo_aggregator/backend.py @@ -618,7 +618,7 @@ def get_user_jobs(self, user_id: str) -> Union[List[BatchJobMetadata], dict]: except Exception as e: _log.error(f"get_user_jobs: skipping job with parse issue: {e!r}", exc_info=True) for backend_id, exc in results.failures.items(): - _log.warning(f"Failed to get job listing from backend {backend_id!r}: {result!r}") + _log.warning(f"Failed to get job listing from backend {backend_id!r}: {exc!r}") federation_missing.add(backend_id) if self.partitioned_job_tracker: diff --git a/tests/test_views.py b/tests/test_views.py index 4c2600f8..ec96171b 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1175,6 +1175,37 @@ def test_list_jobs_basic(self, api100, requests_mock, backend1, backend2): "links": [], } + def test_list_jobs_auth(self, api100, requests_mock, backend1, backend2): + def b1_get_jobs(request, context): + assert request.headers["Authorization"] == TEST_USER_AUTH_HEADER["Authorization"] + return { + "jobs": [ + {"id": "job03", "status": "running", "created": "2021-06-03T12:34:56Z"}, + {"id": "job08", "status": "running", "created": "2021-06-08T12:34:56Z", "title": "Job number 8."}, + ] + } + + def b2_get_jobs(request, context): + assert request.headers["Authorization"] == TEST_USER_AUTH_HEADER["Authorization"] + return { + "jobs": [ + {"id": "job05", "status": "running", "created": "2021-06-05T12:34:56Z"}, + ] + } + + requests_mock.get(backend1 + "/jobs", json=b1_get_jobs) + requests_mock.get(backend2 + "/jobs", json=b2_get_jobs) + api100.set_auth_bearer_token(token=TEST_USER_BEARER_TOKEN) + res = api100.get("/jobs").assert_status_code(200).json + assert res == { + "jobs": [ + {"id": "b1-job03", "status": "running", "created": "2021-06-03T12:34:56Z"}, + {"id": "b1-job08", "status": "running", "created": "2021-06-08T12:34:56Z", "title": "Job number 8."}, + {"id": "b2-job05", "status": "running", "created": "2021-06-05T12:34:56Z"}, + ], + "links": [], + } + @pytest.mark.parametrize("b2_oidc_pid", ["egi", "aho"]) def test_list_jobs_oidc_pid_mapping(self, config, requests_mock, backend1, backend2, b2_oidc_pid): # Override /credentials/oidc of backend2 before building flask app and ApiTester