-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added process to show usage of defaults (#114)
* added process to show usage of defaults
- Loading branch information
Showing
7 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |