This commit is contained in:
felinae98 2022-02-18 00:49:33 +08:00
parent 906fc1814d
commit fd7acea51a
No known key found for this signature in database
GPG Key ID: 00C8B010587FF610

View File

@ -134,6 +134,139 @@ async def test_add_with_target(app: App):
assert sub["target_name"] == "明日方舟Arknights"
@pytest.mark.asyncio
@respx.mock
async def test_add_with_target_no_cat(app: App):
from nonebot.adapters.onebot.v11.event import Sender
from nonebot.adapters.onebot.v11.message import Message
from nonebot_bison.config import Config
from nonebot_bison.config_manager import add_sub_matcher, common_platform
from nonebot_bison.platform import platform_manager
config = Config()
config.user_target.truncate()
ncm_router = respx.get("https://music.163.com/api/artist/albums/32540734")
ncm_router.mock(return_value=Response(200, json=get_json("ncm_siren.json")))
async with app.test_matcher(add_sub_matcher) as ctx:
bot = ctx.create_bot()
event_1 = fake_group_message_event(
message=Message("添加订阅"),
sender=Sender(card="", nickname="test", role="admin"),
to_me=True,
)
ctx.receive_event(bot, event_1)
ctx.should_pass_rule()
ctx.should_call_send(
event_1,
Message(
"请输入想要订阅的平台,目前支持,请输入冒号左边的名称:\n"
+ "".join(
[
"{}{}\n".format(
platform_name, platform_manager[platform_name].name
)
for platform_name in common_platform
]
)
+ "要查看全部平台请输入:“全部”"
),
True,
)
event_3 = fake_group_message_event(
message=Message("ncm-artist"), sender=fake_admin_user
)
ctx.receive_event(bot, event_3)
ctx.should_call_send(
event_3,
Message(
"请输入订阅用户的id详情查阅https://nonebot-bison.vercel.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84uid"
),
True,
)
event_4_ok = fake_group_message_event(
message=Message("32540734"), sender=fake_admin_user
)
ctx.receive_event(bot, event_4_ok)
ctx.should_call_send(event_4_ok, ("添加 塞壬唱片-MSR 成功"), True)
ctx.should_finished()
subs = config.list_subscribe(10000, "group")
assert len(subs) == 1
sub = subs[0]
assert sub["target"] == "32540734"
assert sub["tags"] == []
assert sub["cats"] == []
assert sub["target_type"] == "ncm-artist"
assert sub["target_name"] == "塞壬唱片-MSR"
@pytest.mark.asyncio
@respx.mock
async def test_add_no_target(app: App):
from nonebot.adapters.onebot.v11.event import Sender
from nonebot.adapters.onebot.v11.message import Message
from nonebot_bison.config import Config
from nonebot_bison.config_manager import add_sub_matcher, common_platform
from nonebot_bison.platform import platform_manager
config = Config()
config.user_target.truncate()
async with app.test_matcher(add_sub_matcher) as ctx:
bot = ctx.create_bot()
event_1 = fake_group_message_event(
message=Message("添加订阅"),
sender=Sender(card="", nickname="test", role="admin"),
to_me=True,
)
ctx.receive_event(bot, event_1)
ctx.should_pass_rule()
ctx.should_call_send(
event_1,
Message(
"请输入想要订阅的平台,目前支持,请输入冒号左边的名称:\n"
+ "".join(
[
"{}{}\n".format(
platform_name, platform_manager[platform_name].name
)
for platform_name in common_platform
]
)
+ "要查看全部平台请输入:“全部”"
),
True,
)
event_3 = fake_group_message_event(
message=Message("arknights"), sender=fake_admin_user
)
ctx.receive_event(bot, event_3)
ctx.should_call_send(
event_3,
Message(
"请输入要订阅的类别,以空格分隔,支持的类别有:{}".format(
" ".join(list(platform_manager["arknights"].categories.values()))
)
),
True,
)
event_4 = fake_group_message_event(
message=Message("游戏公告"), sender=fake_admin_user
)
ctx.receive_event(bot, event_4)
ctx.should_call_send(event_4, ("添加 明日方舟游戏信息 成功"), True)
ctx.should_finished()
subs = config.list_subscribe(10000, "group")
assert len(subs) == 1
sub = subs[0]
assert sub["target"] == "default"
assert sub["tags"] == []
assert sub["cats"] == [platform_manager["arknights"].reverse_category["游戏公告"]]
assert sub["target_type"] == "arknights"
assert sub["target_name"] == "明日方舟游戏信息"
@pytest.mark.asyncio
async def test_platform_name_err(app: App):
from nonebot.adapters.onebot.v11.event import Sender