From 2e8230e9f42cfd57df8cda62c8a9d06c6c763d00 Mon Sep 17 00:00:00 2001 From: eya46 <61458340+eya46@users.noreply.github.com> Date: Wed, 23 Aug 2023 14:14:07 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20Fix:=20=E8=AE=BE=E7=BD=AE=20file=20requ?= =?UTF-8?q?est=20=E9=BB=98=E8=AE=A4=20filename=20(#2284)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> --- nonebot/internal/driver/model.py | 2 +- tests/test_driver.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/nonebot/internal/driver/model.py b/nonebot/internal/driver/model.py index 6324006b..927c9a89 100644 --- a/nonebot/internal/driver/model.py +++ b/nonebot/internal/driver/model.py @@ -125,7 +125,7 @@ class Request: files_ = files.items() if isinstance(files, dict) else files for name, file_info in files_: if not isinstance(file_info, tuple): - self.files.append((name, (None, file_info, None))) + self.files.append((name, (name, file_info, None))) elif len(file_info) == 2: self.files.append((name, (file_info[0], file_info[1], None))) else: diff --git a/tests/test_driver.py b/tests/test_driver.py index bd56deed..75c9bc2a 100644 --- a/tests/test_driver.py +++ b/tests/test_driver.py @@ -233,6 +233,23 @@ async def test_http_client(driver: Driver, server_url: URL): content="test", ) response = await driver.request(request) + assert server_url.host is not None + request_raw_url = Request( + "POST", + ( + server_url.scheme.encode("ascii"), + server_url.host.encode("ascii"), + server_url.port, + server_url.path.encode("ascii"), + ), + params={"param": "test"}, + headers={"X-Test": "test"}, + cookies={"session": "test"}, + content="test", + ) + assert ( + request.url == request_raw_url.url + ), "request.url should be equal to request_raw_url.url" assert response.status_code == 200 assert response.content data = json.loads(response.content) @@ -265,7 +282,11 @@ async def test_http_client(driver: Driver, server_url: URL): "POST", server_url, data={"form": "test"}, - files={"test": ("test.txt", b"test")}, + files=[ + ("test1", b"test"), + ("test2", ("test.txt", b"test")), + ("test3", ("test.txt", b"test", "text/plain")), + ], ) response = await driver.request(request) assert response.status_code == 200 @@ -273,7 +294,11 @@ async def test_http_client(driver: Driver, server_url: URL): data = json.loads(response.content) assert data["method"] == "POST" assert data["form"] == {"form": "test"} - assert data["files"] == {"test": "test"} + assert data["files"] == { + "test1": "test", + "test2": "test", + "test3": "test", + }, "file parsing error" await asyncio.sleep(1)