Skip to content

Commit

Permalink
job_options_update: clarify that input can be None
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Apr 25, 2024
1 parent 13d3959 commit 7772bc0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion src/openeo_aggregator/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/openeo_aggregator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
...

Expand Down
32 changes: 32 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down

0 comments on commit 7772bc0

Please sign in to comment.