mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-13 20:38:39 +08:00
🎨 按ruff调整测试代码
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import AsyncClient, Response
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
from httpx import Response, AsyncClient
|
||||
|
||||
from .utils import get_file, get_json
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def arknights(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
return platform_manager["arknights"](ProcessContext(), AsyncClient())
|
||||
|
||||
@@ -39,7 +39,7 @@ def monster_siren_list_1():
|
||||
return get_json("monster-siren_list_1.json")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.asyncio()
|
||||
@respx.mock
|
||||
async def test_fetch_new(
|
||||
arknights,
|
||||
@@ -49,30 +49,18 @@ async def test_fetch_new(
|
||||
monster_siren_list_0,
|
||||
monster_siren_list_1,
|
||||
):
|
||||
ak_list_router = respx.get(
|
||||
"https://ak-conf.hypergryph.com/config/prod/announce_meta/IOS/announcement.meta.json"
|
||||
)
|
||||
detail_router = respx.get(
|
||||
"https://ak.hycdn.cn/announce/IOS/announcement/807_1640060583.html"
|
||||
)
|
||||
version_router = respx.get(
|
||||
"https://ak-conf.hypergryph.com/config/prod/official/IOS/version"
|
||||
)
|
||||
ak_list_router = respx.get("https://ak-conf.hypergryph.com/config/prod/announce_meta/IOS/announcement.meta.json")
|
||||
detail_router = respx.get("https://ak.hycdn.cn/announce/IOS/announcement/807_1640060583.html")
|
||||
version_router = respx.get("https://ak-conf.hypergryph.com/config/prod/official/IOS/version")
|
||||
preannouncement_router = respx.get(
|
||||
"https://ak-conf.hypergryph.com/config/prod/announce_meta/IOS/preannouncement.meta.json"
|
||||
)
|
||||
monster_siren_router = respx.get("https://monster-siren.hypergryph.com/api/news")
|
||||
terra_list = respx.get("https://terra-historicus.hypergryph.com/api/recentUpdate")
|
||||
ak_list_router.mock(return_value=Response(200, json=arknights_list__1))
|
||||
detail_router.mock(
|
||||
return_value=Response(200, text=get_file("arknights-detail-807"))
|
||||
)
|
||||
version_router.mock(
|
||||
return_value=Response(200, json=get_json("arknights-version-0.json"))
|
||||
)
|
||||
preannouncement_router.mock(
|
||||
return_value=Response(200, json=get_json("arknights-pre-0.json"))
|
||||
)
|
||||
detail_router.mock(return_value=Response(200, text=get_file("arknights-detail-807")))
|
||||
version_router.mock(return_value=Response(200, json=get_json("arknights-version-0.json")))
|
||||
preannouncement_router.mock(return_value=Response(200, json=get_json("arknights-pre-0.json")))
|
||||
monster_siren_router.mock(return_value=Response(200, json=monster_siren_list_0))
|
||||
terra_list.mock(return_value=Response(200, json=get_json("terra-hist-0.json")))
|
||||
target = ""
|
||||
@@ -92,7 +80,6 @@ async def test_fetch_new(
|
||||
assert post.target_name == "明日方舟游戏内公告"
|
||||
assert len(post.pics) == 1
|
||||
# assert(post.pics == ['https://ak-fs.hypergryph.com/announce/images/20210623/e6f49aeb9547a2278678368a43b95b07.jpg'])
|
||||
print(res3[0][1])
|
||||
await post.generate_messages()
|
||||
terra_list.mock(return_value=Response(200, json=get_json("terra-hist-1.json")))
|
||||
res = await arknights.fetch_new_post(target, [dummy_user_subinfo])
|
||||
@@ -101,12 +88,10 @@ async def test_fetch_new(
|
||||
assert post.target_type == "terra-historicus"
|
||||
assert post.text == "123罗德岛!? - 「掠风」篇"
|
||||
assert post.url == "https://terra-historicus.hypergryph.com/comic/6253/episode/4938"
|
||||
assert post.pics == [
|
||||
"https://web.hycdn.cn/comic/pic/20220507/ab8a2ff408ec7d587775aed70b178ec0.png"
|
||||
]
|
||||
assert post.pics == ["https://web.hycdn.cn/comic/pic/20220507/ab8a2ff408ec7d587775aed70b178ec0.png"]
|
||||
|
||||
|
||||
@pytest.mark.render
|
||||
@pytest.mark.render()
|
||||
@respx.mock
|
||||
async def test_send_with_render(
|
||||
arknights,
|
||||
@@ -116,30 +101,18 @@ async def test_send_with_render(
|
||||
monster_siren_list_0,
|
||||
monster_siren_list_1,
|
||||
):
|
||||
ak_list_router = respx.get(
|
||||
"https://ak-conf.hypergryph.com/config/prod/announce_meta/IOS/announcement.meta.json"
|
||||
)
|
||||
detail_router = respx.get(
|
||||
"https://ak.hycdn.cn/announce/IOS/announcement/805_1640074952.html"
|
||||
)
|
||||
version_router = respx.get(
|
||||
"https://ak-conf.hypergryph.com/config/prod/official/IOS/version"
|
||||
)
|
||||
ak_list_router = respx.get("https://ak-conf.hypergryph.com/config/prod/announce_meta/IOS/announcement.meta.json")
|
||||
detail_router = respx.get("https://ak.hycdn.cn/announce/IOS/announcement/805_1640074952.html")
|
||||
version_router = respx.get("https://ak-conf.hypergryph.com/config/prod/official/IOS/version")
|
||||
preannouncement_router = respx.get(
|
||||
"https://ak-conf.hypergryph.com/config/prod/announce_meta/IOS/preannouncement.meta.json"
|
||||
)
|
||||
monster_siren_router = respx.get("https://monster-siren.hypergryph.com/api/news")
|
||||
terra_list = respx.get("https://terra-historicus.hypergryph.com/api/recentUpdate")
|
||||
ak_list_router.mock(return_value=Response(200, json=arknights_list_0))
|
||||
detail_router.mock(
|
||||
return_value=Response(200, text=get_file("arknights-detail-805"))
|
||||
)
|
||||
version_router.mock(
|
||||
return_value=Response(200, json=get_json("arknights-version-0.json"))
|
||||
)
|
||||
preannouncement_router.mock(
|
||||
return_value=Response(200, json=get_json("arknights-pre-0.json"))
|
||||
)
|
||||
detail_router.mock(return_value=Response(200, text=get_file("arknights-detail-805")))
|
||||
version_router.mock(return_value=Response(200, json=get_json("arknights-version-0.json")))
|
||||
preannouncement_router.mock(return_value=Response(200, json=get_json("arknights-pre-0.json")))
|
||||
monster_siren_router.mock(return_value=Response(200, json=monster_siren_list_0))
|
||||
terra_list.mock(return_value=Response(200, json=get_json("terra-hist-0.json")))
|
||||
target = ""
|
||||
@@ -159,5 +132,5 @@ async def test_send_with_render(
|
||||
assert post.target_name == "明日方舟游戏内公告"
|
||||
assert len(post.pics) == 1
|
||||
# assert(post.pics == ['https://ak-fs.hypergryph.com/announce/images/20210623/e6f49aeb9547a2278678368a43b95b07.jpg'])
|
||||
print(res3[0][1])
|
||||
r = await post.generate_messages()
|
||||
assert r
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import typing
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import AsyncClient, Response
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
from pytz import timezone
|
||||
from httpx import Response, AsyncClient
|
||||
|
||||
from .utils import get_file, get_json
|
||||
from .utils import get_json
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@@ -19,10 +18,10 @@ if typing.TYPE_CHECKING:
|
||||
from nonebot_bison.platform.bilibili import Bilibili
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def bilibili(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
return platform_manager["bilibili"](ProcessContext(), AsyncClient())
|
||||
|
||||
@@ -46,7 +45,7 @@ async def test_video_forward(bilibili, bing_dy_list):
|
||||
post = await bilibili.parse(bing_dy_list[1])
|
||||
assert (
|
||||
post.text
|
||||
== "答案揭晓:宿舍!来看看投票结果\nhttps://t.bilibili.com/568093580488553786\n--------------\n#可露希尔的秘密档案# \n11:来宿舍休息一下吧 \n档案来源:lambda:\\罗德岛内务\\秘密档案 \n发布时间:9/12 1:00 P.M. \n档案类型:可见 \n档案描述:今天请了病假在宿舍休息。很舒适。 \n提供者:赫默\n=================\n《可露希尔的秘密档案》11话:来宿舍休息一下吧"
|
||||
== "答案揭晓:宿舍!来看看投票结果\nhttps://t.bilibili.com/568093580488553786\n--------------\n#可露希尔的秘密档案# \n11:来宿舍休息一下吧 \n档案来源:lambda:\\罗德岛内务\\秘密档案 \n发布时间:9/12 1:00 P.M. \n档案类型:可见 \n档案描述:今天请了病假在宿舍休息。很舒适。 \n提供者:赫默\n=================\n《可露希尔的秘密档案》11话:来宿舍休息一下吧" # noqa: E501
|
||||
)
|
||||
|
||||
|
||||
@@ -57,7 +56,7 @@ async def test_article_forward(bilibili, bing_dy_list):
|
||||
post.text
|
||||
== "#明日方舟##饼学大厦#\n9.11专栏更新完毕,这还塌了实属没跟新运营对上\n后边除了周日发饼和PV没提及的中文语音,稳了\n别忘了来参加#可露希尔的秘密档案#的主题投票\nhttps://t.bilibili.com/568093580488553786?tab=2"
|
||||
+ "\n--------------\n"
|
||||
+ "【明日方舟】饼学大厦#12~14(风暴瞭望&玛莉娅·临光&红松林&感谢庆典)9.11更新 更新记录09.11更新:覆盖09.10更新;以及排期更新,猜测周一周五开活动09.10更新:以周五开活动为底,PV/公告调整位置,整体结构更新09.08更新:饼学大厦#12更新,新增一件六星商店服饰(周日发饼)09.06更新:饼学大厦整栋整栋翻新,改为9.16开主线(四日无饼!)09.05凌晨更新:10.13后的排期(两日无饼,鹰角背刺,心狠手辣)前言感谢楪筱祈ぺ的动态-哔哩哔哩 (bilibili.com) 对饼学的贡献!后续排期:9.17【风暴瞭望】、10.01【玛莉娅·临光】复刻、10.1"
|
||||
+ "【明日方舟】饼学大厦#12~14(风暴瞭望&玛莉娅·临光&红松林&感谢庆典)9.11更新 更新记录09.11更新:覆盖09.10更新;以及排期更新,猜测周一周五开活动09.10更新:以周五开活动为底,PV/公告调整位置,整体结构更新09.08更新:饼学大厦#12更新,新增一件六星商店服饰(周日发饼)09.06更新:饼学大厦整栋整栋翻新,改为9.16开主线(四日无饼!)09.05凌晨更新:10.13后的排期(两日无饼,鹰角背刺,心狠手辣)前言感谢楪筱祈ぺ的动态-哔哩哔哩 (bilibili.com) 对饼学的贡献!后续排期:9.17【风暴瞭望】、10.01【玛莉娅·临光】复刻、10.1" # noqa: E501
|
||||
)
|
||||
|
||||
|
||||
@@ -66,9 +65,9 @@ async def test_dynamic_forward(bilibili, bing_dy_list):
|
||||
post = await bilibili.parse(bing_dy_list[5])
|
||||
assert (
|
||||
post.text
|
||||
== "饼组主线饼学预测——9.11版\n①今日结果\n9.11 殿堂上的游禽-星极(x,新运营实锤了)\n②后续预测\n9.12 #罗德岛相簿#+#可露希尔的秘密档案#11话\n9.13 六星先锋(执旗手)干员-琴柳\n9.14 宣传策略-空弦+家具\n9.15 轮换池(+中文语音前瞻)\n9.16 停机\n9.17 #罗德岛闲逛部#+新六星EP+EP09·风暴瞭望开启\n9.19 #罗德岛相簿#"
|
||||
== "饼组主线饼学预测——9.11版\n①今日结果\n9.11 殿堂上的游禽-星极(x,新运营实锤了)\n②后续预测\n9.12 #罗德岛相簿#+#可露希尔的秘密档案#11话\n9.13 六星先锋(执旗手)干员-琴柳\n9.14 宣传策略-空弦+家具\n9.15 轮换池(+中文语音前瞻)\n9.16 停机\n9.17 #罗德岛闲逛部#+新六星EP+EP09·风暴瞭望开启\n9.19 #罗德岛相簿#" # noqa: E501
|
||||
+ "\n--------------\n"
|
||||
+ "#明日方舟#\n【新增服饰】\n//殿堂上的游禽 - 星极\n塞壬唱片偶像企划《闪耀阶梯》特供服饰/殿堂上的游禽。星极自费参加了这项企划,尝试着用大众能接受的方式演绎天空之上的故事。\n\n_____________\n谦逊留给观众,骄傲发自歌喉,此夜,唯我璀璨。 "
|
||||
+ "#明日方舟#\n【新增服饰】\n//殿堂上的游禽 - 星极\n塞壬唱片偶像企划《闪耀阶梯》特供服饰/殿堂上的游禽。星极自费参加了这项企划,尝试着用大众能接受的方式演绎天空之上的故事。\n\n_____________\n谦逊留给观众,骄傲发自歌喉,此夜,唯我璀璨。 " # noqa: E501
|
||||
)
|
||||
|
||||
|
||||
@@ -93,9 +92,7 @@ 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"))
|
||||
)
|
||||
post_router.mock(return_value=Response(200, json=get_json("bilibili_strange_post-0.json")))
|
||||
bilibili_main_page_router = respx.get("https://www.bilibili.com/")
|
||||
bilibili_main_page_router.mock(return_value=Response(200))
|
||||
target = "161775300"
|
||||
@@ -111,7 +108,7 @@ async def test_fetch_new(bilibili, dummy_user_subinfo):
|
||||
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位博士赠送【兔兔奇境】周边礼盒一份。 互动抽奖"
|
||||
== "#罗德厨房——回甘##明日方舟#\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位博士赠送【兔兔奇境】周边礼盒一份。 互动抽奖" # noqa: E501
|
||||
)
|
||||
|
||||
|
||||
@@ -127,9 +124,7 @@ async def test_parse_target(bilibili: "Bilibili"):
|
||||
)
|
||||
assert res2 == "161775300"
|
||||
with pytest.raises(Platform.ParseTargetException):
|
||||
await bilibili.parse_target(
|
||||
"https://www.bilibili.com/video/BV1qP4y1g738?spm_id_from=333.999.0.0"
|
||||
)
|
||||
await bilibili.parse_target("https://www.bilibili.com/video/BV1qP4y1g738?spm_id_from=333.999.0.0")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@@ -140,7 +135,6 @@ def post_list():
|
||||
# 测试新tag机制的平台推送情况
|
||||
@pytest.mark.asyncio
|
||||
async def test_filter_user_custom(bilibili, post_list):
|
||||
|
||||
only_banned_tags = ["~可露希尔的秘密档案"]
|
||||
res0 = await bilibili.filter_user_custom(post_list, [], only_banned_tags)
|
||||
assert len(res0) == 8
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import typing
|
||||
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import AsyncClient, Response
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
from httpx import Response, AsyncClient
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
@@ -11,10 +11,10 @@ if typing.TYPE_CHECKING:
|
||||
from nonebot_bison.platform.bilibili import BilibiliBangumi
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def bili_bangumi(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
return platform_manager["bilibili-bangumi"](ProcessContext(), AsyncClient())
|
||||
|
||||
@@ -26,32 +26,20 @@ async def test_parse_target(bili_bangumi: "BilibiliBangumi"):
|
||||
assert res1 == "28339726"
|
||||
res2 = await bili_bangumi.parse_target("md28339726")
|
||||
assert res2 == "28339726"
|
||||
res3 = await bili_bangumi.parse_target(
|
||||
"https://www.bilibili.com/bangumi/media/md28339726"
|
||||
)
|
||||
res3 = await bili_bangumi.parse_target("https://www.bilibili.com/bangumi/media/md28339726")
|
||||
assert res3 == "28339726"
|
||||
with pytest.raises(Platform.ParseTargetException):
|
||||
await bili_bangumi.parse_target(
|
||||
"https://www.bilibili.com/bangumi/play/ep683045"
|
||||
)
|
||||
await bili_bangumi.parse_target("https://www.bilibili.com/bangumi/play/ep683045")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_fetch_bilibili_bangumi_status(
|
||||
bili_bangumi: "BilibiliBangumi", dummy_user_subinfo
|
||||
):
|
||||
async def test_fetch_bilibili_bangumi_status(bili_bangumi: "BilibiliBangumi", dummy_user_subinfo):
|
||||
from nonebot_bison.types import Target
|
||||
|
||||
bili_bangumi_router = respx.get(
|
||||
"https://api.bilibili.com/pgc/review/user?media_id=28235413"
|
||||
)
|
||||
bili_bangumi_detail_router = respx.get(
|
||||
"https://api.bilibili.com/pgc/view/web/season?season_id=39719"
|
||||
)
|
||||
bili_bangumi_router.mock(
|
||||
return_value=Response(200, json=get_json("bilibili-gangumi-hanhua0.json"))
|
||||
)
|
||||
bili_bangumi_router = respx.get("https://api.bilibili.com/pgc/review/user?media_id=28235413")
|
||||
bili_bangumi_detail_router = respx.get("https://api.bilibili.com/pgc/view/web/season?season_id=39719")
|
||||
bili_bangumi_router.mock(return_value=Response(200, json=get_json("bilibili-gangumi-hanhua0.json")))
|
||||
bilibili_main_page_router = respx.get("https://www.bilibili.com/")
|
||||
bilibili_main_page_router.mock(return_value=Response(200))
|
||||
target = Target("28235413")
|
||||
@@ -61,14 +49,8 @@ async def test_fetch_bilibili_bangumi_status(
|
||||
res = await bili_bangumi.fetch_new_post(target, [dummy_user_subinfo])
|
||||
assert len(res) == 0
|
||||
|
||||
bili_bangumi_router.mock(
|
||||
return_value=Response(200, json=get_json("bilibili-gangumi-hanhua1.json"))
|
||||
)
|
||||
bili_bangumi_detail_router.mock(
|
||||
return_value=Response(
|
||||
200, json=get_json("bilibili-gangumi-hanhua1-detail.json")
|
||||
)
|
||||
)
|
||||
bili_bangumi_router.mock(return_value=Response(200, json=get_json("bilibili-gangumi-hanhua1.json")))
|
||||
bili_bangumi_detail_router.mock(return_value=Response(200, json=get_json("bilibili-gangumi-hanhua1-detail.json")))
|
||||
res2 = await bili_bangumi.fetch_new_post(target, [dummy_user_subinfo])
|
||||
|
||||
post = res2[0][1][0]
|
||||
@@ -76,7 +58,5 @@ async def test_fetch_bilibili_bangumi_status(
|
||||
assert post.text == "《汉化日记 第三季》第2话 什么是战区导弹防御系统工作日"
|
||||
assert post.url == "https://www.bilibili.com/bangumi/play/ep519207"
|
||||
assert post.target_name == "汉化日记 第三季"
|
||||
assert post.pics == [
|
||||
"http://i0.hdslb.com/bfs/archive/ea0a302c954f9dbc3d593e676486396c551529c9.jpg"
|
||||
]
|
||||
assert post.compress == True
|
||||
assert post.pics == ["http://i0.hdslb.com/bfs/archive/ea0a302c954f9dbc3d593e676486396c551529c9.jpg"]
|
||||
assert post.compress is True
|
||||
|
||||
@@ -2,21 +2,21 @@ from copy import deepcopy
|
||||
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import AsyncClient, Response
|
||||
from nonebug.app import App
|
||||
from httpx import Response, AsyncClient
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def bili_live(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
return platform_manager["bilibili-live"](ProcessContext(), AsyncClient())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def dummy_only_open_user_subinfo(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
@@ -77,7 +77,7 @@ async def test_fetch_first_live(bili_live, dummy_only_open_user_subinfo):
|
||||
assert post.pics == [
|
||||
"https://i0.hdslb.com/bfs/live/new_room_cover/fd357f0f3cbbb48e9acfbcda616b946c2454c56c.jpg"
|
||||
]
|
||||
assert post.compress == True
|
||||
assert post.compress is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -85,9 +85,7 @@ async def test_fetch_first_live(bili_live, dummy_only_open_user_subinfo):
|
||||
async def test_fetch_bililive_only_live_open(bili_live, dummy_only_open_user_subinfo):
|
||||
mock_bili_live_status = get_json("bili_live_status.json")
|
||||
|
||||
bili_live_router = respx.get(
|
||||
"https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids?uids[]=13164144"
|
||||
)
|
||||
bili_live_router = respx.get("https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids?uids[]=13164144")
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
|
||||
bilibili_main_page_router = respx.get("https://www.bilibili.com/")
|
||||
@@ -106,10 +104,8 @@ async def test_fetch_bililive_only_live_open(bili_live, dummy_only_open_user_sub
|
||||
assert post.text == "[开播] 【Zc】从0挑战到15肉鸽!目前10难度"
|
||||
assert post.url == "https://live.bilibili.com/3044248"
|
||||
assert post.target_name == "魔法Zc目录 其他单机"
|
||||
assert post.pics == [
|
||||
"https://i0.hdslb.com/bfs/live/new_room_cover/fd357f0f3cbbb48e9acfbcda616b946c2454c56c.jpg"
|
||||
]
|
||||
assert post.compress == True
|
||||
assert post.pics == ["https://i0.hdslb.com/bfs/live/new_room_cover/fd357f0f3cbbb48e9acfbcda616b946c2454c56c.jpg"]
|
||||
assert post.compress is True
|
||||
# 标题变更
|
||||
mock_bili_live_status["data"][target]["title"] = "【Zc】从0挑战到15肉鸽!目前11难度"
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
@@ -124,7 +120,7 @@ async def test_fetch_bililive_only_live_open(bili_live, dummy_only_open_user_sub
|
||||
assert len(res4[0][1]) == 0
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def dummy_only_title_user_subinfo(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
@@ -134,17 +130,13 @@ def dummy_only_title_user_subinfo(app: App):
|
||||
return UserSubInfo(user=user, categories=[2], tags=[])
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.asyncio()
|
||||
@respx.mock
|
||||
async def test_fetch_bililive_only_title_change(
|
||||
bili_live, dummy_only_title_user_subinfo
|
||||
):
|
||||
async def test_fetch_bililive_only_title_change(bili_live, dummy_only_title_user_subinfo):
|
||||
mock_bili_live_status = get_json("bili_live_status.json")
|
||||
target = "13164144"
|
||||
|
||||
bili_live_router = respx.get(
|
||||
"https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids?uids[]=13164144"
|
||||
)
|
||||
bili_live_router = respx.get("https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids?uids[]=13164144")
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
|
||||
bilibili_main_page_router = respx.get("https://www.bilibili.com/")
|
||||
@@ -174,10 +166,8 @@ async def test_fetch_bililive_only_title_change(
|
||||
assert post.text == "[标题更新] 【Zc】从0挑战到15肉鸽!目前12难度"
|
||||
assert post.url == "https://live.bilibili.com/3044248"
|
||||
assert post.target_name == "魔法Zc目录 其他单机"
|
||||
assert post.pics == [
|
||||
"https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"
|
||||
]
|
||||
assert post.compress == True
|
||||
assert post.pics == ["https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"]
|
||||
assert post.compress is True
|
||||
# 直播状态更新-下播
|
||||
mock_bili_live_status["data"][target]["live_status"] = 0
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
@@ -186,7 +176,7 @@ async def test_fetch_bililive_only_title_change(
|
||||
assert len(res4[0][1]) == 0
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def dummy_only_close_user_subinfo(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
@@ -202,9 +192,7 @@ async def test_fetch_bililive_only_close(bili_live, dummy_only_close_user_subinf
|
||||
mock_bili_live_status = get_json("bili_live_status.json")
|
||||
target = "13164144"
|
||||
|
||||
bili_live_router = respx.get(
|
||||
"https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids?uids[]=13164144"
|
||||
)
|
||||
bili_live_router = respx.get("https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids?uids[]=13164144")
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
|
||||
bilibili_main_page_router = respx.get("https://www.bilibili.com/")
|
||||
@@ -241,13 +229,11 @@ async def test_fetch_bililive_only_close(bili_live, dummy_only_close_user_subinf
|
||||
assert post.text == "[下播] 【Zc】从0挑战到15肉鸽!目前12难度"
|
||||
assert post.url == "https://live.bilibili.com/3044248"
|
||||
assert post.target_name == "魔法Zc目录 其他单机"
|
||||
assert post.pics == [
|
||||
"https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"
|
||||
]
|
||||
assert post.compress == True
|
||||
assert post.pics == ["https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"]
|
||||
assert post.compress is True
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def dummy_bililive_user_subinfo(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
@@ -263,9 +249,7 @@ async def test_fetch_bililive_combo(bili_live, dummy_bililive_user_subinfo):
|
||||
mock_bili_live_status = get_json("bili_live_status.json")
|
||||
target = "13164144"
|
||||
|
||||
bili_live_router = respx.get(
|
||||
"https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids?uids[]=13164144"
|
||||
)
|
||||
bili_live_router = respx.get("https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids?uids[]=13164144")
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
|
||||
bilibili_main_page_router = respx.get("https://www.bilibili.com/")
|
||||
@@ -289,10 +273,8 @@ async def test_fetch_bililive_combo(bili_live, dummy_bililive_user_subinfo):
|
||||
assert post2.text == "[开播] 【Zc】从0挑战到15肉鸽!目前11难度"
|
||||
assert post2.url == "https://live.bilibili.com/3044248"
|
||||
assert post2.target_name == "魔法Zc目录 其他单机"
|
||||
assert post2.pics == [
|
||||
"https://i0.hdslb.com/bfs/live/new_room_cover/fd357f0f3cbbb48e9acfbcda616b946c2454c56c.jpg"
|
||||
]
|
||||
assert post2.compress == True
|
||||
assert post2.pics == ["https://i0.hdslb.com/bfs/live/new_room_cover/fd357f0f3cbbb48e9acfbcda616b946c2454c56c.jpg"]
|
||||
assert post2.compress is True
|
||||
# 标题变更
|
||||
mock_bili_live_status["data"][target]["title"] = "【Zc】从0挑战到15肉鸽!目前12难度"
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
@@ -302,10 +284,8 @@ async def test_fetch_bililive_combo(bili_live, dummy_bililive_user_subinfo):
|
||||
assert post3.text == "[标题更新] 【Zc】从0挑战到15肉鸽!目前12难度"
|
||||
assert post3.url == "https://live.bilibili.com/3044248"
|
||||
assert post3.target_name == "魔法Zc目录 其他单机"
|
||||
assert post3.pics == [
|
||||
"https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"
|
||||
]
|
||||
assert post3.compress == True
|
||||
assert post3.pics == ["https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"]
|
||||
assert post3.compress is True
|
||||
# 直播状态更新-下播
|
||||
mock_bili_live_status["data"][target]["live_status"] = 0
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
@@ -315,7 +295,5 @@ async def test_fetch_bililive_combo(bili_live, dummy_bililive_user_subinfo):
|
||||
assert post4.text == "[下播] 【Zc】从0挑战到15肉鸽!目前12难度"
|
||||
assert post4.url == "https://live.bilibili.com/3044248"
|
||||
assert post4.target_name == "魔法Zc目录 其他单机"
|
||||
assert post4.pics == [
|
||||
"https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"
|
||||
]
|
||||
assert post4.compress == True
|
||||
assert post4.pics == ["https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"]
|
||||
assert post4.compress is True
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import AsyncClient, Response
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
from httpx import Response, AsyncClient
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def ff14(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
return platform_manager["ff14"](ProcessContext(), AsyncClient())
|
||||
|
||||
@@ -26,9 +26,7 @@ def ff14_newdata_json_1():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_fetch_new(
|
||||
ff14, dummy_user_subinfo, ff14_newdata_json_0, ff14_newdata_json_1
|
||||
):
|
||||
async def test_fetch_new(ff14, dummy_user_subinfo, ff14_newdata_json_0, ff14_newdata_json_1):
|
||||
newdata = respx.get(
|
||||
"https://cqnews.web.sdo.com/api/news/newsList?gameCode=ff&CategoryCode=5309,5310,5311,5312,5313&pageIndex=0&pageSize=5"
|
||||
)
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import pytest
|
||||
import respx
|
||||
import pytest
|
||||
from flaky import flaky
|
||||
from httpx import AsyncClient, Response
|
||||
from nonebug.app import App
|
||||
from httpx import Response, AsyncClient
|
||||
|
||||
from .utils import get_file, get_json
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def mcbbsnews(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
return platform_manager["mcbbsnews"](ProcessContext(), AsyncClient())
|
||||
|
||||
@@ -26,26 +26,14 @@ def raw_post_list():
|
||||
@flaky(max_runs=3, min_passes=1)
|
||||
async def test_fetch_new(mcbbsnews, dummy_user_subinfo, raw_post_list):
|
||||
news_router = respx.get("https://www.mcbbs.net/forum-news-1.html")
|
||||
news_router.mock(
|
||||
return_value=Response(
|
||||
200, text=get_file("mcbbsnews/mock/mcbbsnews_post_list_html-0.html")
|
||||
)
|
||||
)
|
||||
news_router.mock(return_value=Response(200, text=get_file("mcbbsnews/mock/mcbbsnews_post_list_html-0.html")))
|
||||
new_post = respx.get("https://www.mcbbs.net/thread-1340927-1-1.html")
|
||||
new_post.mock(
|
||||
return_value=Response(
|
||||
200, text=get_file("mcbbsnews/mock/mcbbsnews_new_post_html.html")
|
||||
)
|
||||
)
|
||||
new_post.mock(return_value=Response(200, text=get_file("mcbbsnews/mock/mcbbsnews_new_post_html.html")))
|
||||
target = ""
|
||||
res = await mcbbsnews.fetch_new_post(target, [dummy_user_subinfo])
|
||||
assert news_router.called
|
||||
assert len(res) == 0
|
||||
news_router.mock(
|
||||
return_value=Response(
|
||||
200, text=get_file("mcbbsnews/mock/mcbbsnews_post_list_html-1.html")
|
||||
)
|
||||
)
|
||||
news_router.mock(return_value=Response(200, text=get_file("mcbbsnews/mock/mcbbsnews_post_list_html-1.html")))
|
||||
res = await mcbbsnews.fetch_new_post(target, [dummy_user_subinfo])
|
||||
assert news_router.called
|
||||
post = res[0][1][0]
|
||||
@@ -63,20 +51,12 @@ async def test_fetch_new(mcbbsnews, dummy_user_subinfo, raw_post_list):
|
||||
@flaky(max_runs=3, min_passes=1)
|
||||
async def test_news_render(mcbbsnews, dummy_user_subinfo):
|
||||
new_post = respx.get("https://www.mcbbs.net/thread-1340927-1-1.html")
|
||||
new_post.mock(
|
||||
return_value=Response(
|
||||
200, text=get_file("mcbbsnews/mock/mcbbsnews_new_post_html.html")
|
||||
)
|
||||
)
|
||||
pics = await mcbbsnews._news_render(
|
||||
"https://www.mcbbs.net/thread-1340927-1-1.html", "#post_25849603"
|
||||
)
|
||||
new_post.mock(return_value=Response(200, text=get_file("mcbbsnews/mock/mcbbsnews_new_post_html.html")))
|
||||
pics = await mcbbsnews._news_render("https://www.mcbbs.net/thread-1340927-1-1.html", "#post_25849603")
|
||||
assert len(pics) == 1
|
||||
|
||||
pics_err_on_assert = await mcbbsnews._news_render("", "##post_25849603")
|
||||
assert len(pics_err_on_assert) == 2
|
||||
|
||||
pics_err_on_other = await mcbbsnews._news_render(
|
||||
"https://www.mcbbs.net/thread-1340927-1-1.html", "#post_err"
|
||||
)
|
||||
pics_err_on_other = await mcbbsnews._news_render("https://www.mcbbs.net/thread-1340927-1-1.html", "#post_err")
|
||||
assert len(pics_err_on_other) == 2
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import time
|
||||
import typing
|
||||
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import AsyncClient, Response
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
from httpx import Response, AsyncClient
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
@@ -12,10 +12,10 @@ if typing.TYPE_CHECKING:
|
||||
from nonebot_bison.platform.ncm import NcmArtist
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def ncm_artist(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
return platform_manager["ncm-artist"](ProcessContext(), AsyncClient())
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import time
|
||||
import typing
|
||||
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import AsyncClient, Response
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
from httpx import Response, AsyncClient
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
@@ -12,10 +12,10 @@ if typing.TYPE_CHECKING:
|
||||
from nonebot_bison.platform.ncm import NcmRadio
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def ncm_radio(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
return platform_manager["ncm-radio"](ProcessContext(), AsyncClient())
|
||||
|
||||
@@ -50,13 +50,10 @@ async def test_fetch_new(ncm_radio, ncm_radio_0, ncm_radio_1, dummy_user_subinfo
|
||||
ncm_router.mock(return_value=Response(200, json=ncm_radio_1))
|
||||
res2 = await ncm_radio.fetch_new_post(target, [dummy_user_subinfo])
|
||||
post = res2[0][1][0]
|
||||
print(post)
|
||||
assert post.target_type == "ncm-radio"
|
||||
assert post.text == "网易云电台更新:「松烟行动」灰齐山麓"
|
||||
assert post.url == "https://music.163.com/#/program/2494997688"
|
||||
assert post.pics == [
|
||||
"http://p1.music.126.net/H5em5xUNIYXcjJhOmeaSqQ==/109951166647436789.jpg"
|
||||
]
|
||||
assert post.pics == ["http://p1.music.126.net/H5em5xUNIYXcjJhOmeaSqQ==/109951166647436789.jpg"]
|
||||
assert post.target_name == "《明日方舟》游戏原声OST"
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
from time import time
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
from nonebug.app import App
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nonebot_bison.platform import Platform
|
||||
from httpx import AsyncClient
|
||||
|
||||
now = time()
|
||||
passed = now - 3 * 60 * 60
|
||||
|
||||
raw_post_list_1 = [
|
||||
{"id": 1, "text": "p1", "date": now, "tags": ["tag1"], "category": 1}
|
||||
]
|
||||
raw_post_list_1 = [{"id": 1, "text": "p1", "date": now, "tags": ["tag1"], "category": 1}]
|
||||
|
||||
raw_post_list_2 = raw_post_list_1 + [
|
||||
{"id": 2, "text": "p2", "date": now, "tags": ["tag1"], "category": 1},
|
||||
@@ -22,7 +17,7 @@ raw_post_list_2 = raw_post_list_1 + [
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def dummy_user(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
@@ -30,7 +25,7 @@ def dummy_user(app: App):
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def user_info_factory(app: App, dummy_user):
|
||||
from nonebot_bison.types import UserSubInfo
|
||||
|
||||
@@ -40,14 +35,13 @@ def user_info_factory(app: App, dummy_user):
|
||||
return _user_info
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def mock_platform_without_cats_tags(app: App):
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import RawPost, Target
|
||||
from nonebot_bison.types import Target, RawPost
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
|
||||
class MockPlatform(NewMessage):
|
||||
|
||||
platform_name = "mock_platform"
|
||||
name = "Mock Platform"
|
||||
enabled = True
|
||||
@@ -88,21 +82,19 @@ def mock_platform_without_cats_tags(app: App):
|
||||
return MockPlatform
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def mock_platform(app: App):
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Category, RawPost, Tag, Target
|
||||
from nonebot_bison.utils import SchedulerConfig
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.types import Tag, Target, RawPost, Category
|
||||
|
||||
class MockPlatformSchedConf(SchedulerConfig):
|
||||
|
||||
name = "mock"
|
||||
schedule_type = "interval"
|
||||
schedule_setting = {"seconds": 100}
|
||||
|
||||
class MockPlatform(NewMessage):
|
||||
|
||||
platform_name = "mock_platform"
|
||||
name = "Mock Platform"
|
||||
enabled = True
|
||||
@@ -152,12 +144,11 @@ def mock_platform(app: App):
|
||||
return MockPlatform
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def mock_scheduler_conf(app):
|
||||
from nonebot_bison.utils import SchedulerConfig
|
||||
|
||||
class MockPlatformSchedConf(SchedulerConfig):
|
||||
|
||||
name = "mock"
|
||||
schedule_type = "interval"
|
||||
schedule_setting = {"seconds": 100}
|
||||
@@ -165,14 +156,13 @@ def mock_scheduler_conf(app):
|
||||
return MockPlatformSchedConf
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def mock_platform_no_target(app: App, mock_scheduler_conf):
|
||||
from nonebot_bison.platform.platform import CategoryNotSupport, NewMessage
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Category, RawPost, Tag, Target
|
||||
from nonebot_bison.types import Tag, Target, RawPost, Category
|
||||
from nonebot_bison.platform.platform import NewMessage, CategoryNotSupport
|
||||
|
||||
class MockPlatform(NewMessage):
|
||||
|
||||
platform_name = "mock_platform"
|
||||
name = "Mock Platform"
|
||||
enabled = True
|
||||
@@ -221,15 +211,13 @@ def mock_platform_no_target(app: App, mock_scheduler_conf):
|
||||
return MockPlatform
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def mock_platform_no_target_2(app: App, mock_scheduler_conf):
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Category, RawPost, Tag, Target
|
||||
from nonebot_bison.utils import SchedulerConfig
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.types import Tag, Target, RawPost, Category
|
||||
|
||||
class MockPlatform(NewMessage):
|
||||
|
||||
platform_name = "mock_platform"
|
||||
name = "Mock Platform"
|
||||
enabled = True
|
||||
@@ -270,9 +258,7 @@ def mock_platform_no_target_2(app: App, mock_scheduler_conf):
|
||||
|
||||
@classmethod
|
||||
async def get_sub_list(cls, _: "Target"):
|
||||
list_1 = [
|
||||
{"id": 5, "text": "p5", "date": now, "tags": ["tag1"], "category": 4}
|
||||
]
|
||||
list_1 = [{"id": 5, "text": "p5", "date": now, "tags": ["tag1"], "category": 4}]
|
||||
|
||||
list_2 = list_1 + [
|
||||
{"id": 6, "text": "p6", "date": now, "tags": ["tag1"], "category": 4},
|
||||
@@ -287,14 +273,13 @@ def mock_platform_no_target_2(app: App, mock_scheduler_conf):
|
||||
return MockPlatform
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def mock_status_change(app: App):
|
||||
from nonebot_bison.platform.platform import StatusChange
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Category, RawPost, Tag, Target
|
||||
from nonebot_bison.platform.platform import StatusChange
|
||||
from nonebot_bison.types import Target, RawPost, Category
|
||||
|
||||
class MockPlatform(StatusChange):
|
||||
|
||||
platform_name = "mock_platform"
|
||||
name = "Mock Platform"
|
||||
enabled = True
|
||||
@@ -322,9 +307,9 @@ def mock_status_change(app: App):
|
||||
return {"s": False}
|
||||
|
||||
def compare_status(self, target, old_status, new_status) -> list["RawPost"]:
|
||||
if old_status["s"] == False and new_status["s"] == True:
|
||||
if old_status["s"] is False and new_status["s"] is True:
|
||||
return [{"text": "on", "cat": 1}]
|
||||
elif old_status["s"] == True and new_status["s"] == False:
|
||||
elif old_status["s"] is True and new_status["s"] is False:
|
||||
return [{"text": "off", "cat": 2}]
|
||||
return []
|
||||
|
||||
@@ -338,18 +323,14 @@ def mock_status_change(app: App):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_new_message_target_without_cats_tags(
|
||||
mock_platform_without_cats_tags, user_info_factory
|
||||
):
|
||||
async def test_new_message_target_without_cats_tags(mock_platform_without_cats_tags, user_info_factory):
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
|
||||
res1 = await mock_platform_without_cats_tags(
|
||||
ProcessContext(), AsyncClient()
|
||||
).fetch_new_post("dummy", [user_info_factory([1, 2], [])])
|
||||
res1 = await mock_platform_without_cats_tags(ProcessContext(), AsyncClient()).fetch_new_post(
|
||||
"dummy", [user_info_factory([1, 2], [])]
|
||||
)
|
||||
assert len(res1) == 0
|
||||
res2 = await mock_platform_without_cats_tags(
|
||||
ProcessContext(), AsyncClient()
|
||||
).fetch_new_post(
|
||||
res2 = await mock_platform_without_cats_tags(ProcessContext(), AsyncClient()).fetch_new_post(
|
||||
"dummy",
|
||||
[
|
||||
user_info_factory([], []),
|
||||
@@ -358,8 +339,10 @@ async def test_new_message_target_without_cats_tags(
|
||||
assert len(res2) == 1
|
||||
posts_1 = res2[0][1]
|
||||
assert len(posts_1) == 3
|
||||
id_set_1 = set(map(lambda x: x.text, posts_1))
|
||||
assert "p2" in id_set_1 and "p3" in id_set_1 and "p4" in id_set_1
|
||||
id_set_1 = {x.text for x in posts_1}
|
||||
assert "p2" in id_set_1
|
||||
assert "p3" in id_set_1
|
||||
assert "p4" in id_set_1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -385,10 +368,11 @@ async def test_new_message_target(mock_platform, user_info_factory):
|
||||
assert len(posts_1) == 2
|
||||
assert len(posts_2) == 1
|
||||
assert len(posts_3) == 1
|
||||
id_set_1 = set(map(lambda x: x.text, posts_1))
|
||||
id_set_2 = set(map(lambda x: x.text, posts_2))
|
||||
id_set_3 = set(map(lambda x: x.text, posts_3))
|
||||
assert "p2" in id_set_1 and "p3" in id_set_1
|
||||
id_set_1 = {x.text for x in posts_1}
|
||||
id_set_2 = {x.text for x in posts_2}
|
||||
id_set_3 = {x.text for x in posts_3}
|
||||
assert "p2" in id_set_1
|
||||
assert "p3" in id_set_1
|
||||
assert "p2" in id_set_2
|
||||
assert "p2" in id_set_3
|
||||
|
||||
@@ -397,13 +381,11 @@ async def test_new_message_target(mock_platform, user_info_factory):
|
||||
async def test_new_message_no_target(mock_platform_no_target, user_info_factory):
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
|
||||
res1 = await mock_platform_no_target(
|
||||
ProcessContext(), AsyncClient()
|
||||
).fetch_new_post("dummy", [user_info_factory([1, 2], [])])
|
||||
res1 = await mock_platform_no_target(ProcessContext(), AsyncClient()).fetch_new_post(
|
||||
"dummy", [user_info_factory([1, 2], [])]
|
||||
)
|
||||
assert len(res1) == 0
|
||||
res2 = await mock_platform_no_target(
|
||||
ProcessContext(), AsyncClient()
|
||||
).fetch_new_post(
|
||||
res2 = await mock_platform_no_target(ProcessContext(), AsyncClient()).fetch_new_post(
|
||||
"dummy",
|
||||
[
|
||||
user_info_factory([1, 2], []),
|
||||
@@ -418,15 +400,16 @@ async def test_new_message_no_target(mock_platform_no_target, user_info_factory)
|
||||
assert len(posts_1) == 2
|
||||
assert len(posts_2) == 1
|
||||
assert len(posts_3) == 1
|
||||
id_set_1 = set(map(lambda x: x.text, posts_1))
|
||||
id_set_2 = set(map(lambda x: x.text, posts_2))
|
||||
id_set_3 = set(map(lambda x: x.text, posts_3))
|
||||
assert "p2" in id_set_1 and "p3" in id_set_1
|
||||
id_set_1 = {x.text for x in posts_1}
|
||||
id_set_2 = {x.text for x in posts_2}
|
||||
id_set_3 = {x.text for x in posts_3}
|
||||
assert "p2" in id_set_1
|
||||
assert "p3" in id_set_1
|
||||
assert "p2" in id_set_2
|
||||
assert "p2" in id_set_3
|
||||
res3 = await mock_platform_no_target(
|
||||
ProcessContext(), AsyncClient()
|
||||
).fetch_new_post("dummy", [user_info_factory([1, 2], [])])
|
||||
res3 = await mock_platform_no_target(ProcessContext(), AsyncClient()).fetch_new_post(
|
||||
"dummy", [user_info_factory([1, 2], [])]
|
||||
)
|
||||
assert len(res3) == 0
|
||||
|
||||
|
||||
@@ -469,23 +452,22 @@ async def test_group(
|
||||
mock_platform_no_target_2,
|
||||
user_info_factory,
|
||||
):
|
||||
|
||||
from nonebot_bison.types import Target
|
||||
from nonebot_bison.utils import ProcessContext, http_client
|
||||
from nonebot_bison.platform.platform import make_no_target_group
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Category, RawPost, Tag, Target
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
|
||||
group_platform_class = make_no_target_group(
|
||||
[mock_platform_no_target, mock_platform_no_target_2]
|
||||
)
|
||||
group_platform = group_platform_class(ProcessContext(), None)
|
||||
res1 = await group_platform.fetch_new_post("dummy", [user_info_factory([1, 4], [])])
|
||||
dummy = Target("dummy")
|
||||
|
||||
group_platform_class = make_no_target_group([mock_platform_no_target, mock_platform_no_target_2])
|
||||
group_platform = group_platform_class(ProcessContext(), http_client())
|
||||
res1 = await group_platform.fetch_new_post(dummy, [user_info_factory([1, 4], [])])
|
||||
assert len(res1) == 0
|
||||
res2 = await group_platform.fetch_new_post("dummy", [user_info_factory([1, 4], [])])
|
||||
res2 = await group_platform.fetch_new_post(dummy, [user_info_factory([1, 4], [])])
|
||||
assert len(res2) == 1
|
||||
posts = res2[0][1]
|
||||
assert len(posts) == 2
|
||||
id_set_2 = set(map(lambda x: x.text, posts))
|
||||
assert "p2" in id_set_2 and "p6" in id_set_2
|
||||
res3 = await group_platform.fetch_new_post("dummy", [user_info_factory([1, 4], [])])
|
||||
id_set_2 = {x.text for x in posts}
|
||||
assert "p2" in id_set_2
|
||||
assert "p6" in id_set_2
|
||||
res3 = await group_platform.fetch_new_post(dummy, [user_info_factory([1, 4], [])])
|
||||
assert len(res3) == 0
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
import typing
|
||||
from datetime import datetime
|
||||
|
||||
import feedparser
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import AsyncClient, Response
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
import feedparser
|
||||
from pytz import timezone
|
||||
from nonebug.app import App
|
||||
from httpx import Response, AsyncClient
|
||||
|
||||
from .utils import get_file, get_json
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from nonebot_bison.platform.weibo import Weibo
|
||||
|
||||
image_cdn_router = respx.route(
|
||||
host__regex=r"wx\d.sinaimg.cn", path__startswith="/large/"
|
||||
)
|
||||
image_cdn_router = respx.route(host__regex=r"wx\d.sinaimg.cn", path__startswith="/large/")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def weibo(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
return platform_manager["weibo"](ProcessContext(), AsyncClient())
|
||||
|
||||
@@ -34,12 +32,8 @@ def weibo_ak_list_1():
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_get_name(weibo):
|
||||
profile_router = respx.get(
|
||||
"https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937"
|
||||
)
|
||||
profile_router.mock(
|
||||
return_value=Response(200, json=get_json("weibo_ak_profile.json"))
|
||||
)
|
||||
profile_router = respx.get("https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937")
|
||||
profile_router.mock(return_value=Response(200, json=get_json("weibo_ak_profile.json")))
|
||||
name = await weibo.get_target_name(AsyncClient(), "6279793937")
|
||||
assert name == "明日方舟Arknights"
|
||||
|
||||
@@ -47,16 +41,10 @@ async def test_get_name(weibo):
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_fetch_new(weibo, dummy_user_subinfo):
|
||||
ak_list_router = respx.get(
|
||||
"https://m.weibo.cn/api/container/getIndex?containerid=1076036279793937"
|
||||
)
|
||||
ak_list_router = respx.get("https://m.weibo.cn/api/container/getIndex?containerid=1076036279793937")
|
||||
detail_router = respx.get("https://m.weibo.cn/detail/4649031014551911")
|
||||
ak_list_router.mock(
|
||||
return_value=Response(200, json=get_json("weibo_ak_list_0.json"))
|
||||
)
|
||||
detail_router.mock(
|
||||
return_value=Response(200, text=get_file("weibo_detail_4649031014551911"))
|
||||
)
|
||||
ak_list_router.mock(return_value=Response(200, json=get_json("weibo_ak_list_0.json")))
|
||||
detail_router.mock(return_value=Response(200, text=get_file("weibo_detail_4649031014551911")))
|
||||
image_cdn_router.mock(Response(200, content=b""))
|
||||
target = "6279793937"
|
||||
res = await weibo.fetch_new_post(target, [dummy_user_subinfo])
|
||||
@@ -67,9 +55,9 @@ async def test_fetch_new(weibo, dummy_user_subinfo):
|
||||
ak_list_router.mock(return_value=Response(200, json=mock_data))
|
||||
res2 = await weibo.fetch_new_post(target, [dummy_user_subinfo])
|
||||
assert len(res2) == 0
|
||||
mock_data["data"]["cards"][1]["mblog"]["created_at"] = datetime.now(
|
||||
timezone("Asia/Shanghai")
|
||||
).strftime("%a %b %d %H:%M:%S %z %Y")
|
||||
mock_data["data"]["cards"][1]["mblog"]["created_at"] = datetime.now(timezone("Asia/Shanghai")).strftime(
|
||||
"%a %b %d %H:%M:%S %z %Y"
|
||||
)
|
||||
ak_list_router.mock(return_value=Response(200, json=mock_data))
|
||||
res3 = await weibo.fetch_new_post(target, [dummy_user_subinfo])
|
||||
assert len(res3[0][1]) == 1
|
||||
@@ -100,12 +88,10 @@ async def test_classification(weibo):
|
||||
@respx.mock
|
||||
async def test_parse_long(weibo):
|
||||
detail_router = respx.get("https://m.weibo.cn/detail/4645748019299849")
|
||||
detail_router.mock(
|
||||
return_value=Response(200, text=get_file("weibo_detail_4645748019299849"))
|
||||
)
|
||||
detail_router.mock(return_value=Response(200, text=get_file("weibo_detail_4645748019299849")))
|
||||
raw_post = get_json("weibo_ak_list_1.json")["data"]["cards"][0]
|
||||
post = await weibo.parse(raw_post)
|
||||
assert not "全文" in post.text
|
||||
assert "全文" not in post.text
|
||||
assert detail_router.called
|
||||
|
||||
|
||||
@@ -122,7 +108,7 @@ async def test_rsshub_compare(weibo):
|
||||
posts = []
|
||||
for raw_post in raw_posts:
|
||||
posts.append(await weibo.parse(raw_post))
|
||||
url_set = set(map(lambda x: x.url, posts))
|
||||
url_set = {x.url for x in posts}
|
||||
feedres = feedparser.parse("https://rsshub.app/weibo/user/6279793937")
|
||||
for entry in feedres.entries[:5]:
|
||||
# print(entry)
|
||||
@@ -131,7 +117,7 @@ async def test_rsshub_compare(weibo):
|
||||
|
||||
test_post = {
|
||||
"mblog": {
|
||||
"text": '<a href="https://m.weibo.cn/search?containerid=231522type%3D1%26t%3D10%26q%3D%23%E5%88%9A%E5%87%BA%E7%94%9F%E7%9A%84%E5%B0%8F%E7%BE%8A%E9%A9%BC%E9%95%BF%E5%95%A5%E6%A0%B7%23&extparam=%23%E5%88%9A%E5%87%BA%E7%94%9F%E7%9A%84%E5%B0%8F%E7%BE%8A%E9%A9%BC%E9%95%BF%E5%95%A5%E6%A0%B7%23&luicode=10000011&lfid=1076036003966749" data-hide=""><span class="surl-text">#刚出生的小羊驼长啥样#</span></a> <br />小羊驼三三来也<span class="url-icon"><img alt=[好喜欢] src="https://h5.sinaimg.cn/m/emoticon/icon/lxh/lxh_haoxihuan-51860b62e6.png" style="width:1em; height:1em;" /></span><br /><a href="https://m.weibo.cn/p/index?extparam=%E5%B0%8F%E7%BE%8A%E9%A9%BC%E4%B8%89%E4%B8%89&containerid=1008085ae16d2046db677de1b8491d2b708597&luicode=10000011&lfid=1076036003966749" data-hide=""><span class=\'url-icon\'><img style=\'width: 1rem;height: 1rem\' src=\'https://n.sinaimg.cn/photo/5213b46e/20180926/timeline_card_small_super_default.png\'></span><span class="surl-text">小羊驼三三</span></a> ',
|
||||
"text": '<a href="https://m.weibo.cn/search?containerid=231522type%3D1%26t%3D10%26q%3D%23%E5%88%9A%E5%87%BA%E7%94%9F%E7%9A%84%E5%B0%8F%E7%BE%8A%E9%A9%BC%E9%95%BF%E5%95%A5%E6%A0%B7%23&extparam=%23%E5%88%9A%E5%87%BA%E7%94%9F%E7%9A%84%E5%B0%8F%E7%BE%8A%E9%A9%BC%E9%95%BF%E5%95%A5%E6%A0%B7%23&luicode=10000011&lfid=1076036003966749" data-hide=""><span class="surl-text">#刚出生的小羊驼长啥样#</span></a> <br />小羊驼三三来也<span class="url-icon"><img alt=[好喜欢] src="https://h5.sinaimg.cn/m/emoticon/icon/lxh/lxh_haoxihuan-51860b62e6.png" style="width:1em; height:1em;" /></span><br /><a href="https://m.weibo.cn/p/index?extparam=%E5%B0%8F%E7%BE%8A%E9%A9%BC%E4%B8%89%E4%B8%89&containerid=1008085ae16d2046db677de1b8491d2b708597&luicode=10000011&lfid=1076036003966749" data-hide=""><span class=\'url-icon\'><img style=\'width: 1rem;height: 1rem\' src=\'https://n.sinaimg.cn/photo/5213b46e/20180926/timeline_card_small_super_default.png\'></span><span class="surl-text">小羊驼三三</span></a> ', # noqa
|
||||
"bid": "KnssqeqKK",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ path = Path(__file__).parent / "static"
|
||||
|
||||
|
||||
def get_json(file_name: str):
|
||||
with open(path / file_name, "r", encoding="utf8") as f:
|
||||
with open(path / file_name, encoding="utf8") as f:
|
||||
file_text = f.read()
|
||||
return json.loads(file_text)
|
||||
|
||||
|
||||
def get_file(file_name: str):
|
||||
with open(path / file_name, "r", encoding="utf8") as f:
|
||||
with open(path / file_name, encoding="utf8") as f:
|
||||
file_text = f.read()
|
||||
return file_text
|
||||
|
||||
Reference in New Issue
Block a user