Skip to content

Commit

Permalink
Merge pull request #44 from jerome-viveret-onfido/async-iterable-payload
Browse files Browse the repository at this point in the history
Switch BufferedReaderPayload to AsyncIterablePayload
  • Loading branch information
jerome-viveret-onfido authored Nov 16, 2023
2 parents f8325d7 + 5195bbf commit adba08b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions onfido/aio_resource.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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={
Expand Down
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_documents.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import aiofiles
import onfido
from onfido.exceptions import OnfidoRequestError
from onfido.regions import Region
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit adba08b

Please sign in to comment.