Skip to content

Commit 1add32c

Browse files
committed
Add schedule to CI, fix and improve tests after library refresh
1 parent 640198f commit 1add32c

9 files changed

+120
-54
lines changed

.github/workflows/python.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ on:
1616
release:
1717
types:
1818
- published
19+
schedule:
20+
- cron: "0 14 * * 0" # Every Sunday, 2 hours after midday
1921

2022
jobs:
2123
integration-tests:

tests/conftest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def create_applicant(onfido_api, applicant_builder=None):
6060
def upload_document(onfido_api, applicant_id):
6161
return onfido_api.upload_document(
6262
applicant_id=applicant_id,
63-
type="passport",
63+
type=onfido.DocumentTypes.PASSPORT,
6464
side="front",
6565
file="tests/media/sample_driving_licence.png",
6666
)
@@ -93,6 +93,7 @@ def create_check(
9393
applicant_id=applicant_id,
9494
document_ids=document_ids,
9595
report_names=report_names,
96+
privacy_notices_read_consent_given=True,
9697
)
9798
)
9899

@@ -142,13 +143,13 @@ def repeat_request_until_task_output_changes(
142143
instance = function(*params)
143144

144145
iteration = 0
145-
while instance.output == None:
146+
while instance.output is None:
146147
if iteration > max_retries:
147148
pytest.fail("Task output did not change in time")
148149

149150
iteration += 1
150151
sleep(sleep_time)
151-
152+
152153
instance = function(*params)
153154

154155
return instance

tests/test_applicants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def test_create_applicant(onfido_api):
2626
country=onfido.CountryCodes.FRA,
2727
line1="My wonderful address",
2828
),
29+
consents=[
30+
onfido.ApplicantConsentBuilder(
31+
name=onfido.ApplicantConsentName.PRIVACY_NOTICES_READ,
32+
granted=True
33+
)
34+
]
2935
)
3036

3137
applicant = create_applicant(onfido_api, applicant_builder)

tests/test_checks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from onfido import Check, ChecksList, ReportName, CheckBuilder, UsDrivingLicenceBuilder
2+
from onfido import (Check, ChecksList, ReportName, CheckBuilder,
3+
UsDrivingLicenceBuilder, CheckStatus)
34
from tests.conftest import create_applicant, create_check, upload_document
45

56

@@ -28,7 +29,7 @@ def test_create_check(check, applicant_id):
2829
assert isinstance(check, Check)
2930
assert check.applicant_id == applicant_id
3031
assert len(check.report_ids) == 2
31-
assert check.status == "in_progress"
32+
assert check.status == CheckStatus.IN_PROGRESS
3233

3334

3435
def test_create_consider_check(onfido_api, applicant_id, document_id):

tests/test_documents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from onfido import ApiException, Document, DocumentsList
3+
from onfido import ApiException, Document, DocumentsList, DocumentTypes
44
from tests.conftest import create_applicant, upload_document
55

66

@@ -17,7 +17,7 @@ def document(onfido_api, applicant_id):
1717
def test_create_document(applicant_id, document):
1818
assert document is not None
1919
assert document.applicant_id == applicant_id
20-
assert document.type == "passport"
20+
assert document.type == DocumentTypes.PASSPORT
2121
assert document.side == "front"
2222
assert isinstance(document, Document)
2323

tests/test_qualified_electronic_signatures.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def workflow_run(onfido_api, applicant_id, workflow_id):
4141

4242
@pytest.fixture(scope="function")
4343
def file_id(onfido_api, workflow_run):
44-
45-
task = onfido_api.list_tasks(workflow_run.id)[0]
44+
task = onfido_api.list_tasks(workflow_run.id)[1]
4645

