Skip to content

Commit

Permalink
added process to show usage of defaults (#114)
Browse files Browse the repository at this point in the history
* added process to show usage of defaults
  • Loading branch information
cehbrecht authored Sep 17, 2021
1 parent 67bc3a6 commit 01b0fe1
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 3 deletions.
2 changes: 2 additions & 0 deletions emu/processes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .wps_translation import Translation
from .wps_geodata import GeoData
from .wps_pandas import Pandas
from .wps_show_defaults import ShowDefaults


processes = [
Expand All @@ -45,4 +46,5 @@
Translation(),
GeoData(),
Pandas(),
ShowDefaults(),
]
80 changes: 80 additions & 0 deletions emu/processes/wps_show_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import json

from pywps import Process, LiteralInput, ComplexOutput
from pywps import FORMATS

import logging
LOGGER = logging.getLogger("PYWPS")


class ShowDefaults(Process):
"""
Process with examples of default value usage in WPS.
"""
def __init__(self):
inputs = [
LiteralInput(
'string_0',
'String 0: optional, no default',
data_type='string',
min_occurs=0
),
LiteralInput(
'string_1',
'String 1: optional with default',
data_type='string',
default='one',
min_occurs=0
),
LiteralInput(
'string_2',
'String 2: required with default',
data_type='string',
default='two',
min_occurs=1
),
LiteralInput(
'string_3',
'String 3: required no default',
data_type='string',
default='three',
min_occurs=1
),
]
outputs = [
ComplexOutput(
'output',
'Output',
as_reference=True,
supported_formats=[FORMATS.JSON]),
]

super(ShowDefaults, self).__init__(
self._handler,
identifier='show_defaults',
title="Show defaults",
abstract="Show usage of default values in WPS",
version="1.0",
inputs=inputs,
outputs=outputs,
store_supported=True,
status_supported=True
)

@staticmethod
def _handler(request, response):
response.update_status('PyWPS Process started.', 0)

if 'string_0' in request.inputs:
string0 = request.inputs['string_0'][0].data
else:
string0 = "no value"

response.outputs['output'].data = json.dumps({
'string0': string0,
'string1': request.inputs['string_1'][0].data,
'string2': request.inputs['string_2'][0].data,
'string3': request.inputs['string_3'][0].data,
})
response.update_status('PyWPS Process completed.', 100)
return response
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ channels:
dependencies:
- pip
- python>=3.6
- pywps>=4.4.0
- pywps>=4.4.5,<4.5
- jinja2
- click
- psutil
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
pywps>=4.4.0
pywps>=4.4.5
jinja2
click
psutil
defusedxml
geomet
xarray
netCDF4
Expand Down
3 changes: 3 additions & 0 deletions tests/test.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[server]
allowedinputpaths=/
language = en-US,fr-CA,de-DE

[logging]
level=DEBUG
1 change: 1 addition & 0 deletions tests/test_wps_caps.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_wps_caps():
'output_formats',
'pandas',
'poly_centroid',
'show_defaults',
'show_error',
'simple_dry_run',
'sleep',
Expand Down
50 changes: 50 additions & 0 deletions tests/test_wps_show_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import json

from pywps import Service
from pywps import get_ElementMakerForVersion

from .common import client_for
from emu.processes.wps_show_defaults import ShowDefaults

VERSION = "1.0.0"

WPS, OWS = get_ElementMakerForVersion(VERSION)


def test_wps_show_defaults_post():
client = client_for(Service(processes=[ShowDefaults()]))
request_doc = WPS.Execute(
OWS.Identifier('show_defaults'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('string_0'),
WPS.Data(WPS.LiteralData("ZERO"))
),
# WPS.Input(
# OWS.Identifier('string_1'),
# WPS.Data(WPS.LiteralData("ONE"))
# ),
# WPS.Input(
# OWS.Identifier('string_2'),
# WPS.Data(WPS.LiteralData("TWO"))
# ),
WPS.Input(
OWS.Identifier('string_3'),
WPS.Data(WPS.LiteralData("THREE"))
)
),
WPS.ResponseForm(
WPS.RawDataOutput(
OWS.Identifier('output')
)
),
version='1.0.0'
)
resp = client.post_xml(doc=request_doc)
print(resp.data)
assert resp.status_code == 200
result = json.loads(resp.data)
assert result['string0'] == 'ZERO'
assert result['string1'] == 'one'
assert result['string2'] == 'two'
assert result['string3'] == 'THREE'

0 comments on commit 01b0fe1

Please sign in to comment.