Skip to content

Commit

Permalink
wordcounter output is now valid json. added test example with raw b64… (
Browse files Browse the repository at this point in the history
#74)

* wordcounter output is now valid json. added test example with raw b64 content

* fixed py2-3 issues. commented raw test for ncmeta
  • Loading branch information
huard authored and cehbrecht committed Dec 19, 2018
1 parent ca81836 commit d61615f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
8 changes: 4 additions & 4 deletions emu/processes/wps_wordcounter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import json
import re

from collections import Counter

from pywps import Process
Expand Down Expand Up @@ -55,9 +56,8 @@ def words(f):
counts = Counter(words(request.inputs['text'][0].stream))
sorted_counts = sorted([(v, k) for (k, v) in counts.items()],
reverse=True)
with open(os.path.join(self.workdir, 'out.txt'), 'w') as fout:
fout.write(str(sorted_counts))
response.outputs['output'].file = fout.name

response.outputs['output'].data = json.dumps(sorted_counts)

response.update_status('PyWPS Process completed.', 100)
return response
35 changes: 35 additions & 0 deletions tests/test_wps_ncmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from .common import client_for, resource_file
from emu.processes.wps_ncmeta import NCMeta
import owslib.wps

OPENDAP_URL = 'http://test.opendap.org:80/opendap/netcdf/examples/sresa1b_ncar_ccsm3_0_run1_200001.nc'
NC_URL = 'http://test.opendap.org:80/opendap/netcdf/examples/sresa1b_ncar_ccsm3_0_run1_200001.nc.nc4'
Expand Down Expand Up @@ -41,3 +42,37 @@ def test_wps_ncmeta_file():
identifier='ncmeta',
datainputs=datainputs)
assert_response_success(resp)


"""
def test_wps_ncmeta_file_raw():
import six
import base64
from pywps import E, get_ElementMakerForVersion
VERSION = "1.0.0"
WPS, OWS = get_ElementMakerForVersion(VERSION)
client = client_for(Service(processes=[NCMeta()]))
mode = 'r' if six.PY2 else 'rb'
with open(resource_file('test.nc'), mode) as f:
data = base64.b64encode(f.read())
request_doc = WPS.Execute(
OWS.Identifier('ncmeta'),
WPS.DataInputs(
WPS.Input(
OWS.Identifier('dataset'),
WPS.Data(
WPS.ComplexData(str(data), encoding='base64',
mimeType='application/x-netcdf')
)
),
), version='1.0.0'
)
resp = client.post_xml(doc=request_doc)
assert_response_success(resp)
"""
12 changes: 8 additions & 4 deletions tests/test_wps_wordcounter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest

import json
from pywps import Service
from pywps.tests import assert_response_success

from .common import client_for, resource_file
from .common import client_for, resource_file, get_output
from emu.processes.wps_wordcounter import WordCounter


Expand All @@ -26,5 +26,9 @@ def test_wps_wordcount_href():
resp = client.get(
service='wps', request='execute', version='1.0.0',
identifier='wordcounter',
datainputs=datainputs)
assert_response_success(resp)
datainputs=datainputs,
rawdataoutput='output=@mimetype=application/json'
)

assert resp.status_code == 200
json.loads(resp.data)

0 comments on commit d61615f

Please sign in to comment.