diff --git a/examples/wps-rest-client.py b/examples/wps-rest-client.py index d29aa6e1d..808c34837 100755 --- a/examples/wps-rest-client.py +++ b/examples/wps-rest-client.py @@ -17,7 +17,7 @@ def usage(): print(""" - + Usage: %s [parameters] Common Parameters for all request types @@ -25,8 +25,8 @@ def usage(): -u, --url=[URL] the base URL of the WPS - required -r, --request=[REQUEST] the request type - required - {GetCapabilities, DescribeProcess, Processes, Execute, GetStatus} - -v, --verbose set flag for verbose output - optional (defaults to False) + {GetCapabilities, DescribeProcess, Processes, Execute, GetStatus} + -v, --verbose set flag for verbose output - optional (defaults to False) -o, --output=[FORMAT] format of the response to provide - optional {json, yaml} (default: parse and print items) when specified, responses are returned directly with the given format @@ -53,8 +53,8 @@ def usage(): python wps-rest-client.py -u https://ogc-ades.crim.ca/ADES -r GetStatus -i jsonarray2netcdf -j - with 'payload.json' contents: - + with 'payload.json' contents: + { "mode": "async", "response": "document", @@ -220,7 +220,7 @@ def print_content(output_format, output_content): print(f'\nERROR: Empty JSON data from {data}') sys.exit(7) - status_location = wps.execute(identifier, payload) + status_location = wps.execute(identifier, payload).get('location') data, success = wps.monitor_execution(location=status_location) if output: print_content(output, data) diff --git a/owslib/ogcapi/processes.py b/owslib/ogcapi/processes.py index 356b8c318..4fe0102b2 100644 --- a/owslib/ogcapi/processes.py +++ b/owslib/ogcapi/processes.py @@ -31,18 +31,21 @@ def __init__(self, url: str, json_: str = None, timeout: int = 30, __doc__ = API.__doc__ # noqa super().__init__(url, json_, timeout, headers, auth) - def processes(self) -> dict: + def processes(self) -> list: """ implements: GET /processes Lists the processes this API offers. - @returns: `dict` of available processes. + @returns: `list` of available processes. """ + processes_ = [] path = 'processes' data = self._request(path) - return data["processes"] + if 'processes' in data: + processes_.extend(data["processes"]) + return processes_ def process_description(self, process_id: str) -> dict: """ @@ -68,20 +71,25 @@ def job_list(self, process_id: str) -> dict: path = f'processes/{process_id}/jobs' return self._request(path) - def execute(self, process_id: str, json: dict) -> str: + def execute(self, process_id: str, json: dict) -> dict: """ implements: POST /processes/{process-id}/jobs Executes a process, i.e. creates a new job. Inputs and outputs will have to be specified in a JSON document that needs to be send in the POST body. - @returns: `str` of the status location + @returns: `dict` of the status location (async) or outputs (sync) """ + result = {} path = f'processes/{process_id}/jobs' resp = self._request_post(path, json) data = resp.json() - return resp.headers.get("Location", data["location"]) + if 'outputs' in data: + result['outputs'] = data['outputs'] + else: + result['location'] = resp.headers.get("Location", data.get("location")) + return result def _request_post(self, path: str, json: dict) -> requests.Response: # TODO: needs to be implemented in base class @@ -89,7 +97,7 @@ def _request_post(self, path: str, json: dict) -> requests.Response: resp = requests.post(url, json=json) - if resp.status_code != requests.codes.ok: + if resp.status_code not in [requests.codes.ok, 201]: raise RuntimeError(resp.text) return resp diff --git a/tests/test_ogcapi_processes_52n.py b/tests/test_ogcapi_processes_52n.py index 7ac82db59..ae93f86f0 100644 --- a/tests/test_ogcapi_processes_52n.py +++ b/tests/test_ogcapi_processes_52n.py @@ -7,6 +7,7 @@ SERVICE_URL = 'http://geoprocessing.demo.52north.org:8080/javaps/rest/' +@pytest.mark.xfail @pytest.mark.online @pytest.mark.skipif(not service_ok(SERVICE_URL), reason='service is unreachable')