Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cehbrecht committed Feb 18, 2021
1 parent f64313f commit 9141044
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
12 changes: 6 additions & 6 deletions examples/wps-rest-client.py
Expand Up @@ -17,16 +17,16 @@

def usage():
print("""
Usage: %s [parameters]
Common Parameters for all request types
-------------------
-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
Expand All @@ -53,8 +53,8 @@ def usage():
python wps-rest-client.py -u https://ogc-ades.crim.ca/ADES -r GetStatus -i jsonarray2netcdf -j <JobId>
with 'payload.json' contents:
with 'payload.json' contents:
{
"mode": "async",
"response": "document",
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 15 additions & 7 deletions owslib/ogcapi/processes.py
Expand Up @@ -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:
"""
Expand All @@ -68,28 +71,33 @@ 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
url = self._build_url(path)

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
Expand Down
1 change: 1 addition & 0 deletions tests/test_ogcapi_processes_52n.py
Expand Up @@ -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')
Expand Down

0 comments on commit 9141044

Please sign in to comment.