mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-07 04:13:00 +08:00
完善bilibili的单元测试,尝试解决推文乱码问题(?
This commit is contained in:
parent
48120836ac
commit
a6f9cfa2a0
@ -45,7 +45,7 @@ class Bilibili(NewMessage):
|
|||||||
params=params,
|
params=params,
|
||||||
timeout=4.0,
|
timeout=4.0,
|
||||||
)
|
)
|
||||||
res_dict = json.loads(res.text)
|
res_dict = json.loads(res.text.encode("utf-8"))
|
||||||
if res_dict["code"] == 0:
|
if res_dict["code"] == 0:
|
||||||
return res_dict["data"].get("cards")
|
return res_dict["data"].get("cards")
|
||||||
else:
|
else:
|
||||||
|
File diff suppressed because one or more lines are too long
1933
tests/platforms/static/bilibili_strange_post-0.json
Normal file
1933
tests/platforms/static/bilibili_strange_post-0.json
Normal file
File diff suppressed because one or more lines are too long
2112
tests/platforms/static/bilibili_strange_post.json
Normal file
2112
tests/platforms/static/bilibili_strange_post.json
Normal file
File diff suppressed because one or more lines are too long
@ -1,8 +1,12 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import respx
|
||||||
from httpx import Response
|
from httpx import Response
|
||||||
from nonebug.app import App
|
from nonebug.app import App
|
||||||
|
from pytz import timezone
|
||||||
|
|
||||||
from .utils import get_json
|
from .utils import get_file, get_json
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
@ -46,3 +50,29 @@ async def test_dynamic_forward(bilibili, bing_dy_list):
|
|||||||
+ "\n--------------\n"
|
+ "\n--------------\n"
|
||||||
+ "#明日方舟#\n【新增服饰】\n//殿堂上的游禽 - 星极\n塞壬唱片偶像企划《闪耀阶梯》特供服饰/殿堂上的游禽。星极自费参加了这项企划,尝试着用大众能接受的方式演绎天空之上的故事。\n\n_____________\n谦逊留给观众,骄傲发自歌喉,此夜,唯我璀璨。 "
|
+ "#明日方舟#\n【新增服饰】\n//殿堂上的游禽 - 星极\n塞壬唱片偶像企划《闪耀阶梯》特供服饰/殿堂上的游禽。星极自费参加了这项企划,尝试着用大众能接受的方式演绎天空之上的故事。\n\n_____________\n谦逊留给观众,骄傲发自歌喉,此夜,唯我璀璨。 "
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@respx.mock
|
||||||
|
async def test_fetch_new(bilibili, dummy_user_subinfo):
|
||||||
|
post_router = respx.get(
|
||||||
|
"https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?host_uid=161775300&offset=0&need_top=0"
|
||||||
|
)
|
||||||
|
post_router.mock(
|
||||||
|
return_value=Response(200, json=get_json("bilibili_strange_post-0.json"))
|
||||||
|
)
|
||||||
|
target = "161775300"
|
||||||
|
res = await bilibili.fetch_new_post(target, [dummy_user_subinfo])
|
||||||
|
assert post_router.called
|
||||||
|
assert len(res) == 0
|
||||||
|
|
||||||
|
mock_data = get_json("bilibili_strange_post.json")
|
||||||
|
mock_data["data"]["cards"][0]["desc"]["timestamp"] = int(datetime.now().timestamp())
|
||||||
|
post_router.mock(return_value=Response(200, json=mock_data))
|
||||||
|
res2 = await bilibili.fetch_new_post(target, [dummy_user_subinfo])
|
||||||
|
assert len(res2[0][1]) == 1
|
||||||
|
post = res2[0][1][0]
|
||||||
|
assert (
|
||||||
|
post.text
|
||||||
|
== "#罗德厨房——回甘##明日方舟#\r\n明日方舟官方美食漫画,正式开餐。\r\n往事如烟,安然即好。\r\nMenu 01:高脚羽兽烤串与罗德岛的领袖\r\n\r\n哔哩哔哩漫画阅读:https://manga.bilibili.com/detail/mc31998?from=manga_search\r\n\r\n关注并转发本动态,我们将会在5月27日抽取10位博士赠送【兔兔奇境】周边礼盒一份。 互动抽奖"
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user