mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-08 04:43:00 +08:00
test(fix):向test中添加了图片的mock
This commit is contained in:
parent
6da77e2404
commit
864b1e4d83
@ -32,7 +32,7 @@ class _CustomPost(BasePost):
|
|||||||
md += "{}<br>".format(message_segment.data.get("text", ""))
|
md += "{}<br>".format(message_segment.data.get("text", ""))
|
||||||
elif message_segment.type == "image":
|
elif message_segment.type == "image":
|
||||||
try:
|
try:
|
||||||
# 先尝试获取file的值,没有在尝试获取url的值,都没有则为空
|
# 先尝试获取file的值,没有再尝试获取url的值,都没有则为空
|
||||||
pic_res = message_segment.data.get(
|
pic_res = message_segment.data.get(
|
||||||
"file", message_segment.data.get("url", "")
|
"file", message_segment.data.get("url", "")
|
||||||
)
|
)
|
||||||
|
BIN
tests/platforms/static/custom_post_pic.jpg
Normal file
BIN
tests/platforms/static/custom_post_pic.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
@ -1,8 +1,10 @@
|
|||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import respx
|
||||||
|
from httpx import Response
|
||||||
from nonebot.adapters.onebot.v11.message import MessageSegment
|
from nonebot.adapters.onebot.v11.message import MessageSegment
|
||||||
from nonebug.app import App
|
from nonebug.app import App
|
||||||
|
|
||||||
@ -41,10 +43,21 @@ def test_gene_md(app: App, expect_md, ms_list):
|
|||||||
assert cp_md == expect_md
|
assert cp_md == expect_md
|
||||||
|
|
||||||
|
|
||||||
|
@respx.mock
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_gene_pic(app: App, ms_list, pic_hash):
|
async def test_gene_pic(app: App, ms_list, pic_hash):
|
||||||
from nonebot_bison.post.custom_post import CustomPost
|
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 = CustomPost(message_segments=ms_list)
|
||||||
cp_pic_bytes: list[MessageSegment] = await cp.generate_pic_messages()
|
cp_pic_bytes: list[MessageSegment] = await cp.generate_pic_messages()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user