Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/formdata_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

import httpx2
import pytest

from aiopenapi3 import OpenAPI
from aiopenapi3.v30.formdata import MultipartParameter, encode_multipart_parameters
Expand Down Expand Up @@ -78,6 +79,30 @@ def test_formdata_encoding(httpx2_mock, with_paths_requestbody_formdata_encoding
assert result == "ok"


@pytest.mark.httpx2_mock(can_send_already_matched_responses=True)
def test_formdata_file(httpx2_mock, with_paths_requestbody_formdata_encoding):
import io

httpx2_mock.add_response(
headers={"Content-Type": "application/json"},
json="ok",
)

api = OpenAPI("http://localhost/api", with_paths_requestbody_formdata_encoding, session_factory=httpx2.Client)
content = b"data"

api._.file(data=("test.png", io.BytesIO(content)))
request = httpx2_mock.get_requests()[-1]
assert request.content == content

api._.file(data=io.BytesIO(content))
request = httpx2_mock.get_requests()[-1]
assert request.content == content

with pytest.raises(TypeError):
api._.file(data=1)


def _test_speed():
import timeit

Expand Down