Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

补测试,修bug(? #2280

Closed
wants to merge 4 commits into from
Closed

补测试,修bug(? #2280

wants to merge 4 commits into from

Conversation

eya46
Copy link
Contributor

@eya46 eya46 commented Aug 18, 2023

  • 补message.py的测试
  • 补model.py的测试
  • 补FileTypes的bug(?

httpx驱动器上传失败 #1647

nb model.py内会把files={"test":b"test"}处理成,("test", (None, b"test", None))

httpx

当FileTypes为bytes,不是Tuple[Optional[str], FileContent, Optional[str]]时,httpx会默认file_name="upload"
但传的是 Tuple[None, FileContent, Optional[str]] ,httpx会处理成FileField -> (None, b'test')
( 这会导致server端收不到文件?

# httpx/_multipart.py
if isinstance(value, tuple):
    if len(value) == 2:
        # neither the 3rd parameter (content_type) nor the 4th (headers) was included
        filename, fileobj = value  # type: ignore
    elif len(value) == 3:
        filename, fileobj, content_type = value  # type: ignore
    else:
        # all 4 parameters included
        filename, fileobj, content_type, headers = value  # type: ignore
else:
    filename = Path(str(getattr(value, "name", "upload"))).name

aiohttp

没看(

test_file

files=[
    ("test1", b"test"),
    ("test2", ("test.txt", b"test")),
    ("test3", ("test.txt", b"test", "text/plain")),
]

response = await driver.request(request)
data = json.loads(response.content)

// httpx {"test2": "test", "test3": "test"}, "报错""file parsing error"
assert data["files"] == {
    "test1": "test",
    "test2": "test",
    "test3": "test",
}, "file parsing error"

// aiohttp ok

@codecov
Copy link

codecov bot commented Aug 18, 2023

Codecov Report

Merging #2280 (21a0b6e) into master (47d5a64) will increase coverage by 0.23%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2280      +/-   ##
==========================================
+ Coverage   89.80%   90.04%   +0.23%     
==========================================
  Files          46       46              
  Lines        3345     3345              
==========================================
+ Hits         3004     3012       +8     
+ Misses        341      333       -8     
Flag Coverage Δ
unittests 90.04% <100.00%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
nonebot/internal/driver/model.py 73.42% <100.00%> (+2.79%) ⬆️

... and 1 file with indirect coverage changes

@github-actions
Copy link
Contributor

🚀 Deployed on https://deploy-preview-2280--nonebot2.netlify.app

@github-actions github-actions bot temporarily deployed to pull request August 18, 2023 03:10 Inactive
@yanyongyu
Copy link
Member

能不能一个pr做一件事?

@eya46 eya46 closed this Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants