From cce96ce49de121f442ac4c771ae9e646e92fb841 Mon Sep 17 00:00:00 2001 From: andrepereiramendes Date: Fri, 31 May 2024 15:34:49 +0100 Subject: [PATCH] tests id_photos --- tests/conftest.py | 19 +++++++++++------ tests/test_id_photos.py | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 tests/test_id_photos.py diff --git a/tests/conftest.py b/tests/conftest.py index 84f40d2..794c079 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -57,12 +57,19 @@ def upload_live_photo(onfido_api, applicant_id): ) +def upload_id_photo(onfido_api, applicant_id): + return onfido_api.upload_id_photo( + applicant_id=applicant_id, + file="tests/media/sample_photo.png", + ) + + def create_check( - onfido_api, - check_builder=None, - applicant_id=None, - document_ids=None, - report_names=None, + onfido_api, + check_builder=None, + applicant_id=None, + document_ids=None, + report_names=None, ): if check_builder is None: return onfido_api.create_check( @@ -77,7 +84,7 @@ def create_check( def create_workflow_run( - onfido_api, workflow_run_builder=None, applicant_id=None, workflow_id=None + onfido_api, workflow_run_builder=None, applicant_id=None, workflow_id=None ): if workflow_run_builder is None: return onfido_api.create_workflow_run( diff --git a/tests/test_id_photos.py b/tests/test_id_photos.py new file mode 100644 index 0000000..0699280 --- /dev/null +++ b/tests/test_id_photos.py @@ -0,0 +1,47 @@ +import pytest + +from onfido import ApiException, IdPhoto, IDPhotosList +from tests.conftest import create_applicant, upload_id_photo + + +@pytest.fixture(scope="function") +def applicant_id(onfido_api): + return create_applicant(onfido_api).id + + +@pytest.fixture(scope="function", autouse=True) +def id_photo(onfido_api, applicant_id): + return upload_id_photo(onfido_api, applicant_id) + + +def test_create_id_photo(applicant_id, id_photo): + assert id_photo is not None + assert id_photo.file_name == f"{id_photo.id}.png" + assert isinstance(id_photo, IdPhoto) + + +def test_list_id_photos(onfido_api, applicant_id): + id_photos = onfido_api.list_id_photos(applicant_id) + + assert len(id_photos.id_photos) > 0 + assert isinstance(id_photos, IDPhotosList) + + +def test_retrieve_id_photo(onfido_api, id_photo): + get_id_photo = onfido_api.find_id_photo(id_photo.id) + + assert get_id_photo.id == id_photo.id + assert isinstance(get_id_photo, IdPhoto) + + +def test_download_id_photo(onfido_api, id_photo): + file = onfido_api.download_id_photo(id_photo.id) + + assert len(file) > 0 + + +def test_download_inexistent_id_photo(onfido_api): + inexistent_id_photo_id = "00000000-0000-0000-0000-000000000000" + + with pytest.raises(ApiException): + onfido_api.download_id_photo(inexistent_id_photo_id)