-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcommon.py
51 lines (36 loc) · 1.5 KB
/
common.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
import os
from pywps import get_ElementMakerForVersion
from pywps.app.basic import get_xpath_ns
from pywps.tests import WpsClient, WpsTestResponse
TESTS_HOME = os.path.abspath(os.path.dirname(__file__))
CFG_FILE = os.path.join(TESTS_HOME, 'test.cfg')
VERSION = "1.0.0"
WPS, OWS = get_ElementMakerForVersion(VERSION)
xpath_ns = get_xpath_ns(VERSION)
def resource_file(filepath):
return os.path.join(TESTS_HOME, 'testdata', filepath)
class WpsTestClient(WpsClient):
def get(self, *args, **kwargs):
query = "?"
for key, value in kwargs.items():
query += u"{0}={1}&".format(key, value)
return super(WpsTestClient, self).get(query)
def client_for(service):
return WpsTestClient(service, WpsTestResponse)
def get_output(doc):
"""Copied from pywps/tests/test_execute.py.
TODO: make this helper method public in pywps."""
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:
output[identifier_el.text] = data_el[0].text
return output