Skip to content

Commit

Permalink
Fix broken pre-flight validation in `Connection.save_user_defined_pro…
Browse files Browse the repository at this point in the history
…cess`
  • Loading branch information
soxofaan committed Jan 12, 2024
1 parent 66358cb commit 2dc9c44
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix band name support in `DataCube.band()` when no metadata is available ([#515](https://github.com/Open-EO/openeo-python-client/issues/515))
- Support optional child callbacks in generated `openeo.processes`, e.g. `merge_cubes` ([#522]((https://github.com/Open-EO/openeo-python-client/issues/522)))
- Fix broken pre-flight validation in `Connection.save_user_defined_process` ([#526](https://github.com/Open-EO/openeo-python-client/issues/526))


## [0.26.0] - 2023-11-27 - "SRR6" release
Expand Down
2 changes: 1 addition & 1 deletion openeo/rest/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def store(
# TODO: this "public" flag is not standardized yet EP-3609, https://github.com/Open-EO/openeo-api/issues/310
process["public"] = public

self._connection._preflight_validation(pg_with_metadata=process)
self._connection._preflight_validation(pg_with_metadata={"process": process})
self._connection.put(
path="/process_graphs/{}".format(self.user_defined_process_id), json=process, expected_status=200
)
Expand Down
39 changes: 38 additions & 1 deletion tests/rest/test_udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@pytest.fixture
def con100(requests_mock):
requests_mock.get(API_URL + "/", json=build_capabilities(udp=True))
requests_mock.get(API_URL + "/", json=build_capabilities(udp=True, validation=True))
con = openeo.connect(API_URL)
return con

Expand Down Expand Up @@ -197,6 +197,43 @@ def check_body(request):
assert adapter.called


def test_store_with_validation(con100, requests_mock, caplog):
requests_mock.get(API_URL + "/processes", json={"processes": [{"id": "add"}]})
validation_mock = requests_mock.post(
API_URL + "/validation", json={"errors": [{"code": "TooComplex", "message": "Nope"}]}
)

two = {
"add": {
"process_id": "add",
"arguments": {
"x": 1,
"y": 1,
},
"result": True,
}
}

def check_body(request):
body = request.json()
assert body == {
"process_graph": two,
"public": False,
}
return True

udp_mock = requests_mock.put(API_URL + "/process_graphs/two", additional_matcher=check_body)

udp = con100.save_user_defined_process("two", two)
assert isinstance(udp, RESTUserDefinedProcess)

assert udp_mock.called
assert validation_mock.called
assert [(r.levelname, r.getMessage()) for r in caplog.records] == [
("WARNING", "Preflight process graph validation raised: [TooComplex] Nope")
]


def test_update(con100, requests_mock):
updated_udp = load_json_resource("data/1.0.0/udp_details.json")

Expand Down

0 comments on commit 2dc9c44

Please sign in to comment.