diff --git a/onfido/resources/workflow_runs.py b/onfido/resources/workflow_runs.py index d4bc252..ed20d1f 100644 --- a/onfido/resources/workflow_runs.py +++ b/onfido/resources/workflow_runs.py @@ -2,5 +2,16 @@ class WorkflowRuns(Resource): + def create(self, request_body: dict): + return self._post("workflow_runs/", **request_body) + + def all(self, **user_payload: dict): + payload = {"page": 1, "sort": "desc"} + payload.update(user_payload) + return self._get("workflow_runs", payload=payload) + + def find(self, workflow_run_id: str): + return self._get(f"workflow_runs/{workflow_run_id}") + def evidence(self, workflow_run_id: str): return self._download_request(f"workflow_runs/{workflow_run_id}/signed_evidence_file") diff --git a/onfido/resources_aio/workflow_runs.py b/onfido/resources_aio/workflow_runs.py index dbecacc..dafc87c 100644 --- a/onfido/resources_aio/workflow_runs.py +++ b/onfido/resources_aio/workflow_runs.py @@ -2,5 +2,16 @@ class WorkflowRuns(Resource): + def create(self, request_body: dict): + return self._post("workflow_runs/", **request_body) + + def all(self, **user_payload: dict): + payload = {"page": 1, "sort": "desc"} + payload.update(user_payload) + return self._get("workflow_runs", payload=payload) + + def find(self, workflow_run_id: str): + return self._get(f"workflow_runs/{workflow_run_id}") + def evidence(self, workflow_run_id: str): return self._download_request(f"workflow_runs/{workflow_run_id}/signed_evidence_file") diff --git a/tests/test_workflow_runs.py b/tests/test_workflow_runs.py index f6973e1..03591eb 100644 --- a/tests/test_workflow_runs.py +++ b/tests/test_workflow_runs.py @@ -1,11 +1,53 @@ import onfido from onfido.regions import Region - +from urllib.parse import urlparse, parse_qs api = onfido.Api("", region=Region.EU) +workflow_run_details = { + "applicant_id": "12345", + "completed_redirect_url": "https://", + "expired_redirect_url": "https://", + "expires_at": "2023-11-17T16:39:04Z", + "language": "en_US" +} + fake_uuid = "58a9c6d2-8661-4dbd-96dc-b9b9d344a7ce" +def test_create_workflow_run(requests_mock): + mock_create = requests_mock.post("https://api.eu.onfido.com/v3.6/workflow_runs/", json=[]) + api.workflowrun.create(workflow_run_details) + assert mock_create.called is True + +def test_list_workflow_runs(requests_mock): + mock_list = requests_mock.get("https://api.eu.onfido.com/v3.6/workflow_runs", json=[]) + api.workflowrun.all( + page=2, + status="approved,declined", + tags="dummy_tag1,dummy_tag2", + created_at_gt="2023-11-17T16:39:04Z", + created_at_lt="2008-02-29T02:56:37Z", + sort='asc' + ) + history = mock_list.request_history + assert mock_list.called is True + assert history[0].method == 'GET' + query_params = urlparse(history[0].url).query + assert history[0].url == "https://api.eu.onfido.com/v3.6/workflow_runs?" + query_params + assert parse_qs(query_params) == { + "page": ['2'], + "status": ["approved,declined"], + "tags": ["dummy_tag1,dummy_tag2"], + "created_at_gt": ["2023-11-17T16:39:04Z"], + "created_at_lt": ["2008-02-29T02:56:37Z"], + "sort": ['asc'] + } + +def test_find_workflow_run(requests_mock): + mock_find = requests_mock.get(f"https://api.eu.onfido.com/v3.6/workflow_runs/{fake_uuid}", json=[]) + api.workflowrun.find(fake_uuid) + assert mock_find.called is True + def test_evidence_workflowrun(requests_mock): mock_download = requests_mock.get(f"https://api.eu.onfido.com/v3.6/workflow_runs/{fake_uuid}/signed_evidence_file", text="FAKE PDF BINARY", headers={"Content-type": "application/pdf"}) onfido_download = api.workflowrun.evidence(fake_uuid)