Skip to content

Commit 2dc9c44

Browse files
committed
Fix broken pre-flight validation in Connection.save_user_defined_process
1 parent 66358cb commit 2dc9c44

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626

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

3031

3132
## [0.26.0] - 2023-11-27 - "SRR6" release

openeo/rest/udp.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def store(
9494
# TODO: this "public" flag is not standardized yet EP-3609, https://github.com/Open-EO/openeo-api/issues/310
9595
process["public"] = public
9696

97-
self._connection._preflight_validation(pg_with_metadata=process)
97+
self._connection._preflight_validation(pg_with_metadata={"process": process})
9898
self._connection.put(
9999
path="/process_graphs/{}".format(self.user_defined_process_id), json=process, expected_status=200
100100
)

tests/rest/test_udp.py

+38-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
@pytest.fixture
1616
def con100(requests_mock):
17-
requests_mock.get(API_URL + "/", json=build_capabilities(udp=True))
17+
requests_mock.get(API_URL + "/", json=build_capabilities(udp=True, validation=True))
1818
con = openeo.connect(API_URL)
1919
return con
2020

@@ -197,6 +197,43 @@ def check_body(request):
197197
assert adapter.called
198198

199199

200+
def test_store_with_validation(con100, requests_mock, caplog):
201+
requests_mock.get(API_URL + "/processes", json={"processes": [{"id": "add"}]})
202+
validation_mock = requests_mock.post(
203+
API_URL + "/validation", json={"errors": [{"code": "TooComplex", "message": "Nope"}]}
204+
)
205+
206+
two = {
207+
"add": {
208+
"process_id": "add",
209+
"arguments": {
210+
"x": 1,
211+
"y": 1,
212+
},
213+
"result": True,
214+
}
215+
}
216+
217+
def check_body(request):
218+
body = request.json()
219+
assert body == {
220+
"process_graph": two,
221+
"public": False,
222+
}
223+
return True
224+
225+
udp_mock = requests_mock.put(API_URL + "/process_graphs/two", additional_matcher=check_body)
226+
227+
udp = con100.save_user_defined_process("two", two)
228+
assert isinstance(udp, RESTUserDefinedProcess)
229+
230+
assert udp_mock.called
231+
assert validation_mock.called
232+
assert [(r.levelname, r.getMessage()) for r in caplog.records] == [
233+
("WARNING", "Preflight process graph validation raised: [TooComplex] Nope")
234+
]
235+
236+
200237
def test_update(con100, requests_mock):
201238
updated_udp = load_json_resource("data/1.0.0/udp_details.json")
202239

0 commit comments

Comments
 (0)