From b0b449b2e253d899656100d65a6bc71571bf50dc Mon Sep 17 00:00:00 2001 From: Pingu Carsti Date: Fri, 18 May 2018 14:53:17 +0200 Subject: [PATCH] Added sleep process (#3) and fixed tests imports (#17) --- .../tests/test_wps_caps.py | 1 + .../tests/test_wps_inout.py | 2 +- .../tests/test_wps_sleep.py | 18 +++++++ .../tests/test_wps_wordcounter.py | 2 +- .../processes/__init__.py | 2 + .../processes/wps_sleep.py | 51 +++++++++++++++++++ 6 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 {{cookiecutter.project_slug}}/tests/test_wps_sleep.py create mode 100644 {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/processes/wps_sleep.py diff --git a/{{cookiecutter.project_slug}}/tests/test_wps_caps.py b/{{cookiecutter.project_slug}}/tests/test_wps_caps.py index a70820ea7..bf52f9dc6 100644 --- a/{{cookiecutter.project_slug}}/tests/test_wps_caps.py +++ b/{{cookiecutter.project_slug}}/tests/test_wps_caps.py @@ -14,4 +14,5 @@ def test_wps_caps(): '/ows:Identifier') assert sorted(names.split()) == [ 'inout', + 'sleep', 'wordcounter'] diff --git a/{{cookiecutter.project_slug}}/tests/test_wps_inout.py b/{{cookiecutter.project_slug}}/tests/test_wps_inout.py index c18756641..83ea4008b 100644 --- a/{{cookiecutter.project_slug}}/tests/test_wps_inout.py +++ b/{{cookiecutter.project_slug}}/tests/test_wps_inout.py @@ -3,7 +3,7 @@ from pywps import Service from pywps.tests import assert_response_success -from {{ cookiecutter.project_slug }}.tests.common import client_for +from . common import client_for from {{ cookiecutter.project_slug }}.processes.wps_inout import InOut diff --git a/{{cookiecutter.project_slug}}/tests/test_wps_sleep.py b/{{cookiecutter.project_slug}}/tests/test_wps_sleep.py new file mode 100644 index 000000000..161d0e3f5 --- /dev/null +++ b/{{cookiecutter.project_slug}}/tests/test_wps_sleep.py @@ -0,0 +1,18 @@ +import pytest + +from pywps import Service +from pywps.tests import assert_response_success + +from . common import client_for +from {{ cookiecutter.project_slug }}.processes.wps_sleep import Sleep + + +@pytest.mark.slow +def test_wps_sleep(): + client = client_for(Service(processes=[Sleep()])) + datainputs = "deplay=1" + resp = client.get( + service='WPS', request='Execute', version='1.0.0', identifier='sleep', + datainputs=datainputs) + print resp.data + assert_response_success(resp) diff --git a/{{cookiecutter.project_slug}}/tests/test_wps_wordcounter.py b/{{cookiecutter.project_slug}}/tests/test_wps_wordcounter.py index 922fa0299..b811759c4 100644 --- a/{{cookiecutter.project_slug}}/tests/test_wps_wordcounter.py +++ b/{{cookiecutter.project_slug}}/tests/test_wps_wordcounter.py @@ -3,7 +3,7 @@ from pywps import Service from pywps.tests import assert_response_success -from {{ cookiecutter.project_slug }}.tests.common import client_for +from . common import client_for from {{ cookiecutter.project_slug }}.processes.wps_wordcounter import WordCounter diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/processes/__init__.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/processes/__init__.py index 143b5fff0..4a54baee1 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/processes/__init__.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/processes/__init__.py @@ -1,7 +1,9 @@ from .wps_wordcounter import WordCounter from .wps_inout import InOut +from .wps_sleep import Sleep processes = [ WordCounter(), InOut(), + Sleep(), ] diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/processes/wps_sleep.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/processes/wps_sleep.py new file mode 100644 index 000000000..eea134ff4 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/processes/wps_sleep.py @@ -0,0 +1,51 @@ +from pywps import Process, LiteralInput, LiteralOutput +from pywps.app.Common import Metadata + + +class Sleep(Process): + def __init__(self): + inputs = [ + LiteralInput('delay', 'Delay between every update', + default='10', data_type='float') + ] + outputs = [ + LiteralOutput('sleep_output', 'Sleep Output', data_type='string') + ] + + super(Sleep, self).__init__( + self._handler, + identifier='sleep', + version='1.0', + title='Sleep Process', + abstract='Testing a long running process, in the sleep.' + 'This process will sleep for a given delay or 10 seconds if not a valid value.', + profile='', + metadata=[ + Metadata('PyWPS Demo', 'https://pywps-demo.readthedocs.io/en/latest/'), + ], + inputs=inputs, + outputs=outputs, + store_supported=True, + status_supported=True + ) + + def _handler(self, request, response): + import time + + if 'delay' in request.inputs: + sleep_delay = request.inputs['delay'][0].data + else: + sleep_delay = 10 + + time.sleep(sleep_delay) + response.update_status('PyWPS Process started. Waiting...', 20) + time.sleep(sleep_delay) + response.update_status('PyWPS Process started. Waiting...', 40) + time.sleep(sleep_delay) + response.update_status('PyWPS Process started. Waiting...', 60) + time.sleep(sleep_delay) + response.update_status('PyWPS Process started. Waiting...', 80) + time.sleep(sleep_delay) + response.outputs['sleep_output'].data = 'done sleeping' + + return response