From 7772bc0ec0ec41920ef272b25430461b20a39960 Mon Sep 17 00:00:00 2001 From: Stefaan Lippens Date: Thu, 25 Apr 2024 09:28:14 +0200 Subject: [PATCH] job_options_update: clarify that input can be `None` --- CHANGELOG.md | 2 +- src/openeo_aggregator/about.py | 2 +- src/openeo_aggregator/config.py | 2 +- tests/test_views.py | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af7ba24..496a13b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ The format is roughly based on [Keep a Changelog](https://keepachangelog.com/en/ ## [0.29.0] -- Add config option to inject job options before sending a job to upstream back-end ([#135](https://github.com/Open-EO/openeo-aggregator/issues/135)) +- Add config option `job_options_update` to inject job options before sending a job to upstream back-end ([#135](https://github.com/Open-EO/openeo-aggregator/issues/135)) ## [0.28.0] diff --git a/src/openeo_aggregator/about.py b/src/openeo_aggregator/about.py index 2884e4c..d04d079 100644 --- a/src/openeo_aggregator/about.py +++ b/src/openeo_aggregator/about.py @@ -2,7 +2,7 @@ import sys from typing import Optional -__version__ = "0.32.1a1" +__version__ = "0.32.2a1" def log_version_info(logger: Optional[logging.Logger] = None): diff --git a/src/openeo_aggregator/config.py b/src/openeo_aggregator/config.py index 9cc79f1..8b67680 100644 --- a/src/openeo_aggregator/config.py +++ b/src/openeo_aggregator/config.py @@ -33,7 +33,7 @@ class ConfigException(ValueError): class JobOptionsUpdater(Protocol): """API for `job_options_update` config (callable)""" - def __call__(self, job_options: dict, backend_id: str) -> dict: + def __call__(self, job_options: Union[dict, None], backend_id: str) -> Union[dict, None]: """Return updated job options dict""" ... diff --git a/tests/test_views.py b/tests/test_views.py index 3c99b3d..51bdd6b 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1689,6 +1689,38 @@ def post_jobs(request: requests.Request, context): assert res.headers["Location"] == "http://oeoa.test/openeo/1.0.0/jobs/b1-th3j0b" assert res.headers["OpenEO-Identifier"] == "b1-th3j0b" + @pytest.mark.parametrize( + ["job_options_update", "expected"], + [ + (None, {}), + ( + lambda job_options, backend_id: {**(job_options or {}), **{"beverage": f"fizzy{backend_id}"}}, + {"job_options": {"beverage": "fizzyb1"}}, + ), + ], + ) + def test_create_job_options_update_start_empty(self, api100, requests_mock, backend1, job_options_update, expected): + """Test job_options_update handling when there are no job options yet""" + requests_mock.get(backend1 + "/collections", json={"collections": [{"id": "S2"}]}) + + def post_jobs(request: requests.Request, context): + assert request.json() == {"process": {"process_graph": pg}} | expected + context.headers["Location"] = backend1 + "/jobs/th3j0b" + context.headers["OpenEO-Identifier"] = "th3j0b" + context.status_code = 201 + + requests_mock.post(backend1 + "/jobs", text=post_jobs) + + pg = {"lc": {"process_id": "load_collection", "arguments": {"id": "S2"}, "result": True}} + api100.set_auth_bearer_token(token=TEST_USER_BEARER_TOKEN) + with config_overrides(job_options_update=job_options_update): + res = api100.post( + "/jobs", + json={"process": {"process_graph": pg}}, + ).assert_status_code(201) + assert res.headers["Location"] == "http://oeoa.test/openeo/1.0.0/jobs/b1-th3j0b" + assert res.headers["OpenEO-Identifier"] == "b1-th3j0b" + @pytest.mark.parametrize( "body", [