mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-02 09:26:12 +08:00
✨ 添加no_permission_matcher相关的单元测试
This commit is contained in:
parent
85cc112599
commit
bbe5a22479
@ -124,4 +124,5 @@ __all__ = [
|
||||
"query_sub_matcher",
|
||||
"del_sub_matcher",
|
||||
"group_manage_matcher",
|
||||
"no_permission_matcher",
|
||||
]
|
||||
|
45
tests/sub_manager/test_no_permission.py
Normal file
45
tests/sub_manager/test_no_permission.py
Normal file
@ -0,0 +1,45 @@
|
||||
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()
|
@ -154,3 +154,4 @@ class BotReply:
|
||||
)
|
||||
add_reply_on_tags_need_more_info = "订阅标签直接输入标签内容\n屏蔽标签请在标签名称前添加~号\n详见https://nonebot-bison.netlify.app/usage/#%E5%B9%B3%E5%8F%B0%E8%AE%A2%E9%98%85%E6%A0%87%E7%AD%BE-tag"
|
||||
add_reply_abort = "已中止订阅"
|
||||
no_permission = "您没有权限进行此操作,请联系Bot所有者"
|
||||
|
Loading…
x
Reference in New Issue
Block a user