4746
output = repeat_request_until_task_output_changes(
4847
onfido_api.find_task, [workflow_run.id, task.id], max_retries=10, sleep_time=3
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
from onfido.webhook_event_verifier import (
2+
WebhookEventVerifier, OnfidoInvalidSignatureError
3+
)
4+
from onfido import (
5+
WebhookEvent, WebhookEventPayload, WebhookEventPayloadObject,
6+
WebhookEventResourceType, WebhookEventType, WebhookEventObjectStatus,
7+
WebhookEventPayloadResource
8+
)
9+
10+
import pytest
11+
12+
classic_raw_event = ("{\"payload\":{\"resource_type\":\"check\",\"action\":\"check.completed\","
13+
"\"object\":{\"id\":\"f2302f45-227d-413d-ad61-09ec077a086a\",\"status\":\"complete\","
14+
"\"completed_at_iso8601\":\"2024-04-04T09:21:21Z\","
15+
"\"href\":\"https://api.onfido.com/v3.6/checks/f2302f45-227d-413d-ad61-09ec077a086a\"}}}")
16+
17+
studio_raw_event = ("{\"payload\":{\"resource_type\":\"workflow_task\",\"action\":\"workflow_task.started\","
18+
"\"object\":{\"id\":\"profile_1eb92\",\"task_spec_id\":\"profile_1eb92\","
19+
"\"task_def_id\":\"profile_data\",\"workflow_run_id\":\"bc77c6e5-753a-4580-96a6-aaed3e5a8d19\""
20+
",\"status\":\"started\",\"started_at_iso8601\":\"2024-07-10T12:49:09Z\","
21+
"\"href\":\"https://api.eu.onfido.com/v3.6/workflow_runs/"
22+
"bc77c6e5-753a-4580-96a6-aaed3e5a8d19/tasks/profile_1eb92\"},"
23+
"\"resource\":{\"created_at\":\"2024-07-10T12:49:09Z\",\"id\":""\"profile_1eb92\","
24+
"\"workflow_run_id\":\"bc77c6e5-753a-4580-96a6-aaed3e5a8d19\",\"updated_at\":\"2024-07-10T12:49:09Z\""
25+
",\"input\":{},\"task_def_version\":null,\"task_def_id\":\"profile_data\",\"output\":null}}}")
26+
27+
classic_expected_event = WebhookEvent(
28+
payload=WebhookEventPayload(
29+
action=WebhookEventType.CHECK_DOT_COMPLETED,
30+
resource_type=WebhookEventResourceType.CHECK,
31+
object=WebhookEventPayloadObject(
32+
id='f2302f45-227d-413d-ad61-09ec077a086a',
33+
href='https://api.onfido.com/v3.6/checks/f2302f45-227d-413d-ad61-09ec077a086a',
34+
status=WebhookEventObjectStatus.COMPLETE,
35+
completed_at_iso8601='2024-04-04T09:21:21Z'
36+
)
37+
)
38+
)
39+
40+
studio_expected_event = WebhookEvent(
41+
payload=WebhookEventPayload(
42+
action=WebhookEventType.WORKFLOW_TASK_DOT_STARTED,
43+
resource_type=WebhookEventResourceType.WORKFLOW_TASK,
44+
object=WebhookEventPayloadObject(
45+
id='profile_1eb92',
46+
href='https://api.eu.onfido.com/v3.6/workflow_runs/bc77c6e5-753a-4580-96a6-aaed3e5a8d19/tasks/profile_1eb92',
47+
status=WebhookEventObjectStatus.STARTED,
48+
started_at_iso8601='2024-07-10T12:49:09Z',
49+
task_def_id='profile_data',
50+
task_spec_id='profile_1eb92',
51+
workflow_run_id='bc77c6e5-753a-4580-96a6-aaed3e5a8d19'
52+
),
53+
resource=WebhookEventPayloadResource(
54+
created_at='2024-07-10T12:49:09Z',
55+
id='profile_1eb92',
56+
input={},
57+
output=None,
58+
task_def_id='profile_data',
59+
task_def_version=None,
60+
updated_at='2024-07-10T12:49:09Z',
61+
workflow_run_id='bc77c6e5-753a-4580-96a6-aaed3e5a8d19'
62+
)
63+
)
64+
)
65+
66+
67+
classic_verifier = WebhookEventVerifier("wU99mE6jJ7nXOLFwZ0tJymM1lpI15pZh")
68+
studio_verifier = WebhookEventVerifier("YKOC6mkBxi6yK2zlUIrLMvsJMFEZObP5")
69+
70+
71+
def test_classic_webhook_event_verification():
72+
signature = "77ebc3e418f26be6eebb47f7ebe551321de26734fc273961e075fc9ab163d9c7"
73+
74+
event = classic_verifier.read_payload(classic_raw_event, signature)
75+
assert event == classic_expected_event
76+
77+
78+
def test_classic_webhook_event_verification_invalid_signature():
79+
signature = "77ebc3e418f26be6eebb47f7ebe551321de26734fc273961e075fc9ab163d9c8"
80+
81+
with pytest.raises(OnfidoInvalidSignatureError):
82+
classic_verifier.read_payload(classic_raw_event, signature)
83+
84+
85+
def test_studio_webhook_event_verification():
86+
signature = "c95a5b785484f6fa1bc25f381b5595d66bf85cb442eefb06aa007802ee6a4dfa"
87+
88+
event = studio_verifier.read_payload(studio_raw_event, signature)
89+
event.payload.object.additional_properties = {} # Suppress any additional property in object
90+
assert event == studio_expected_event
91+
92+
93+
def test_studio_webhook_event_verification_invalid_signature():
94+
signature = "c95a5b785484f6fa1bc25f381b5595d66bf85cb442eefb06aa007802ee6a4dfb"
95+
96+
with pytest.raises(OnfidoInvalidSignatureError):
97+
studio_verifier.read_payload(studio_raw_event, signature)

tests/test_webhook_verification.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/test_workflow_runs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from onfido import TimelineFileReference, WorkflowRun, WorkflowRunBuilder
3+
from onfido import TimelineFileReference, WorkflowRun, WorkflowRunBuilder, WorkflowRunStatus
44
from tests.conftest import (
55
create_applicant,
66
create_workflow_run,
@@ -30,7 +30,7 @@ def test_create_workflow_run(workflow_run, workflow_id):
3030
assert workflow_run is not None
3131
assert isinstance(workflow_run, WorkflowRun)
3232
assert workflow_run.workflow_id == workflow_id
33-
assert workflow_run.status == "awaiting_input"
33+
assert workflow_run.status == WorkflowRunStatus.AWAITING_INPUT
3434

3535

3636
def test_create_workflow_run_with_custom_inputs(onfido_api, applicant_id):
@@ -46,7 +46,7 @@ def test_create_workflow_run_with_custom_inputs(onfido_api, applicant_id):
4646
)
4747
assert isinstance(workflow_run, WorkflowRun)
4848
assert workflow_run.workflow_id == workflow_id
49-
assert workflow_run.status == "approved"
49+
assert workflow_run.status == WorkflowRunStatus.APPROVED
5050

5151

5252
def test_list_workflow_runs(onfido_api):
@@ -76,7 +76,7 @@ def test_generate_timeline_file(onfido_api, applicant_id):
7676
onfido_api, applicant_id=applicant_id, workflow_id=workflow_id
7777
).id
7878
repeat_request_until_status_changes(
79-
onfido_api.find_workflow_run, [workflow_run_id], "approved"
79+
onfido_api.find_workflow_run, [workflow_run_id], WorkflowRunStatus.APPROVED
8080
)
8181

8282
workflow_timeline_file_data = onfido_api.create_timeline_file(workflow_run_id)
@@ -92,7 +92,7 @@ def test_find_timeline_file(onfido_api, applicant_id):
9292
onfido_api, applicant_id=applicant_id, workflow_id=workflow_id
9393
).id
9494
repeat_request_until_status_changes(
95-
onfido_api.find_workflow_run, [workflow_run_id], "approved"
95+
onfido_api.find_workflow_run, [workflow_run_id], WorkflowRunStatus.APPROVED
9696
)
9797

9898
timeline_file_id = onfido_api.create_timeline_file(

0 commit comments

Comments
 (0)