From 53273d2d6f109a048ad58e22dc1113349ad25721 Mon Sep 17 00:00:00 2001 From: Azide Date: Mon, 14 Mar 2022 23:47:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=86test=5Fconfig=5Fmana?= =?UTF-8?q?ger=5Fadmin=E4=B8=AD=E7=9A=84test=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_config_manager_admin.py | 43 +++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/tests/test_config_manager_admin.py b/tests/test_config_manager_admin.py index 34f8586..1d8ebf8 100644 --- a/tests/test_config_manager_admin.py +++ b/tests/test_config_manager_admin.py @@ -1,8 +1,13 @@ +import pytest from nonebug import App -from .utils import fake_admin_user, fake_private_message_event, fake_group_message_event, fake_superuser +from .utils import ( + fake_admin_user, + fake_group_message_event, + fake_private_message_event, + fake_superuser, +) -import pytest @pytest.mark.asyncio async def test_query_with_superuser_private(app: App): @@ -28,29 +33,42 @@ async def test_query_with_superuser_private(app: App): event, Message("请选择需要管理的群:\n1. 101 - test group\n请输入左侧序号"), True ) event_1_err = fake_private_message_event( - message=Message("0"), sender=fake_superuser + message=Message("0"), + sender=fake_superuser, + to_me=True, + user_id=fake_superuser.user_id, ) ctx.receive_event(bot, event_1_err) - ctx.should_rejected() ctx.should_call_send(event_1_err, "请输入正确序号", True) + ctx.should_rejected() event_1_ok = fake_private_message_event( - message=Message("1"), sender=fake_superuser + message=Message("1"), + sender=fake_superuser, + to_me=True, + user_id=fake_superuser.user_id, ) ctx.receive_event(bot, event_1_ok) ctx.should_call_send(event_1_ok, "请输入需要使用的命令:添加订阅,查询订阅,删除订阅", True) event_2_err = fake_private_message_event( - message=Message("222"), sender=fake_superuser + message=Message("222"), + sender=fake_superuser, + to_me=True, + user_id=fake_superuser.user_id, ) ctx.receive_event(bot, event_2_err) - ctx.should_rejected() ctx.should_call_send(event_2_err, "请输入正确的命令", True) + ctx.should_rejected() event_2_ok = fake_private_message_event( - message=Message("查询订阅"), sender=fake_superuser + message=Message("查询订阅"), + sender=fake_superuser, + to_me=True, + user_id=fake_superuser.user_id, ) ctx.receive_event(bot, event_2_ok) ctx.should_pass_rule() ctx.should_pass_permission() + @pytest.mark.asyncio async def test_query_with_superuser_group_tome(app: App): from nonebot.adapters.onebot.v11.bot import Bot @@ -60,11 +78,12 @@ async def test_query_with_superuser_group_tome(app: App): async with app.test_matcher(group_manage_matcher) as ctx: bot = ctx.create_bot(base=Bot) event = fake_group_message_event( - message=Message("群管理"), sender=fake_superuser,to_me=True + message=Message("群管理"), + sender=fake_superuser, + to_me=True, + user_id=fake_superuser.user_id, ) ctx.receive_event(bot, event) ctx.should_pass_rule() ctx.should_pass_permission() - ctx.should_call_send( - event, '', True - ) \ No newline at end of file + ctx.should_call_send(event, "", True)