Skip to content

Commit

Permalink
Added Translation process. Configured language not recognized (#102)
Browse files Browse the repository at this point in the history
* added Translation process for fr-CA and de-DE
  • Loading branch information
huard authored Apr 21, 2020
1 parent ec7160c commit dea910c
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 2 deletions.
1 change: 1 addition & 0 deletions emu/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ allowedinputpaths = /
maxsingleinputsize = 200mb
maxprocesses = 10
parallelprocesses = 2
language = en-US,fr-CA,de-DE

[logging]
level = INFO
Expand Down
2 changes: 2 additions & 0 deletions emu/processes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .wps_ncmeta import NCMeta
from .wps_nonpyid import NonPyID
from .wps_dry_run import SimpleDryRun
from .wps_translation import Translation

processes = [
UltimateQuestion(),
Expand All @@ -36,4 +37,5 @@
NCMeta(),
NonPyID(),
SimpleDryRun(),
Translation(),
]
58 changes: 58 additions & 0 deletions emu/processes/wps_translation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
Translation process to check WPS translations
"""
from pywps import Process, LiteralInput, LiteralOutput

import logging
LOGGER = logging.getLogger("PYWPS")


class Translation(Process):
def __init__(self):
inputs = [
LiteralInput('input1', 'Input1 number',
default='100', data_type='integer',
translations={
"fr-CA": {"title": "Entrée #1", "abstract": "Entier #1"},
"de-DE": {"title": "Eingabe #1", "abstract": "Eingabe #1"},
}),
]
outputs = [
LiteralOutput('output1', 'Output1 add 1 result',
data_type='string',
translations={
"fr-CA": {"title": "Sortie #1", "abstract": "Chaîne de charactères"},
"de-DE": {"title": "Ausgabe #1", "abstract": "Ergebnis"}
}),
]

super(Translation, self).__init__(
self._handler,
identifier='translation',
title="Translated process",
abstract="Process including translations in other languages.",
version="1.0",
inputs=inputs,
outputs=outputs,
store_supported=True,
status_supported=True,
keywords=["languages"],
translations={
"fr-CA": {"title": "Processus traduit",
"abstract": "Processus incluant des traductions",
"keywords": ["langues"]},
"de-DE": {"title": "Mehrsprachiger Prozess",
"abstract": "Prozess mit mehreren Sprachen.",
"keywords": ["sprachen"]}
}
)

@staticmethod
def _handler(request, response):
response.update_status('PyWPS Process started.', 0)

LOGGER.debug("input1 %s", request.inputs['input1'][0].data)
response.outputs['output1'].data = request.inputs['input1'][0].data + 1

response.update_status('PyWPS Process completed.', 100)
return response
2 changes: 2 additions & 0 deletions emu/templates/pywps.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ outputpath= {{ wps_outputpath }}
{% if wps_workdir %}
workdir={{ wps_workdir }}
{% endif %}
languages = en-US,fr-CA,de-DE


[logging]
level = {{ wps_log_level|default('INFO') }}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pywps>=4.2.0<4.3
pywps>=4.2.4<4.3
jinja2
click
psutil
Expand Down
1 change: 1 addition & 0 deletions tests/test.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[server]
allowedinputpaths=/
language = en-US,fr-CA,de-DE
15 changes: 14 additions & 1 deletion tests/test_wps_caps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def test_wps_caps():
client = client_for(Service(processes=processes))
resp = client.get(service='wps', request='getcapabilities', version='1.0.0')
resp = client.get(service='wps', request='getcapabilities', version='1.0.0', language='en-US')
names = resp.xpath_text('/wps:Capabilities'
'/wps:ProcessOfferings'
'/wps:Process'
Expand All @@ -29,6 +29,19 @@ def test_wps_caps():
'show_error',
'simple_dry_run',
'sleep',
'translation',
'ultimate_question',
'wordcounter',
]

# caps language
assert resp.xpath('/wps:Capabilities/@xml:lang')[0] == "en-US"

# supported languages
languages = resp.xpath_text('/wps:Capabilities'
'/wps:Languages'
'/wps:Supported'
'/ows:Language')
assert 'en-US' in languages
assert 'fr-CA' in languages
assert 'de-DE' in languages
50 changes: 50 additions & 0 deletions tests/test_wps_translation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from pywps import Service
from pywps.tests import assert_response_success

from .common import client_for
from emu.processes.wps_translation import Translation


def test_wps_translation_describe_fr():
client = client_for(Service(processes=[Translation()]))
resp = client.get(
service='wps', request='DescribeProcess', version='1.0.0',
identifier='translation',
language="fr-CA")
print(resp.data)
title = resp.xpath_text(
'/wps:ProcessDescriptions'
'/ProcessDescription'
'/ows:Title'
)
assert title == 'Processus traduit'


def test_wps_translation_describe_de():
client = client_for(Service(processes=[Translation()]))
resp = client.get(
service='wps', request='DescribeProcess', version='1.0.0',
identifier='translation',
language="de-DE")
print(resp.data)
title = resp.xpath_text(
'/wps:ProcessDescriptions'
'/ProcessDescription'
'/ows:Title'
)
assert title == 'Mehrsprachiger Prozess'


def test_wps_translation_execute():
client = client_for(Service(processes=[Translation()]))
datainputs = "input1=10"
resp = client.get(
service='wps', request='execute', version='1.0.0',
identifier='translation',
datainputs=datainputs,
language="fr-CA")
print(resp.data)
assert_response_success(resp)

outputs = list(resp.xpath('/wps:ExecuteResponse/wps:ProcessOutputs/wps:Output')[0])
assert outputs[1].text == "Sortie #1"

0 comments on commit dea910c

Please sign in to comment.