|
| 1 | +import pytest |
| 2 | +from pydantic import ValidationError |
| 3 | + |
| 4 | +from onfido import ApiException, SigningDocument, SigningDocumentsList |
| 5 | +from tests.conftest import create_applicant, upload_signing_document |
| 6 | + |
| 7 | +INEXISTENT_SIGNING_DOCUMENT_ID = "00000000-0000-0000-0000-000000000000" |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture(scope="function") |
| 11 | +def applicant(onfido_api): |
| 12 | + return create_applicant(onfido_api) |
| 13 | + |
| 14 | + |
| 15 | +@pytest.fixture(scope="function") |
| 16 | +def signing_document(onfido_api, applicant): |
| 17 | + return upload_signing_document(onfido_api, applicant.id) |
| 18 | + |
| 19 | + |
| 20 | +def test_upload_signing_document(signing_document, applicant): |
| 21 | + assert isinstance(signing_document, SigningDocument) |
| 22 | + assert signing_document.file_name == "sample_signing_document.pdf" |
| 23 | + assert signing_document.file_type == "pdf" |
| 24 | + assert signing_document.applicant_id == applicant.id |
| 25 | + assert signing_document.href is not None |
| 26 | + assert signing_document.download_href is not None |
| 27 | + assert signing_document.file_size is not None and signing_document.file_size > 0 |
| 28 | + assert signing_document.model_dump_json(by_alias=True, exclude_none=True) is not None |
| 29 | + |
| 30 | + |
| 31 | +def test_download_signing_document(onfido_api, signing_document): |
| 32 | + file_contents = onfido_api.download_signing_document(signing_document.id) |
| 33 | + |
| 34 | + assert len(file_contents) > 0 |
| 35 | + assert bytes(file_contents[:4]) == b"%PDF" |
| 36 | + |
| 37 | + |
| 38 | +def test_find_signing_document(onfido_api, signing_document, applicant): |
| 39 | + found = onfido_api.find_signing_document(signing_document.id) |
| 40 | + |
| 41 | + assert isinstance(found, SigningDocument) |
| 42 | + assert found.id == signing_document.id |
| 43 | + assert found.file_name == "sample_signing_document.pdf" |
| 44 | + assert found.file_type == "pdf" |
| 45 | + assert found.applicant_id == applicant.id |
| 46 | + assert found.download_href is not None |
| 47 | + assert found.model_dump_json(by_alias=True, exclude_none=True) is not None |
| 48 | + |
| 49 | + |
| 50 | +def test_list_signing_documents(onfido_api, applicant, signing_document): |
| 51 | + documents = onfido_api.list_signing_documents(applicant.id) |
| 52 | + |
| 53 | + assert documents is not None |
| 54 | + assert isinstance(documents, SigningDocumentsList) |
| 55 | + assert any(doc.id == signing_document.id for doc in documents.signing_documents) |
| 56 | + |
| 57 | + |
| 58 | +def test_upload_signing_document_with_null_params(onfido_api): |
| 59 | + with pytest.raises(ValidationError): |
| 60 | + onfido_api.upload_signing_document(None, None) |
| 61 | + |
| 62 | + |
| 63 | +def test_download_inexistent_signing_document(onfido_api): |
| 64 | + with pytest.raises(ApiException): |
| 65 | + onfido_api.download_signing_document(INEXISTENT_SIGNING_DOCUMENT_ID) |
0 commit comments