Skip to content

Commit 3502572

Browse files
authored
Fixed tests with complexinput, update of #45. (#48)
1 parent 482a9fa commit 3502572

File tree

10 files changed

+2505
-39
lines changed

10 files changed

+2505
-39
lines changed

emu/processes/wps_poly_centroid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self):
1717
supported_formats=[FORMATS.GML, ]),
1818
]
1919
outputs = [
20-
LiteralOutput('centroid', 'The centroid of the polygon geometry.',
20+
LiteralOutput('output', 'The centroid of the polygon geometry.',
2121
abstract="The coordinates of the polygon's approximate centroid.",)
2222
]
2323

@@ -56,5 +56,5 @@ def _handler(request, response):
5656
cx = sum(x) / n
5757
cy = sum(y) / n
5858

59-
response.outputs['centroid'].data = '{},{}'.format(cx, cy)
59+
response.outputs['output'].data = '{:.5f},{:.5f}'.format(cx, cy)
6060
return response

emu/processes/wps_wordcounter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _handler(request, response):
4949

5050
def words(f):
5151
for line in f:
52-
for word in wordre.findall(line):
52+
for word in wordre.findall(line.decode('UTF-8')):
5353
yield word
5454

5555
counts = Counter(words(request.inputs['text'][0].stream))

tests/common.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
import os
2+
from pywps import get_ElementMakerForVersion
3+
from pywps.app.basic import get_xpath_ns
14
from pywps.tests import WpsClient, WpsTestResponse
25

6+
TESTS_HOME = os.path.abspath(os.path.dirname(__file__))
7+
8+
VERSION = "1.0.0"
9+
WPS, OWS = get_ElementMakerForVersion(VERSION)
10+
xpath_ns = get_xpath_ns(VERSION)
11+
12+
13+
def resource_file(filepath):
14+
return os.path.join(TESTS_HOME, 'testdata', filepath)
15+
316

417
class WpsTestClient(WpsClient):
518

@@ -12,3 +25,15 @@ def get(self, *args, **kwargs):
1225

1326
def client_for(service):
1427
return WpsTestClient(service, WpsTestResponse)
28+
29+
30+
def get_output(doc):
31+
"""Copied from pywps/tests/test_execute.py.
32+
TODO: make this helper method public in pywps."""
33+
output = {}
34+
for output_el in xpath_ns(doc, '/wps:ExecuteResponse'
35+
'/wps:ProcessOutputs/wps:Output'):
36+
[identifier_el] = xpath_ns(output_el, './ows:Identifier')
37+
[value_el] = xpath_ns(output_el, './wps:Data/wps:LiteralData')
38+
output[identifier_el.text] = value_el.text
39+
return output

tests/test_wps_dummy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pywps import Service
22
from pywps.tests import assert_response_success
33

4-
from .common import client_for
4+
from .common import client_for, get_output
55
from emu.processes.wps_dummy import Dummy
66

77

@@ -13,3 +13,4 @@ def test_wps_dummy():
1313
identifier='dummyprocess',
1414
datainputs=datainputs)
1515
assert_response_success(resp)
16+
assert get_output(resp.xml) == {'output1': '11', 'output2': '1'}

tests/test_wps_hello.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,17 @@
11
import pytest
22

33
from pywps import Service
4-
from pywps.tests import assert_response_success
4+
from pywps.tests import client_for, assert_response_success
55

6-
from .common import client_for
6+
from .common import get_output
77
from emu.processes.wps_say_hello import SayHello
88

99

1010
def test_wps_hello():
1111
client = client_for(Service(processes=[SayHello()]))
1212
datainputs = "name=LovelySugarBird"
1313
resp = client.get(
14-
service='WPS', request='Execute', version='1.0.0', identifier='hello',
15-
datainputs=datainputs)
14+
"?service=WPS&request=Execute&version=1.0.0&identifier=hello&datainputs={}".format(
15+
datainputs))
1616
assert_response_success(resp)
17-
18-
19-
@pytest.mark.skip(reason="build_request_response method not available anymore")
20-
def test_wps_hello_again():
21-
"""Example of how to debug this process, running outside a PyWPS instance.
22-
"""
23-
hello = SayHello()
24-
(request, response) = hello.build_request_response()
25-
literal_in = hello.inputs[0]
26-
literal_in.data = 'Alice'
27-
request.inputs["name"].append(literal_in)
28-
hello._handler(request, response)
29-
30-
assert response.outputs["output"].data == 'Hello Alice'
31-
print("All good!")
17+
assert get_output(resp.xml) == {'output': "Hello LovelySugarBird"}

tests/test_wps_poly_centroid.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
1-
import pytest
21
import os
2+
import requests
33
from pywps import Service
44
from pywps.tests import assert_response_success
55

6-
from .common import client_for
7-
import emu
6+
from .common import client_for, resource_file, TESTS_HOME, WPS, OWS, get_output
87
from emu.processes.wps_poly_centroid import PolyCentroid
9-
from eggshell.config import Paths
108

11-
paths = Paths(emu)
12-
TESTS_HOME = os.path.abspath(os.path.dirname(__file__))
139
cfgfiles = os.path.join(TESTS_HOME, 'test.cfg')
1410

1511

16-
def test_wps_poly_centroid():
12+
def test_wps_poly_centroid_get():
1713
client = client_for(Service(processes=[PolyCentroid(), ], cfgfiles=cfgfiles))
18-
fn = os.path.join(TESTS_HOME, 'testdata', 'poly.xml')
19-
datainputs = "polygon=files@xlink:href=file://{0}".format(fn)
14+
datainputs = "polygon=@xlink:href=file://{0}".format(resource_file('poly.xml'))
2015
resp = client.get(
2116
service='WPS', request='Execute', version='1.0.0',
2217
identifier='poly_centroid',
2318
datainputs=datainputs)
2419
assert_response_success(resp)
20+
assert get_output(resp.xml) == {'output': "119.59740,-13.57388"}
21+
22+
23+
def test_wps_poly_centroid_post():
24+
client = client_for(Service(processes=[PolyCentroid(), ], cfgfiles=cfgfiles))
25+
request_doc = WPS.Execute(
26+
OWS.Identifier('poly_centroid'),
27+
WPS.DataInputs(
28+
WPS.Input(
29+
OWS.Identifier('polygon'),
30+
WPS.Data(WPS.ComplexData(open(resource_file('poly.xml'), 'r').read()))
31+
)
32+
),
33+
version='1.0.0'
34+
)
35+
resp = client.post_xml(doc=request_doc)
36+
assert_response_success(resp)
37+
assert get_output(resp.xml) == {'output': "119.59740,-13.57388"}

tests/test_wps_wordcounter.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import pytest
2-
31
from pywps import Service
42
from pywps.tests import assert_response_success
53

6-
from .common import client_for
4+
from .common import client_for, resource_file
75
from emu.processes.wps_wordcounter import WordCounter
86

97

10-
@pytest.mark.online
118
def test_wps_wordcount():
129
client = client_for(Service(processes=[WordCounter()]))
13-
datainputs = "text={0}".format(
14-
"https://en.wikipedia.org/wiki/Web_Processing_Service")
10+
datainputs = "text=@xlink:href=file://{0}".format(
11+
resource_file('alice-in-wonderland.txt'))
1512
resp = client.get(
1613
service='wps', request='execute', version='1.0.0',
1714
identifier='wordcounter',

0 commit comments

Comments
 (0)