-
Notifications
You must be signed in to change notification settings - Fork 120
/
test_execute.py
733 lines (622 loc) · 26.9 KB
/
test_execute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
##################################################################
# Copyright 2018 Open Source Geospatial Foundation and others #
# licensed under MIT, Please consult LICENSE.txt for details #
##################################################################
import unittest
import pytest
from pywps import xml_util as etree
import json
import tempfile
import os.path
from pywps import Service, Process, LiteralOutput, LiteralInput,\
BoundingBoxOutput, BoundingBoxInput, Format, ComplexInput, ComplexOutput, FORMATS
from pywps.validator.base import emptyvalidator
from pywps.validator.complexvalidator import validategml
from pywps.exceptions import InvalidParameterValue
from pywps import get_inputs_from_xml
from pywps import E, get_ElementMakerForVersion
from pywps.app.basic import get_xpath_ns
from pywps.tests import client_for, assert_response_success
from pywps import configuration
from io import StringIO
try:
import netCDF4
except ImportError:
WITH_NC4 = False
else:
WITH_NC4 = True
DATA_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
VERSION = "1.0.0"
WPS, OWS = get_ElementMakerForVersion(VERSION)
xpath_ns = get_xpath_ns(VERSION)
def create_ultimate_question():
def handler(request, response):
response.outputs['outvalue'].data = '42'
return response
return Process(handler=handler,
identifier='ultimate_question',
title='Ultimate Question',
outputs=[LiteralOutput('outvalue', 'Output Value', data_type='string')])
def create_greeter():
def greeter(request, response):
name = request.inputs['name'][0].data
assert isinstance(name, str)
response.outputs['message'].data = "Hello {}!".format(name)
return response
return Process(handler=greeter,
identifier='greeter',
title='Greeter',
inputs=[LiteralInput('name', 'Input name', data_type='string')],
outputs=[LiteralOutput('message', 'Output message', data_type='string')])
def create_translated_greeter():
def greeter(request, response):
name = request.inputs['name'][0].data
response.outputs['message'].data = "Hello {}!".format(name)
return response
return Process(
handler=greeter,
identifier='greeter',
title='Greeter',
abstract='Say hello',
inputs=[
LiteralInput(
'name',
'Input name',
data_type='string',
abstract='Input description',
translations={"fr-CA": {"title": "Nom", "abstract": "Description"}},
)
],
outputs=[
LiteralOutput(
'message',
'Output message',
data_type='string',
abstract='Output description',
translations={"fr-CA": {"title": "Message de retour", "abstract": "Description"}},
)
],
translations={"fr-CA": {"title": "Salutations", "abstract": "Dire allô"}},
)
def create_bbox_process():
def bbox_process(request, response):
coords = request.inputs['mybbox'][0].data
assert isinstance(coords, list)
assert len(coords) == 4
assert coords[0] == 15.0
response.outputs['outbbox'].data = coords
return response
return Process(handler=bbox_process,
identifier='my_bbox_process',
title='Bbox process',
inputs=[BoundingBoxInput('mybbox', 'Input name', ["EPSG:4326"])],
outputs=[BoundingBoxOutput('outbbox', 'Output message', ["EPSG:4326"])])
def create_complex_proces():
def complex_proces(request, response):
response.outputs['complex'].data = request.inputs['complex'][0].data
return response
frmt = Format(mime_type='application/gml', extension=".gml") # this is unknown mimetype
return Process(handler=complex_proces,
identifier='my_complex_process',
title='Complex process',
inputs=[
ComplexInput(
'complex',
'Complex input',
default="DEFAULT COMPLEX DATA",
supported_formats=[frmt])
],
outputs=[
ComplexOutput(
'complex',
'Complex output',
supported_formats=[frmt])
])
def create_complex_nc_process():
def complex_proces(request, response):
from pywps.dependencies import netCDF4 as nc
url = request.inputs['dods'][0].url
with nc.Dataset(url) as D:
response.outputs['conventions'].data = D.Conventions
response.outputs['outdods'].url = url
response.outputs['ncraw'].file = os.path.join(DATA_DIR, 'netcdf', 'time.nc')
response.outputs['ncraw'].data_format = FORMATS.NETCDF
return response
return Process(handler=complex_proces,
identifier='my_opendap_process',
title='Opendap process',
inputs=[
ComplexInput(
'dods',
'Opendap input',
supported_formats=[Format('DODS'), Format('NETCDF')],
# mode=MODE.STRICT
)
],
outputs=[
LiteralOutput(
'conventions',
'NetCDF convention',
),
ComplexOutput('outdods', 'Opendap output',
supported_formats=[FORMATS.DODS, ],
as_reference=True),
ComplexOutput('ncraw', 'NetCDF raw data output',
supported_formats=[FORMATS.NETCDF, ],
as_reference=False)
])
def create_mimetype_process():
def _handler(request, response):
response.outputs['mimetype'].data = response.outputs['mimetype'].data_format.mime_type
return response
frmt_txt = Format(mime_type='text/plain')
frmt_txt2 = Format(mime_type='text/plain+test')
return Process(handler=_handler,
identifier='get_mimetype_process',
title='Get mimeType process',
inputs=[],
outputs=[
ComplexOutput(
'mimetype',
'mimetype of requested output',
supported_formats=[frmt_txt, frmt_txt2])
])
def create_metalink_process():
from .processes.metalinkprocess import MultipleOutputs
return MultipleOutputs()
def get_output(doc):
"""Return the content of LiteralData, Reference or ComplexData."""
output = {}
for output_el in xpath_ns(doc, '/wps:ExecuteResponse'
'/wps:ProcessOutputs/wps:Output'):
[identifier_el] = xpath_ns(output_el, './ows:Identifier')
lit_el = xpath_ns(output_el, './wps:Data/wps:LiteralData')
if lit_el != []:
output[identifier_el.text] = lit_el[0].text
ref_el = xpath_ns(output_el, './wps:Reference')
if ref_el != []:
output[identifier_el.text] = ref_el[0].attrib['href']
data_el = xpath_ns(output_el, './wps:Data/wps:ComplexData')
if data_el != []:
if data_el[0].text:
output[identifier_el.text] = data_el[0].text
else: # XML children
ch = list(data_el[0])[0]
output[identifier_el.text] = etree.tostring(ch)
return output
class ExecuteTest(unittest.TestCase):
"""Test for Exeucte request KVP request"""
@pytest.mark.xfail(reason="test.opendap.org is offline")
def test_dods(self):
if not WITH_NC4:
self.skipTest('netCDF4 not installed')
my_process = create_complex_nc_process()
service = Service(processes=[my_process])
href = "http://test.opendap.org:80/opendap/netcdf/examples/sresa1b_ncar_ccsm3_0_run1_200001.nc"
""" # Is this how the request should be written ?
request_doc = WPS.Execute(
OWS.Identifier('my_opendap_process'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('dods'),
WPS.Reference(
WPS.Body('request body'),
{'{http://www.w3.org/1999/xlink}href': href},
method='POST'
)
#WPS.Data(WPS.ComplexData(href=href, mime_type='application/x-ogc-dods'))
# This form is not supported yet. Should it be ?
)
),
version='1.0.0'
)
resp = client.post_xml(doc=request_doc)
assert_response_success(resp)
"""
class FakeRequest():
identifier = 'my_opendap_process'
service = 'wps'
operation = 'execute'
version = '1.0.0'
raw = True,
inputs = {'dods': [{
'identifier': 'dods',
'href': href,
}]}
store_execute = False
lineage = False
outputs = ['conventions']
language = "en-US"
request = FakeRequest()
resp = service.execute('my_opendap_process', request, 'fakeuuid')
self.assertEqual(resp.outputs['conventions'].data, 'CF-1.0')
self.assertEqual(resp.outputs['outdods'].url, href)
self.assertTrue(resp.outputs['outdods'].as_reference)
self.assertFalse(resp.outputs['ncraw'].as_reference)
with open(os.path.join(DATA_DIR, 'netcdf', 'time.nc'), 'rb') as f:
data = f.read()
self.assertEqual(resp.outputs['ncraw'].data, data)
def test_input_parser(self):
"""Test input parsing
"""
my_process = create_complex_proces()
service = Service(processes=[my_process])
self.assertEqual(len(service.processes), 1)
self.assertTrue(service.processes['my_complex_process'])
class FakeRequest():
identifier = 'complex_process'
service = 'wps'
operation = 'execute'
version = '1.0.0'
inputs = {'complex': [{
'identifier': 'complex',
'mimeType': 'text/gml',
'data': 'the data'
}]}
language = "en-US"
request = FakeRequest()
try:
service.execute('my_complex_process', request, 'fakeuuid')
except InvalidParameterValue as e:
self.assertEqual(e.locator, 'mimeType')
request.inputs['complex'][0]['mimeType'] = 'application/gml'
parsed_inputs = service.create_complex_inputs(my_process.inputs[0],
request.inputs['complex'])
# TODO parse outputs and their validators too
self.assertEqual(parsed_inputs[0].data_format.validate, emptyvalidator)
request.inputs['complex'][0]['mimeType'] = 'application/xml+gml'
try:
parsed_inputs = service.create_complex_inputs(my_process.inputs[0],
request.inputs['complex'])
except InvalidParameterValue as e:
self.assertEqual(e.locator, 'mimeType')
try:
my_process.inputs[0].data_format = Format(mime_type='application/xml+gml')
except InvalidParameterValue as e:
self.assertEqual(e.locator, 'mimeType')
frmt = Format(mime_type='application/xml+gml', validate=validategml)
self.assertEqual(frmt.validate, validategml)
my_process.inputs[0].supported_formats = [frmt]
my_process.inputs[0].data_format = Format(mime_type='application/xml+gml')
parsed_inputs = service.create_complex_inputs(my_process.inputs[0],
request.inputs['complex'])
self.assertEqual(parsed_inputs[0].data_format.validate, validategml)
def test_input_default(self):
"""Test input parsing
"""
my_process = create_complex_proces()
service = Service(processes=[my_process])
self.assertEqual(len(service.processes), 1)
self.assertTrue(service.processes['my_complex_process'])
class FakeRequest():
identifier = 'complex_process'
service = 'wps'
operation = 'execute'
version = '1.0.0'
inputs = {}
raw = False
outputs = {}
store_execute = False
lineage = False
language = "en-US"
request = FakeRequest()
response = service.execute('my_complex_process', request, 'fakeuuid')
self.assertEqual(response.outputs['complex'].data, 'DEFAULT COMPLEX DATA')
def test_output_mimetype(self):
"""Test input parsing
"""
my_process = create_mimetype_process()
service = Service(processes=[my_process])
self.assertEqual(len(service.processes), 1)
self.assertTrue(service.processes['get_mimetype_process'])
class FakeRequest():
def __init__(self, mimetype):
self.outputs = {'mimetype': {
'identifier': 'mimetype',
'mimetype': mimetype,
'data': 'the data'
}}
identifier = 'get_mimetype_process'
service = 'wps'
operation = 'execute'
version = '1.0.0'
inputs = {}
raw = False
store_execute = False
lineage = False
language = "en-US"
# valid mimetype
request = FakeRequest('text/plain+test')
response = service.execute('get_mimetype_process', request, 'fakeuuid')
self.assertEqual(response.outputs['mimetype'].data, 'text/plain+test')
# non valid mimetype
request = FakeRequest('text/xml')
with self.assertRaises(InvalidParameterValue):
response = service.execute('get_mimetype_process', request, 'fakeuuid')
def test_metalink(self):
client = client_for(Service(processes=[create_metalink_process()]))
resp = client.get('?Request=Execute&identifier=multiple-outputs')
assert resp.status_code == 400
def test_missing_process_error(self):
client = client_for(Service(processes=[create_ultimate_question()]))
resp = client.get('?Request=Execute&identifier=foo')
assert resp.status_code == 400
def test_get_with_no_inputs(self):
client = client_for(Service(processes=[create_ultimate_question()]))
resp = client.get('?service=wps&version=1.0.0&Request=Execute&identifier=ultimate_question')
assert_response_success(resp)
assert get_output(resp.xml) == {'outvalue': '42'}
def test_post_with_no_inputs(self):
client = client_for(Service(processes=[create_ultimate_question()]))
request_doc = WPS.Execute(
OWS.Identifier('ultimate_question'),
version='1.0.0'
)
resp = client.post_xml(doc=request_doc)
assert_response_success(resp)
assert get_output(resp.xml) == {'outvalue': '42'}
def test_post_with_string_input(self):
client = client_for(Service(processes=[create_greeter()]))
request_doc = WPS.Execute(
OWS.Identifier('greeter'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('name'),
WPS.Data(WPS.LiteralData('foo'))
)
),
version='1.0.0'
)
resp = client.post_xml(doc=request_doc)
assert_response_success(resp)
assert get_output(resp.xml) == {'message': "Hello foo!"}
def test_bbox(self):
client = client_for(Service(processes=[create_bbox_process()]))
request_doc = WPS.Execute(
OWS.Identifier('my_bbox_process'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('mybbox'),
WPS.Data(WPS.BoundingBoxData(
OWS.LowerCorner('15.0 50.0'),
OWS.UpperCorner('16.0 51.0'),
))
)
),
version='1.0.0'
)
resp = client.post_xml(doc=request_doc)
assert_response_success(resp)
[output] = xpath_ns(resp.xml, '/wps:ExecuteResponse'
'/wps:ProcessOutputs/wps:Output')
self.assertEqual('outbbox', xpath_ns(
output,
'./ows:Identifier')[0].text)
lower_corner = xpath_ns(output, './wps:Data/wps:BoundingBoxData/ows:LowerCorner')[0].text
lower_corner = lower_corner.strip().replace(' ', ' ')
self.assertEqual('15.0 50.0', lower_corner)
upper_corner = xpath_ns(output, './wps:Data/wps:BoundingBoxData/ows:UpperCorner')[0].text
upper_corner = upper_corner.strip().replace(' ', ' ')
self.assertEqual('16.0 51.0', upper_corner)
def test_output_response_dataType(self):
client = client_for(Service(processes=[create_greeter()]))
request_doc = WPS.Execute(
OWS.Identifier('greeter'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('name'),
WPS.Data(WPS.LiteralData('foo'))
)
),
version='1.0.0'
)
resp = client.post_xml(doc=request_doc)
el = next(resp.xml.iter('{http://www.opengis.net/wps/1.0.0}LiteralData'))
assert el.attrib['dataType'] == 'string'
class ExecuteTranslationsTest(unittest.TestCase):
def setUp(self):
configuration.get_config_value('server', 'language')
configuration.CONFIG.set('server', 'language', 'en-US,fr-CA')
def tearDown(self):
configuration.CONFIG.set('server', 'language', 'en-US')
def test_translations(self):
client = client_for(Service(processes=[create_translated_greeter()]))
request_doc = WPS.Execute(
OWS.Identifier('greeter'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('name'),
WPS.Data(WPS.LiteralData('foo'))
)
),
WPS.ResponseForm(
WPS.ResponseDocument(
lineage='true',
)
),
version='1.0.0',
language='fr-CA',
)
resp = client.post_xml(doc=request_doc)
assert resp.xpath('/wps:ExecuteResponse/@xml:lang')[0] == "fr-CA"
process_title = [e.text for e in resp.xpath('//wps:Process/ows:Title')]
assert process_title == ["Salutations"]
process_abstract = [e.text for e in resp.xpath('//wps:Process/ows:Abstract')]
assert process_abstract == ["Dire allô"]
input_titles = [e.text for e in resp.xpath('//wps:Input/ows:Title')]
assert input_titles == ["Nom"]
input_abstract = [e.text for e in resp.xpath('//wps:Input/ows:Abstract')]
assert input_abstract == ["Description"]
output_titles = [e.text for e in resp.xpath('//wps:OutputDefinitions/wps:Output/ows:Title')]
assert output_titles == ["Message de retour"]
output_abstract = [e.text for e in resp.xpath('//wps:OutputDefinitions/wps:Output/ows:Abstract')]
assert output_abstract == ["Description"]
output_titles = [e.text for e in resp.xpath('//wps:ProcessOutputs/wps:Output/ows:Title')]
assert output_titles == ["Message de retour"]
output_abstract = [e.text for e in resp.xpath('//wps:ProcessOutputs/wps:Output/ows:Abstract')]
assert output_abstract == ["Description"]
class ExecuteXmlParserTest(unittest.TestCase):
"""Tests for Execute request XML Parser
"""
def test_empty(self):
request_doc = WPS.Execute(OWS.Identifier('foo'))
assert get_inputs_from_xml(request_doc) == {}
def test_one_string(self):
request_doc = WPS.Execute(
OWS.Identifier('foo'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('name'),
WPS.Data(WPS.LiteralData('foo'))),
WPS.Input(
OWS.Identifier('name'),
WPS.Data(WPS.LiteralData('bar')))
))
rv = get_inputs_from_xml(request_doc)
self.assertTrue('name' in rv)
self.assertEqual(len(rv['name']), 2)
self.assertEqual(rv['name'][0]['data'], 'foo')
self.assertEqual(rv['name'][1]['data'], 'bar')
def test_two_strings(self):
request_doc = WPS.Execute(
OWS.Identifier('foo'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('name1'),
WPS.Data(WPS.LiteralData('foo'))),
WPS.Input(
OWS.Identifier('name2'),
WPS.Data(WPS.LiteralData('bar')))))
rv = get_inputs_from_xml(request_doc)
self.assertEqual(rv['name1'][0]['data'], 'foo')
self.assertEqual(rv['name2'][0]['data'], 'bar')
def test_complex_input(self):
the_data = E.TheData("hello world")
request_doc = WPS.Execute(
OWS.Identifier('foo'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('name'),
WPS.Data(
WPS.ComplexData(the_data, mimeType='text/foobar')))))
rv = get_inputs_from_xml(request_doc)
self.assertEqual(rv['name'][0]['mimeType'], 'text/foobar')
rv_doc = etree.parse(StringIO(rv['name'][0]['data'])).getroot()
self.assertEqual(rv_doc.tag, 'TheData')
self.assertEqual(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.assertEqual(rv['json'][0]['mimeType'], 'application/json')
json_data = json.loads(rv['json'][0]['data'])
self.assertEqual(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.assertEqual(json_data['plot']['Version'], '0.1')
def test_bbox_input(self):
request_doc = WPS.Execute(
OWS.Identifier('request'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('bbox'),
WPS.Data(
WPS.BoundingBoxData(
OWS.LowerCorner('40 50'),
OWS.UpperCorner('60 70'))))))
rv = get_inputs_from_xml(request_doc)
bbox = rv['bbox'][0]
# assert isinstance(bbox, BoundingBox)
assert bbox['data'] == ['40', '50', '60', '70']
# assert bbox.minx == '40'
# assert bbox.miny == '50'
# assert bbox.maxx == '60'
# assert bbox.maxy == '70'
def test_reference_post_input(self):
request_doc = WPS.Execute(
OWS.Identifier('foo'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('name'),
WPS.Reference(
WPS.Body('request body'),
{'{http://www.w3.org/1999/xlink}href': 'http://foo/bar/service'},
method='POST'
)
)
)
)
rv = get_inputs_from_xml(request_doc)
self.assertEqual(rv['name'][0]['href'], 'http://foo/bar/service')
self.assertEqual(rv['name'][0]['method'], 'POST')
self.assertEqual(rv['name'][0]['body'], 'request body')
def test_reference_post_bodyreference_input(self):
request_doc = WPS.Execute(
OWS.Identifier('foo'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('name'),
WPS.Reference(
WPS.BodyReference(
{'{http://www.w3.org/1999/xlink}href': 'http://foo/bar/reference'}),
{'{http://www.w3.org/1999/xlink}href': 'http://foo/bar/service'},
method='POST'
)
)
)
)
rv = get_inputs_from_xml(request_doc)
self.assertEqual(rv['name'][0]['href'], 'http://foo/bar/service')
self.assertEqual(rv['name'][0]['bodyreference'], 'http://foo/bar/reference')
def test_build_input_file_name(self):
from pywps.inout.basic import ComplexInput
h = ComplexInput('ci')
h.workdir = workdir = tempfile.mkdtemp()
self.assertEqual(
h._build_file_name('http://path/to/test.txt'),
os.path.join(workdir, 'test.txt'))
self.assertEqual(
h._build_file_name('http://path/to/test'),
os.path.join(workdir, 'test'))
self.assertEqual(
h._build_file_name('file://path/to/.config'),
os.path.join(workdir, '.config'))
self.assertEqual(
h._build_file_name('https://path/to/test.txt?token=abc&expires_at=1234567'),
os.path.join(workdir, 'test.txt'))
h.supported_formats = [FORMATS.TEXT, ]
h.data_format = FORMATS.TEXT
self.assertEqual(
h._build_file_name('http://path/to/test'),
os.path.join(workdir, 'test.txt'))
open(os.path.join(workdir, 'duplicate.html'), 'a').close()
inpt_filename = h._build_file_name('http://path/to/duplicate.html')
self.assertTrue(inpt_filename.startswith(os.path.join(workdir, 'duplicate_')))
self.assertTrue(inpt_filename.endswith('.html'))
def load_tests(loader=None, tests=None, pattern=None):
if not loader:
loader = unittest.TestLoader()
suite_list = [
loader.loadTestsFromTestCase(ExecuteTest),
loader.loadTestsFromTestCase(ExecuteTranslationsTest),
loader.loadTestsFromTestCase(ExecuteXmlParserTest),
]
return unittest.TestSuite(suite_list)