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)