test(fix):向test中添加了图片的mock

This commit is contained in:
Azide 2022-07-05 22:55:32 +08:00
parent 6da77e2404
commit 864b1e4d83
3 changed files with 15 additions and 2 deletions

View File

@ -32,7 +32,7 @@ class _CustomPost(BasePost):
md += "{}<br>".format(message_segment.data.get("text", ""))
elif message_segment.type == "image":
try:
# 先尝试获取file的值没有尝试获取url的值都没有则为空
# 先尝试获取file的值没有尝试获取url的值都没有则为空
pic_res = message_segment.data.get(
"file", message_segment.data.get("url", "")
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -1,8 +1,10 @@
import base64
import hashlib
import logging
from pathlib import Path
import pytest
import respx
from httpx import Response
from nonebot.adapters.onebot.v11.message import MessageSegment
from nonebug.app import App
@ -41,10 +43,21 @@ def test_gene_md(app: App, expect_md, ms_list):
assert cp_md == expect_md
@respx.mock
@pytest.mark.asyncio
async def test_gene_pic(app: App, ms_list, pic_hash):
from nonebot_bison.post.custom_post import CustomPost
pic_router = respx.get(
"http://i0.hdslb.com/bfs/live/new_room_cover/cf7d4d3b2f336c6dba299644c3af952c5db82612.jpg"
)
pic_path = Path(__file__).parent / "platforms" / "static" / "custom_post_pic.jpg"
with open(pic_path, mode="rb") as f:
mock_pic = f.read()
pic_router.mock(return_value=Response(200, stream=mock_pic))
cp = CustomPost(message_segments=ms_list)
cp_pic_bytes: list[MessageSegment] = await cp.generate_pic_messages()