Skip to content

Commit

Permalink
Merge pull request #58 from onfido/test-id-photos
Browse files Browse the repository at this point in the history
Tests id_photos endpoints
  • Loading branch information
sofia-gomes-onfido authored Jun 4, 2024
2 parents 4b57c74 + cce96ce commit 2ada0fc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
19 changes: 13 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
47 changes: 47 additions & 0 deletions tests/test_id_photos.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2ada0fc

Please sign in to comment.