From 531cb22c3b7d84b45cdae2dce915a79473674717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20K=C3=B6tter?= Date: Thu, 3 Sep 2026 09:49:38 +0200 Subject: [PATCH] tests - coverage f. body w. ct application/octet-stream --- tests/formdata_test.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/formdata_test.py b/tests/formdata_test.py index b40bfacb..2ffe913f 100644 --- a/tests/formdata_test.py +++ b/tests/formdata_test.py @@ -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 @@ -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