diff --git a/tests/conftest.py b/tests/conftest.py index a5b8587..e1a34ee 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -136,6 +136,24 @@ def repeat_request_until_status_changes( return instance +def repeat_request_until_task_output_changes( + function, params, max_retries=10, sleep_time=1 +): + instance = function(*params) + + iteration = 0 + while instance.output == None: + if iteration > max_retries: + pytest.fail("Task output did not change in time") + + iteration += 1 + sleep(sleep_time) + + instance = function(*params) + + return instance + + def repeat_request_until_http_code_changes( function, params, max_retries=10, sleep_time=1 ): diff --git a/tests/test_qualified_electronic_signatures.py b/tests/test_qualified_electronic_signatures.py index b952632..44d9c85 100644 --- a/tests/test_qualified_electronic_signatures.py +++ b/tests/test_qualified_electronic_signatures.py @@ -5,6 +5,7 @@ from tests.conftest import ( create_applicant, create_workflow_run, + repeat_request_until_task_output_changes, ) @@ -40,11 +41,12 @@ def workflow_run(onfido_api, applicant_id, workflow_id): @pytest.fixture(scope="function") def file_id(onfido_api, workflow_run): - import time - time.sleep(2) + task = onfido_api.list_tasks(workflow_run.id)[0] - output = onfido_api.find_task(workflow_run.id, task.id).output + output = repeat_request_until_task_output_changes( + onfido_api.find_task, [workflow_run.id, task.id], max_retries=10, sleep_time=3 + ).output return output["properties"]["signed_documents"][0]["id"]