-
Notifications
You must be signed in to change notification settings - Fork 24
[BIO-8820] feat: Add biometric token endpoints tests #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dvacca-onfido
merged 4 commits into
onfido:master
from
anancarv:feat/add-tests-for-bio-token-endpoints
Jul 9, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e225f91
tests: Add biometric token endpoint tests
anancarv f576086
fix: fix merge conflicts and adjust tests
anancarv c027180
fix: remove edits in the auto-generated biometric_token file
anancarv d3e712f
refactor: improve the biometric_token tests
anancarv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| import json | ||
| from time import sleep | ||
| from uuid import uuid4 | ||
|
|
||
| import pytest | ||
|
|
||
| from onfido import ( | ||
| ApiException, | ||
| ApplicantBuilder, | ||
| ApplicantConsentBuilder, | ||
| ApplicantConsentName, | ||
| BiometricTokenUpdater, | ||
| WorkflowRunBuilder, | ||
| ) | ||
| from tests.conftest import create_applicant, upload_live_photo | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def applicant_id(onfido_api): | ||
| unique_suffix = uuid4().hex[:8] | ||
| applicant = create_applicant( | ||
| onfido_api, | ||
| ApplicantBuilder( | ||
| first_name=f"First{unique_suffix}", | ||
| last_name=f"Last{unique_suffix}", | ||
| email=f"first.last.{unique_suffix}@example.com", | ||
| consents=[ | ||
| ApplicantConsentBuilder( | ||
| name=ApplicantConsentName.PRIVACY_NOTICES_READ, | ||
| granted=True, | ||
| ) | ||
| ], | ||
| ), | ||
| ) | ||
| return applicant.id | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def biometric_workflow_id(): | ||
| return "b79dcf69-41a0-412d-b803-d1a618730f72" | ||
|
anancarv marked this conversation as resolved.
|
||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def biometric_customer_user_id(): | ||
| return f"test-user-id-{uuid4()}" | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function", autouse=True) | ||
| def live_photo(onfido_api, applicant_id): | ||
| return upload_live_photo(onfido_api, applicant_id) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def create_biometric_token( | ||
| onfido_api, | ||
| applicant_id, | ||
| biometric_workflow_id, | ||
| biometric_customer_user_id, | ||
| live_photo, | ||
| ): | ||
| workflow_run = onfido_api.create_workflow_run( | ||
| WorkflowRunBuilder( | ||
| applicant_id=applicant_id, | ||
| workflow_id=biometric_workflow_id, | ||
| customer_user_id=biometric_customer_user_id, | ||
| custom_data={ | ||
| "media_ids": [ | ||
| { | ||
| "id": str(live_photo.id), | ||
| } | ||
| ] | ||
| }, | ||
| ) | ||
| ) | ||
|
|
||
| assert workflow_run.customer_user_id == biometric_customer_user_id | ||
|
|
||
| max_retries = 3 | ||
|
|
||
| # Wait for the biometric token to be created | ||
| for _ in range(max_retries + 1): | ||
| biometric_tokens = onfido_api.list_biometric_tokens( | ||
| biometric_customer_user_id | ||
| ) | ||
| if biometric_tokens.biometric_tokens: | ||
| return biometric_tokens | ||
| sleep(2) | ||
|
|
||
| pytest.fail("Biometric tokens were not created in time") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def biometric_token_id(create_biometric_token): | ||
| token_uuid = create_biometric_token.biometric_tokens[0].uuid | ||
| if token_uuid is None: | ||
|
anancarv marked this conversation as resolved.
|
||
| pytest.fail("Biometric token response did not include a uuid") | ||
|
|
||
| return token_uuid | ||
|
|
||
|
|
||
| def test_list_biometric_tokens(create_biometric_token): | ||
| assert len(create_biometric_token.biometric_tokens) > 0 | ||
| assert create_biometric_token.biometric_tokens[0].uuid is not None | ||
| assert create_biometric_token.biometric_tokens[0].data.status is not None | ||
|
|
||
|
|
||
| def test_find_biometric_token(onfido_api, biometric_customer_user_id, biometric_token_id): | ||
| biometric_token_response = onfido_api.find_biometric_token( | ||
| biometric_customer_user_id, | ||
| biometric_token_id, | ||
| ) | ||
|
|
||
| assert biometric_token_response.biometric_token.uuid == biometric_token_id | ||
| assert biometric_token_response.biometric_token.data.status is not None | ||
|
|
||
|
|
||
| def test_update_biometric_token_status(onfido_api, biometric_customer_user_id, biometric_token_id): | ||
| approved_status = "approved" | ||
| updated_biometric_token = onfido_api.update_biometric_token( | ||
| biometric_customer_user_id, | ||
| biometric_token_id, | ||
| BiometricTokenUpdater(status=approved_status), | ||
| ) | ||
|
|
||
| assert updated_biometric_token.biometric_token.uuid == biometric_token_id | ||
| assert updated_biometric_token.biometric_token.data.status == approved_status | ||
|
|
||
|
|
||
| def test_invalidate_biometric_token_success(onfido_api, biometric_customer_user_id, biometric_token_id): | ||
| response = onfido_api.invalidate_biometric_token_without_preload_content( | ||
| biometric_customer_user_id, | ||
| biometric_token_id, | ||
| ) | ||
|
|
||
| assert response.status == 200 | ||
|
|
||
|
|
||
| def test_invalidate_biometric_token_not_found_when_already_deleted( | ||
| onfido_api, | ||
| biometric_customer_user_id, | ||
| biometric_token_id, | ||
| ): | ||
| onfido_api.invalidate_biometric_token_without_preload_content( | ||
| biometric_customer_user_id, | ||
| biometric_token_id, | ||
| ) | ||
|
|
||
| with pytest.raises(ApiException) as exc_info: | ||
| onfido_api.invalidate_biometric_token( | ||
| biometric_customer_user_id, | ||
| biometric_token_id, | ||
| ) | ||
|
|
||
| error_response = json.loads(exc_info.value.body) | ||
|
|
||
| assert exc_info.value.status == 404 | ||
| assert error_response["error"]["message"] == "Not found" | ||
| assert error_response["error"]["type"] == "resource_not_found" | ||
|
|
||
|
|
||
| def test_invalidate_biometric_tokens_success( | ||
| onfido_api, | ||
| biometric_customer_user_id, | ||
| create_biometric_token, | ||
| ): | ||
| response = onfido_api.invalidate_biometric_tokens_without_preload_content( | ||
| biometric_customer_user_id | ||
| ) | ||
|
|
||
| assert response.status == 200 | ||
|
|
||
|
|
||
| def test_invalidate_biometric_tokens_not_found_when_already_deleted( | ||
| onfido_api, | ||
| biometric_customer_user_id, | ||
| create_biometric_token, | ||
| ): | ||
| onfido_api.invalidate_biometric_tokens_without_preload_content( | ||
| biometric_customer_user_id | ||
| ) | ||
|
|
||
| with pytest.raises(ApiException) as exc_info: | ||
| onfido_api.invalidate_biometric_tokens( | ||
| biometric_customer_user_id | ||
| ) | ||
|
|
||
| error_response = json.loads(exc_info.value.body) | ||
|
|
||
| assert exc_info.value.status == 404 | ||
| assert error_response["error"]["message"] == "Not found" | ||
| assert error_response["error"]["type"] == "resource_not_found" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.