nonebot-bison/tests/sub_manager/test_no_permission.py
suyiiyii d6205867b8
无权限用户尝试添加订阅时返回提示信息 (#617)
*  无权限用户尝试添加订阅时返回提示信息

*  添加no_permission_matcher相关的单元测试

* 🐛 优化无权限提示的排版

* 🐛 移除没有必要的命令
2024-09-01 22:32:47 +08:00

46 lines
1.6 KiB
Python

import pytest
from nonebug import App
from ..utils import BotReply, fake_admin_user, fake_group_message_event
@pytest.mark.asyncio
async def test_with_permission(app: App):
from nonebot.adapters.onebot.v11.bot import Bot
from nonebot.adapters.onebot.v11.message import Message
from nonebot_bison.platform import platform_manager
from nonebot_bison.sub_manager import add_sub_matcher, common_platform, no_permission_matcher
async with app.test_matcher([add_sub_matcher, no_permission_matcher]) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event(message=Message("添加订阅"), sender=fake_admin_user, to_me=True)
ctx.receive_event(bot, event)
ctx.should_call_send(
event,
BotReply.add_reply_on_platform(platform_manager, common_platform),
True,
)
ctx.should_pass_rule()
ctx.should_pass_permission()
@pytest.mark.asyncio
async def test_without_permission(app: App):
from nonebot.adapters.onebot.v11.bot import Bot
from nonebot.adapters.onebot.v11.message import Message
from nonebot_bison.sub_manager import add_sub_matcher, no_permission_matcher
async with app.test_matcher([add_sub_matcher, no_permission_matcher]) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event(message=Message("添加订阅"), to_me=True)
ctx.receive_event(bot, event)
ctx.should_call_send(
event,
BotReply.no_permission,
True,
)
ctx.should_pass_rule()
ctx.should_pass_permission()