Skip to content

Commit

Permalink
fixes geopython#73
Browse files Browse the repository at this point in the history
  • Loading branch information
jachym committed Dec 26, 2015
1 parent 74408c0 commit c15f6b2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 16 deletions.
21 changes: 14 additions & 7 deletions pywps/app/WPSRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,17 @@ def get_inputs_from_xml(doc):
complex_data_el = complex_data[0]
inpt = {}
inpt['identifier'] = identifier_el.text
inpt['mimeType'] = complex_data_el.attrib.get('mimeType', '')
inpt['encoding'] = complex_data_el.attrib.get(
'encoding', '').lower()
inpt['schema'] = complex_data_el.attrib.get('schema', '')
inpt['method'] = complex_data_el.attrib.get('method', 'GET')
if len(complex_data_el.getchildren()) > 0:
value_el = complex_data_el[0]
inpt['data'] = _get_dataelement_value(value_el)
else:
inpt['data'] = _get_rawvalue_value(complex_data_el.text)
inpt['mimeType'] = complex_data_el.attrib.get('mimeType', '')
inpt['encoding'] = complex_data_el.attrib.get('encoding', '')
inpt['schema'] = complex_data_el.attrib.get('schema', '')
inpt['method'] = complex_data_el.attrib.get('method', 'GET')
inpt['data'] = _get_rawvalue_value(
complex_data_el.text, inpt['encoding'])
the_inputs[identifier].append(inpt)
continue

Expand All @@ -277,7 +279,8 @@ def get_inputs_from_xml(doc):
inpt = {}
inpt['identifier'] = identifier_el.text
inpt[identifier_el.text] = reference_data_el.text
inpt['href'] = reference_data_el.attrib.get('{http://www.w3.org/1999/xlink}href', '')
inpt['href'] = reference_data_el.attrib.get(
'{http://www.w3.org/1999/xlink}href', '')
inpt['mimeType'] = reference_data_el.attrib.get('mimeType', '')
the_inputs[identifier].append(inpt)
continue
Expand Down Expand Up @@ -401,10 +404,14 @@ def _get_dataelement_value(value_el):
else:
return value_el

def _get_rawvalue_value(data):
def _get_rawvalue_value(data, encoding=None):
"""Return real value of CDATA section"""

try:
if encoding is None or encoding == "":
return data
elif encoding == 'base64':
return base64.b64decode(data)
return base64.b64decode(data)
except:
return data
52 changes: 43 additions & 9 deletions tests/test_execute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import lxml.etree
import json
from pywps import Service, Process, LiteralOutput, LiteralInput,\
BoundingBoxOutput, BoundingBoxInput, Format, ComplexInput, ComplexOutput
from pywps.validator.base import emptyvalidator
Expand Down Expand Up @@ -233,10 +234,10 @@ def test_one_string(self):
WPS.Data(WPS.LiteralData('bar')))
))
rv = get_inputs_from_xml(request_doc)
assert 'name' in rv
assert len(rv['name']) == 2
assert rv['name'][0]['data'] == 'foo'
assert rv['name'][1]['data'] == 'bar'
self.assertTrue('name' in rv)
self.assertEquals(len(rv['name']), 2)
self.assertEquals(rv['name'][0]['data'], 'foo')
self.assertEquals(rv['name'][1]['data'], 'bar')

def test_two_strings(self):
request_doc = WPS.Execute(
Expand All @@ -249,8 +250,8 @@ def test_two_strings(self):
OWS.Identifier('name2'),
WPS.Data(WPS.LiteralData('bar')))))
rv = get_inputs_from_xml(request_doc)
assert rv['name1'][0]['data'] == 'foo'
assert rv['name2'][0]['data'] == 'bar'
self.assertEquals(rv['name1'][0]['data'], 'foo')
self.assertEquals(rv['name2'][0]['data'], 'bar')

def test_complex_input(self):
the_data = E.TheData("hello world")
Expand All @@ -262,10 +263,43 @@ def test_complex_input(self):
WPS.Data(
WPS.ComplexData(the_data, mimeType='text/foobar')))))
rv = get_inputs_from_xml(request_doc)
assert rv['name'][0]['mimeType'] == 'text/foobar'
self.assertEquals(rv['name'][0]['mimeType'], 'text/foobar')
rv_doc = lxml.etree.parse(StringIO(rv['name'][0]['data'])).getroot()
assert rv_doc.tag == 'TheData'
assert rv_doc.text == "hello world"
self.assertEquals(rv_doc.tag, 'TheData')
self.assertEquals(rv_doc.text, 'hello world')

def test_complex_input_raw_value(self):
the_data = '{ "plot":{ "Version" : "0.1" } }'

request_doc = WPS.Execute(
OWS.Identifier('foo'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('json'),
WPS.Data(
WPS.ComplexData(the_data, mimeType='application/json')))))
rv = get_inputs_from_xml(request_doc)
self.assertEquals(rv['json'][0]['mimeType'], 'application/json')
json_data = json.loads(rv['json'][0]['data'])
self.assertEquals(json_data['plot']['Version'], '0.1')

def test_complex_input_base64_value(self):
the_data = 'eyAicGxvdCI6eyAiVmVyc2lvbiIgOiAiMC4xIiB9IH0='

request_doc = WPS.Execute(
OWS.Identifier('foo'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('json'),
WPS.Data(
WPS.ComplexData(the_data,
encoding='base64',
mimeType='application/json')))))
rv = get_inputs_from_xml(request_doc)
self.assertEqual(rv['json'][0]['mimeType'], 'application/json')
json_data = json.loads(rv['json'][0]['data'].decode())
self.assertEquals(json_data['plot']['Version'], '0.1')


def test_bbox_input(self):
if not PY2:
Expand Down

0 comments on commit c15f6b2

Please sign in to comment.