diff --git a/CHANGELOG.md b/CHANGELOG.md index 91b938ef1..ca36f0b88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/openeo/rest/udp.py b/openeo/rest/udp.py index 5cac35347..7c1b84f2b 100644 --- a/openeo/rest/udp.py +++ b/openeo/rest/udp.py @@ -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 ) diff --git a/tests/rest/test_udp.py b/tests/rest/test_udp.py index d621d9e7f..3c5c9fdfc 100644 --- a/tests/rest/test_udp.py +++ b/tests/rest/test_udp.py @@ -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 @@ -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")