Skip to content

Commit c8d1fe1

Browse files
authored
fix JSON encoding of CRS type (#610) (#650)
* Fixed the JSON encoding of the CRS type which crashed when the execution request was serialized * Fixed the JSON encoding of the CRS type by making sure the CRS is always set as string when parsing input Also added tests * Changed converting the string conversion of the crs input to calling the getcodeurn() method directly * Now setting bbox CRS handles None values properly
1 parent 7f228ff commit c8d1fe1

File tree

4 files changed

+107
-4
lines changed

4 files changed

+107
-4
lines changed

pywps/app/WPSRequest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ def get_inputs_from_xml(doc):
575575
inpt = {}
576576
inpt['identifier'] = identifier_el.text
577577
inpt['data'] = [bbox.minx, bbox.miny, bbox.maxx, bbox.maxy]
578-
inpt['crs'] = bbox.crs
578+
inpt['crs'] = bbox.crs.getcodeurn() if bbox.crs else None
579579
inpt['dimensions'] = bbox.dimensions
580580
the_inputs[identifier].append(inpt)
581581
return the_inputs

tests/processes/__init__.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
##################################################################
55

66
from pywps import Process
7-
from pywps.inout import LiteralInput, LiteralOutput
7+
from pywps.inout import LiteralInput, LiteralOutput, BoundingBoxInput, BoundingBoxOutput
88
from pywps.inout.literaltypes import ValuesReference
99

1010

@@ -71,3 +71,31 @@ def inout(request, response):
7171
a_string = request.inputs['string'][0].data
7272
response.outputs['string'].data = "".format(a_string)
7373
return response
74+
75+
76+
class BBox(Process):
77+
def __init__(self):
78+
super(BBox, self).__init__(
79+
self.bbox,
80+
identifier='bbox_test',
81+
title='BBox Test',
82+
inputs=[
83+
BoundingBoxInput(
84+
'area',
85+
'An area',
86+
abstract='Define the area of interest',
87+
crss=['epsg:4326', 'epsg:3857'],
88+
min_occurs=1,
89+
max_occurs=1
90+
),
91+
],
92+
outputs=[
93+
BoundingBoxOutput('extent', 'Extent', crss=['epsg:4326', 'epsg:3857'])
94+
]
95+
)
96+
97+
@staticmethod
98+
def bbox(request, response):
99+
area = request.inputs['area'][0].data
100+
response.outputs['extent'].data = area
101+
return response

tests/test_processing.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from pywps.app import WPSRequest
1919
from pywps.response.execute import ExecuteResponse
2020

21-
from .processes import Greeter, InOut
21+
from .processes import Greeter, InOut, BBox
2222

2323

2424
class GreeterProcessingTest(unittest.TestCase):
@@ -97,13 +97,47 @@ def test_job_dump(self):
9797
self.assertEqual(new_job.json, self.job.json) # idempotent test
9898

9999

100+
class BBoxProcessingTest(unittest.TestCase):
101+
"""Processing test case with BBox input and output process"""
102+
103+
def setUp(self):
104+
self.uuid = uuid.uuid1()
105+
self.dummy_process = BBox()
106+
self.dummy_process._set_uuid(self.uuid)
107+
self.dummy_process.set_workdir('/tmp')
108+
self.wps_request = WPSRequest()
109+
self.wps_response = ExecuteResponse(self.wps_request, self.uuid,
110+
process=self.dummy_process)
111+
self.job = Job(
112+
process=self.dummy_process,
113+
wps_request=self.wps_request,
114+
wps_response=self.wps_response)
115+
116+
def test_job_json(self):
117+
new_job = Job.from_json(json.loads(self.job.json))
118+
self.assertEqual(new_job.name, 'bbox_test')
119+
self.assertEqual(new_job.uuid, str(self.uuid))
120+
self.assertEqual(new_job.workdir, '/tmp')
121+
self.assertEqual(len(new_job.process.inputs), 1)
122+
self.assertEqual(new_job.json, self.job.json) # idempotent test
123+
124+
def test_job_dump(self):
125+
new_job = Job.load(self.job.dump())
126+
self.assertEqual(new_job.name, 'bbox_test')
127+
self.assertEqual(new_job.uuid, str(self.uuid))
128+
self.assertEqual(new_job.workdir, '/tmp')
129+
self.assertEqual(len(new_job.process.inputs), 1)
130+
self.assertEqual(new_job.json, self.job.json) # idempotent test
131+
132+
100133
def load_tests(loader=None, tests=None, pattern=None):
101134
"""Load local tests
102135
"""
103136
if not loader:
104137
loader = unittest.TestLoader()
105138
suite_list = [
106139
loader.loadTestsFromTestCase(GreeterProcessingTest),
107-
loader.loadTestsFromTestCase(InOutProcessingTest)
140+
loader.loadTestsFromTestCase(InOutProcessingTest),
141+
loader.loadTestsFromTestCase(BBoxProcessingTest)
108142
]
109143
return unittest.TestSuite(suite_list)

tests/test_wpsrequest.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import tempfile
99
import datetime
1010
import json
11+
from owslib.crs import Crs
1112

1213
from pywps.inout.literaltypes import AnyValue
1314

@@ -116,6 +117,46 @@ def test_json_inout_datetime(self):
116117
self.assertEqual(self.request.inputs['date'][0].data, datetime.date(2017, 4, 20), 'Data set')
117118
self.assertEqual(self.request.inputs['time'][0].data, datetime.time(9, 0, 0), 'Time set')
118119

120+
def test_json_inout_bbox(self):
121+
obj = {
122+
'operation': 'getcapabilities',
123+
'version': '1.0.0',
124+
'language': 'eng',
125+
'identifier': 'arghhhh',
126+
'identifiers': 'arghhhh', # TODO: why identifierS?
127+
'store_execute': True,
128+
'status': True,
129+
'lineage': True,
130+
'inputs': {
131+
'bbox': [{
132+
'identifier': 'bbox',
133+
'type': 'bbox',
134+
'bbox': '6.117602,46.176194,6.22283,46.275832',
135+
'crs': 'urn:ogc:def:crs:EPSG::4326',
136+
'crss': ['epsg:4326'],
137+
'dimensions': 2,
138+
'translations': None
139+
}],
140+
},
141+
'outputs': {},
142+
'raw': False
143+
}
144+
145+
self.request = WPSRequest()
146+
self.request.json = obj
147+
148+
self.assertEqual(self.request.inputs['bbox'][0].data, [6.117602, 46.176194, 6.22283, 46.275832], 'BBox data set')
149+
self.assertTrue(isinstance(self.request.inputs['bbox'][0].crs, str), 'CRS is a string')
150+
self.assertEqual(self.request.inputs['bbox'][0].crs, 'epsg:4326', 'CRS data correctly parsed')
151+
152+
# dump to json and reload
153+
dump = self.request.json
154+
self.request.json = json.loads(dump)
155+
156+
self.assertEqual(self.request.inputs['bbox'][0].data, [6.117602, 46.176194, 6.22283, 46.275832], 'BBox data set')
157+
self.assertTrue(isinstance(self.request.inputs['bbox'][0].crs, str), 'CRS is a string')
158+
self.assertEqual(self.request.inputs['bbox'][0].crs, 'epsg:4326', 'CRS data correctly parsed')
159+
119160

120161
def load_tests(loader=None, tests=None, pattern=None):
121162
if not loader:

0 commit comments

Comments
 (0)