|
| 1 | +#!/usr/bin/env python |
| 2 | +"""SPDX-FileCopyrightText: (c) 2026 by mundialis GmbH & Co. KG. |
| 3 | +
|
| 4 | +SPDX-License-Identifier: GPL-3.0-or-later |
| 5 | +""" |
| 6 | + |
| 7 | +__license__ = "GPL-3.0-or-later" |
| 8 | +__author__ = "Anika Weinmann" |
| 9 | +__copyright__ = "Copyright 2026 mundialis GmbH & Co. KG" |
| 10 | +__maintainer__ = "mundialis GmbH & Co. KG" |
| 11 | + |
| 12 | + |
| 13 | +import json |
| 14 | +import pathlib |
| 15 | + |
| 16 | +import pytest |
| 17 | +from flask import Response |
| 18 | + |
| 19 | +from tests.testsuite import TestCase |
| 20 | + |
| 21 | +test_process_input_error = { |
| 22 | + "inputs": { |
| 23 | + "input": { |
| 24 | + "href": "https://raw.githubusercontent.com/mmacata/pagestest/" |
| 25 | + "refs/heads/gh-pages/kalimantan_osm_epsg4326.geojson", |
| 26 | + }, |
| 27 | + "size": 3, |
| 28 | + "method": ["maximum"], |
| 29 | + "output": ["slope_n3_max"], |
| 30 | + }, |
| 31 | + "outputs": {"result": {"transmissionMode": "reference"}}, |
| 32 | + "response": "document", |
| 33 | +} |
| 34 | + |
| 35 | + |
| 36 | +class ProcessExecutionInputByReference(TestCase): |
| 37 | + """Test class for executing Processes with input by reference. |
| 38 | +
|
| 39 | + For /processes/<process_id>/execute endpoint. |
| 40 | + """ |
| 41 | + |
| 42 | + @pytest.mark.integrationtest |
| 43 | + def test_post_process_execution_vbuffer(self) -> None: |
| 44 | + """Test post method of the /processes/<process_id>/execution endpoint. |
| 45 | +
|
| 46 | + Succesfull query v.buffer process |
| 47 | + """ |
| 48 | + json_path = ( |
| 49 | + "tests/resources/request_bodies/test_v_buffer_by_reference.json" |
| 50 | + ) |
| 51 | + with pathlib.Path(json_path).open(encoding="utf-8") as file: |
| 52 | + request_body = json.load(file) |
| 53 | + |
| 54 | + resp = self.app.post( |
| 55 | + "/processes/v.buffer/execution", |
| 56 | + headers=self.HEADER_AUTH, |
| 57 | + json=request_body, |
| 58 | + ) |
| 59 | + assert isinstance(resp, Response) |
| 60 | + assert resp.status_code == 201 |
| 61 | + assert hasattr(resp, "json") |
| 62 | + assert "message" in resp.json |
| 63 | + assert resp.json["message"] == "Resource accepted" |
| 64 | + # response should follow StatusInfoResponseModel: |
| 65 | + # contain jobID, status and links |
| 66 | + assert isinstance(resp.json, dict) |
| 67 | + assert "jobID" in resp.json |
| 68 | + assert "status" in resp.json |
| 69 | + assert resp.json["status"] in { |
| 70 | + "accepted", |
| 71 | + "running", |
| 72 | + "successful", |
| 73 | + "failed", |
| 74 | + "dismissed", |
| 75 | + } |
| 76 | + assert "links" in resp.json |
| 77 | + assert isinstance(resp.json["links"], list) |
| 78 | + # link should point to job status resource |
| 79 | + if resp.json["links"]: |
| 80 | + assert any( |
| 81 | + "/jobs/" in link.get("href", "") for link in resp.json["links"] |
| 82 | + ) |
| 83 | + |
| 84 | + @pytest.mark.integrationtest |
| 85 | + def test_post_process_execution_rneighbors(self) -> None: |
| 86 | + """Test post method of the /processes/<process_id>/execution endpoint. |
| 87 | +
|
| 88 | + Succesfull query r.neighbors process with input by reference |
| 89 | + """ |
| 90 | + json_path = ( |
| 91 | + "tests/resources/request_bodies/test_r_neighbors_by_reference.json" |
| 92 | + ) |
| 93 | + with pathlib.Path(json_path).open(encoding="utf-8") as file: |
| 94 | + request_body = json.load(file) |
| 95 | + |
| 96 | + resp = self.app.post( |
| 97 | + "/processes/r.neighbors/execution", |
| 98 | + headers=self.HEADER_AUTH, |
| 99 | + json=request_body, |
| 100 | + ) |
| 101 | + assert isinstance(resp, Response) |
| 102 | + assert resp.status_code == 201 |
| 103 | + assert hasattr(resp, "json") |
| 104 | + assert "message" in resp.json |
| 105 | + assert resp.json["message"] == "Resource accepted" |
| 106 | + |
| 107 | + @pytest.mark.integrationtest |
| 108 | + def test_post_process_execution_vclip(self) -> None: |
| 109 | + """Test post method of the /processes/<process_id>/execution endpoint. |
| 110 | +
|
| 111 | + Succesfull query v.clip process with input by reference |
| 112 | + """ |
| 113 | + json_path = ( |
| 114 | + "tests/resources/request_bodies/test_v_clip_by_reference.json" |
| 115 | + ) |
| 116 | + with pathlib.Path(json_path).open(encoding="utf-8") as file: |
| 117 | + request_body = json.load(file) |
| 118 | + |
| 119 | + resp = self.app.post( |
| 120 | + "/processes/v.clip/execution", |
| 121 | + headers=self.HEADER_AUTH, |
| 122 | + json=request_body, |
| 123 | + ) |
| 124 | + assert isinstance(resp, Response) |
| 125 | + assert resp.status_code == 201 |
| 126 | + assert hasattr(resp, "json") |
| 127 | + assert "message" in resp.json |
| 128 | + assert resp.json["message"] == "Resource accepted" |
| 129 | + |
| 130 | + @pytest.mark.integrationtest |
| 131 | + def test_post_process_execution_input_by_ref_error(self) -> None: |
| 132 | + """Test post method of the /processes/<process_id>/execution endpoint. |
| 133 | +
|
| 134 | + Failing query with input by reference |
| 135 | + """ |
| 136 | + resp = self.app.post( |
| 137 | + "/processes/r.neighbors/execution", |
| 138 | + headers=self.HEADER_AUTH, |
| 139 | + json=test_process_input_error, |
| 140 | + ) |
| 141 | + assert isinstance(resp, Response) |
| 142 | + assert resp.status_code == 400 |
| 143 | + assert hasattr(resp, "json") |
| 144 | + assert "message" in resp.json |
| 145 | + assert "'.geojson' which is not supported." in resp.json["message"] |
0 commit comments