From 5195bbf4a0cd6ae6d7a9d11587f24da6160582cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Viveret?= Date: Thu, 16 Nov 2023 14:44:39 +0100 Subject: [PATCH] Switch BufferedReaderPayload to AsyncIterablePayload --- onfido/aio_resource.py | 4 ++-- poetry.lock | 13 ++++++++++++- pyproject.toml | 3 ++- tests/test_documents.py | 6 +++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/onfido/aio_resource.py b/onfido/aio_resource.py index dd63efa..6fce079 100644 --- a/onfido/aio_resource.py +++ b/onfido/aio_resource.py @@ -1,4 +1,4 @@ -from aiohttp import BufferedReaderPayload, ClientSession, MultipartWriter, StringPayload +from aiohttp import AsyncIterablePayload, ClientSession, MultipartWriter, StringPayload from .exceptions import OnfidoRequestError from aiohttp.client_reqrep import ClientResponse from .onfido_download import OnfidoAioDownload @@ -69,7 +69,7 @@ async def _upload_request(self, path, file: BinaryIO, **request_body): ) file_part = mpwriter.append_payload( - BufferedReaderPayload( + AsyncIterablePayload( file, content_type=mimetype_from_name(file.name), headers={ diff --git a/poetry.lock b/poetry.lock index 7387090..0212d39 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,5 +1,16 @@ # This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +[[package]] +name = "aiofiles" +version = "23.2.1" +description = "File support for asyncio." +optional = false +python-versions = ">=3.7" +files = [ + {file = "aiofiles-23.2.1-py3-none-any.whl", hash = "sha256:19297512c647d4b27a2cf7c34caa7e405c0d60b5560618a29a9fe027b18b0107"}, + {file = "aiofiles-23.2.1.tar.gz", hash = "sha256:84ec2218d8419404abcb9f0c02df3f34c6e0a68ed41072acfb1cef5cbc29051a"}, +] + [[package]] name = "aiohttp" version = "3.8.6" @@ -1020,4 +1031,4 @@ testing = ["func-timeout", "jaraco.itertools"] [metadata] lock-version = "2.0" python-versions = ">=3.7,<4" -content-hash = "1cd59a073ff3075b1b34a5b2522f4de7c38ad0b416545031affe56aeefb85a1e" +content-hash = "f2f96684037cf7db56a64a5d93a734dd62d9c9bb2ed6db9ad0af600b47a07427" diff --git a/pyproject.toml b/pyproject.toml index 0dec796..74191a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "onfido-python" -version = "2.8.0" +version = "2.8.1" description = "The official wrapper for the Onfido API" homepage = "https://github.com/onfido/onfido-python" readme = "README.md" @@ -29,6 +29,7 @@ flake8 = "^3.8.3" [tool.poetry.group.dev.dependencies] aioresponses = "^0.7.4" pytest-asyncio = "^0.21.1" +aiofiles = "^23.2.1" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/tests/test_documents.py b/tests/test_documents.py index 69904fa..a6a1e45 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -1,3 +1,4 @@ +import aiofiles import onfido from onfido.exceptions import OnfidoRequestError from onfido.regions import Region @@ -46,9 +47,8 @@ async def test_async_upload_document(m): m.post("https://api.eu.onfido.com/v3.6/documents/", payload=request_body) - sample_file = open("sample_driving_licence.png", "rb") - - await async_api.document.upload(sample_file, request_body) + async with aiofiles.open("sample_driving_licence.png", "rb") as sample_file: + await async_api.document.upload(sample_file, request_body) m.assert_called_once()