mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 00:55:07 +08:00
🐛 Fix: 设置 file request 默认 filename (#2284)
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>
This commit is contained in:
parent
4bfea99e54
commit
2e8230e9f4
@ -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:
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user