From 517d6947ca47627c404c43196c0d4bf743916521 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 28 2018 07:52:31 +0000 Subject: Add support in the tests for task returning to a POST query Cf pagure.utils.wait_for_task_post Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/__init__.py b/tests/__init__.py index 99f8240..f93407e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ - (c) 2015-2017 - Copyright Red Hat Inc + (c) 2015-2018 - Copyright Red Hat Inc Authors: Pierre-Yves Chibon @@ -102,10 +102,41 @@ def get_wait_target(html): return found[-1] +POST_REGEX = re.compile("""
') +def get_post_args(html): + """ This parses from the wait page the hidden arguments for the form. """ + found = INPUT_REGEX.findall(html) + if len(found) == 0: + raise Exception("Not able to get the POST arguments in %s" % html) + output = {} + for key, val in found: + output[key] = val + return output + + def create_maybe_waiter(method, getter): def maybe_waiter(*args, **kwargs): """ A wrapper for self.app.get()/.post() that will resolve wait's """ result = method(*args, **kwargs) + + # Handle the POST wait case + form_url = None + form_args = None + if 'id="waitform"' in result.data: + form_url = get_post_target(result.data) + form_args = get_post_args(result.data) + form_args['csrf_token'] = result.data.split( + 'name="csrf_token" type="hidden" value="')[1].split('">')[0] + count = 0 while 'We are waiting for your task to finish.' in result.data: # Resolve wait page @@ -118,6 +149,8 @@ def create_maybe_waiter(method, getter): if count > 50: raise Exception('Had to wait too long') else: + if form_url and form_args: + return method(form_url, data=form_args, follow_redirects=True) return result return maybe_waiter