From 53ba8ac8910cba430d874066fc7986e7cae6a125 Mon Sep 17 00:00:00 2001 From: David Huard Date: Fri, 16 Sep 2022 19:09:55 -0400 Subject: [PATCH] Move Sleep process definition from tests/test_assync.py to tests/processes/__init__.py where other test processes are to facilitate reuse. --- tests/processes/__init__.py | 35 +++++++++++++++++++++++++++++++++++ tests/test_assync.py | 30 ++---------------------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/tests/processes/__init__.py b/tests/processes/__init__.py index 0b847ace4..5882a9ef1 100644 --- a/tests/processes/__init__.py +++ b/tests/processes/__init__.py @@ -99,3 +99,38 @@ def bbox(request, response): area = request.inputs['area'][0].data response.outputs['extent'].data = area return response + + +class Sleep(Process): + """A long running process, just sleeping.""" + def __init__(self): + inputs = [ + LiteralInput('seconds', title='Seconds', data_type='float') + ] + outputs = [ + LiteralOutput('finished', title='Finished', data_type='boolean') + ] + + super(Sleep, self).__init__( + self._handler, + identifier='sleep', + title='Sleep', + abstract='Wait for specified number of seconds.', + inputs=inputs, + outputs=outputs, + store_supported=True, + status_supported=True + ) + + @staticmethod + def _handler(request, response): + import time + + seconds = request.inputs['seconds'][0].data + step = seconds / 3 + for i in range(3): + response.update_status('Sleep in progress...', i / 3 * 100) + time.sleep(step) + + response.outputs['finished'].data = "True" + return response diff --git a/tests/test_assync.py b/tests/test_assync.py index 2db2eb074..1e267601c 100644 --- a/tests/test_assync.py +++ b/tests/test_assync.py @@ -8,43 +8,17 @@ from pywps import Service, Process, LiteralInput, LiteralOutput from pywps import get_ElementMakerForVersion from pywps.tests import client_for, assert_response_accepted +from .processes import Sleep VERSION = "1.0.0" WPS, OWS = get_ElementMakerForVersion(VERSION) -def create_sleep(): - - def sleep(request, response): - seconds = request.inputs['seconds'][0].data - assert isinstance(seconds, float) - - step = seconds / 3 - for i in range(3): - # How is status working in version 4 ? - #self.status.set("Waiting...", i * 10) - time.sleep(step) - - response.outputs['finished'].data = "True" - return response - - return Process(handler=sleep, - identifier='sleep', - title='Sleep', - inputs=[ - LiteralInput('seconds', title='Seconds', data_type='float') - ], - outputs=[ - LiteralOutput('finished', title='Finished', data_type='boolean') - ] - ) - - class ExecuteTest(unittest.TestCase): def test_assync(self): - client = client_for(Service(processes=[create_sleep()])) + client = client_for(Service(processes=[Sleep()])) request_doc = WPS.Execute( OWS.Identifier('sleep'), WPS.DataInputs(