From 29f4abd9f4f4e166c505fe9e3bb4c6c6d906d1db Mon Sep 17 00:00:00 2001 From: Azide Date: Sun, 13 Mar 2022 01:37:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=90=E5=8A=9F=E5=BE=AE=E8=B0=83test=5Fconf?= =?UTF-8?q?ig=5Fmanager=5Fadd=E4=BD=BF=E4=B9=8Bpass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/nonebot_bison/config_manager.py | 4 +- ...ages_add.py => test_config_manager_add.py} | 45 ++++++++----------- tests/utils.py | 12 ++--- 3 files changed, 27 insertions(+), 34 deletions(-) rename tests/{test_config_manages_add.py => test_config_manager_add.py} (85%) diff --git a/src/plugins/nonebot_bison/config_manager.py b/src/plugins/nonebot_bison/config_manager.py index 3d330a6..5e00414 100644 --- a/src/plugins/nonebot_bison/config_manager.py +++ b/src/plugins/nonebot_bison/config_manager.py @@ -134,11 +134,11 @@ def do_add_sub(add_sub: Type[Matcher]): state["id"] = target state["name"] = name except (LookupError): - url="https://nonebot-bison.vercel.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84uid" + url="https://nonebot-bison.vercel.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84-uid" title="Bison所支持的平台UID" content="查询相关平台的uid格式或获取方式" image="https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg" - getId_share=f"[CQ:share,url={url},title={title},content={content},image={image}"#缩短字符串格式长度,以及方便后续修改为消息段格式 + getId_share=f"[CQ:share,url={url},title={title},content={content},image={image}]"#缩短字符串格式长度,以及方便后续修改为消息段格式 await add_sub.reject(Message(getId_share)) except (KeyboardInterrupt): await add_sub.finish("已中止订阅") diff --git a/tests/test_config_manages_add.py b/tests/test_config_manager_add.py similarity index 85% rename from tests/test_config_manages_add.py rename to tests/test_config_manager_add.py index 34ca2a8..5e80e3e 100644 --- a/tests/test_config_manages_add.py +++ b/tests/test_config_manager_add.py @@ -6,7 +6,6 @@ from nonebug.app import App from .platforms.utils import get_json from .utils import fake_admin_user, fake_group_message_event, BotReply -bot_reply=BotReply() @pytest.mark.asyncio async def test_configurable_at_me_true_failed(app: App): @@ -49,7 +48,7 @@ async def test_configurable_at_me_false(app: App): ctx.receive_event(bot, event) ctx.should_call_send( event, - bot_reply.add_reply_on_platform(platform_manager,common_platform), + Message(BotReply.add_reply_on_platform(platform_manager,common_platform)), True, ) ctx.should_pass_rule() @@ -91,7 +90,7 @@ async def test_add_with_target(app: App): ctx.should_pass_rule() ctx.should_call_send( event_1, - bot_reply.add_reply_on_platform(platform_manager,common_platform), + Message(BotReply.add_reply_on_platform(platform_manager=platform_manager,common_platform=common_platform)), True, ) event_2 = fake_group_message_event( @@ -101,7 +100,7 @@ async def test_add_with_target(app: App): ctx.should_rejected() ctx.should_call_send( event_2, - bot_reply.add_reply_on_platform_input_allplatform(platform_manager), + BotReply.add_reply_on_platform_input_allplatform(platform_manager), True, ) event_3 = fake_group_message_event( @@ -110,14 +109,14 @@ async def test_add_with_target(app: App): ctx.receive_event(bot, event_3) ctx.should_call_send( event_3, - bot_reply.add_reply_on_id, + Message(BotReply.add_reply_on_id), True, ) event_4_err = fake_group_message_event( message=Message("000"), sender=fake_admin_user ) ctx.receive_event(bot, event_4_err) - ctx.should_call_send(event_4_err, bot_reply.add_reply_on_id_input_error, True) + ctx.should_call_send(event_4_err, BotReply.add_reply_on_id_input_error, True) ctx.should_rejected() event_4_ok = fake_group_message_event( message=Message("6279793937"), sender=fake_admin_user @@ -125,30 +124,30 @@ async def test_add_with_target(app: App): ctx.receive_event(bot, event_4_ok) ctx.should_call_send( event_4_ok, - bot_reply.add_reply_on_target_confirm("weibo","明日方舟Arknights","6279793937"), + BotReply.add_reply_on_target_confirm("weibo","明日方舟Arknights","6279793937"), True ) ctx.should_call_send( event_4_ok, - bot_reply.add_reply_on_cats(platform_manager,"weibo"), + Message(BotReply.add_reply_on_cats(platform_manager,"weibo")), True, ) event_5_err = fake_group_message_event( message=Message("图文 文字 err"), sender=fake_admin_user ) ctx.receive_event(bot, event_5_err) - ctx.should_call_send(event_5_err, bot_reply.add_reply_on_cats_input_error("err"), True) + ctx.should_call_send(event_5_err, BotReply.add_reply_on_cats_input_error("err"), True) ctx.should_rejected() event_5_ok = fake_group_message_event( message=Message("图文 文字"), sender=fake_admin_user ) ctx.receive_event(bot, event_5_ok) - ctx.should_call_send(event_5_ok, bot_reply.add_reply_on_tags, True) + ctx.should_call_send(event_5_ok, Message(BotReply.add_reply_on_tags), True) event_6 = fake_group_message_event( message=Message("全部标签"), sender=fake_admin_user ) ctx.receive_event(bot, event_6) - ctx.should_call_send(event_6, bot_reply.add_reply_subscribe_success("明日方舟Arknights"), True) + ctx.should_call_send(event_6, BotReply.add_reply_subscribe_success("明日方舟Arknights"), True) ctx.should_finished() subs = config.list_subscribe(10000, "group") assert len(subs) == 1 @@ -187,7 +186,7 @@ async def test_add_with_target_no_cat(app: App): ctx.should_pass_rule() ctx.should_call_send( event_1, - bot_reply.add_reply_on_platform(platform_manager,common_platform), + Message(BotReply.add_reply_on_platform(platform_manager,common_platform)), True, ) event_3 = fake_group_message_event( @@ -196,7 +195,7 @@ async def test_add_with_target_no_cat(app: App): ctx.receive_event(bot, event_3) ctx.should_call_send( event_3, - bot_reply.add_reply_on_id, + Message(BotReply.add_reply_on_id), True, ) event_4_ok = fake_group_message_event( @@ -205,10 +204,10 @@ async def test_add_with_target_no_cat(app: App): ctx.receive_event(bot, event_4_ok) ctx.should_call_send( event_4_ok, - bot_reply.add_reply_on_target_confirm("ncm-artist","塞壬唱片-MSR","32540734"), + BotReply.add_reply_on_target_confirm("ncm-artist","塞壬唱片-MSR","32540734"), True ) - ctx.should_call_send(event_4_ok, bot_reply.add_reply_subscribe_success("塞壬唱片-MSR"), True) + ctx.should_call_send(event_4_ok, BotReply.add_reply_subscribe_success("塞壬唱片-MSR"), True) ctx.should_finished() subs = config.list_subscribe(10000, "group") assert len(subs) == 1 @@ -242,7 +241,7 @@ async def test_add_no_target(app: App): ctx.should_pass_rule() ctx.should_call_send( event_1, - bot_reply.add_reply_on_platform(platform_manager,common_platform), + Message(BotReply.add_reply_on_platform(platform_manager,common_platform)), True, ) event_3 = fake_group_message_event( @@ -251,20 +250,14 @@ async def test_add_no_target(app: App): ctx.receive_event(bot, event_3) ctx.should_call_send( event_3, - bot_reply.add_reply_on_target_confirm("arknights","明日方舟游戏信息","default") - , - True - ) - ctx.should_call_send( - event_3, - bot_reply.add_reply_on_cats(platform_manager,"arknights"), + Message(BotReply.add_reply_on_cats(platform_manager,"arknights")), 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, bot_reply.add_reply_subscribe_success("明日方舟游戏信息"), True) + ctx.should_call_send(event_4, BotReply.add_reply_subscribe_success("明日方舟游戏信息"), True) ctx.should_finished() subs = config.list_subscribe(10000, "group") assert len(subs) == 1 @@ -296,7 +289,7 @@ async def test_platform_name_err(app: App): ctx.should_pass_rule() ctx.should_call_send( event_1, - bot_reply.add_reply_on_platform(platform_manager,common_platform), + Message(BotReply.add_reply_on_platform(platform_manager,common_platform)), True, ) event_2 = fake_group_message_event( @@ -307,6 +300,6 @@ async def test_platform_name_err(app: App): ctx.should_rejected() ctx.should_call_send( event_2, - bot_reply.add_reply_on_platform_input_error, + BotReply.add_reply_on_platform_input_error, True, ) diff --git a/tests/utils.py b/tests/utils.py index 17f009f..6911ea9 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -73,7 +73,7 @@ fake_superuser = Sender(user_id=10001, nickname="superuser") from nonebot.adapters.onebot.v11.message import Message class BotReply: def add_reply_on_platform(platform_manager,common_platform): - return Message( + return ( "请输入想要订阅的平台,目前支持,请输入冒号左边的名称:\n" + "".join( [ @@ -98,20 +98,20 @@ class BotReply: search_title="Bison所支持的平台UID" search_content="查询相关平台的uid格式或获取方式" search_image="https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg" - return Message(f"[CQ:share,url={search_url},title={search_title},content={search_content},image={search_image}") + return (f"[CQ:share,url={search_url},title={search_title},content={search_content},image={search_image}") def add_reply_on_target_confirm(platform,name,id): - return Message(f"即将订阅的用户为:{platform} {name} {id}\n如有错误请输入“取消”重新订阅") + return (f"即将订阅的用户为:{platform} {name} {id}\n如有错误请输入“取消”重新订阅") def add_reply_on_cats(platform_manager,platform:str): - return Message("请输入要订阅的类别,以空格分隔,支持的类别有:{}".format( + return ("请输入要订阅的类别,以空格分隔,支持的类别有:{}".format( " ".join(list(platform_manager[platform].categories.values())))) def add_reply_on_cats_input_error(cat:str): - return Message("不支持 {}".format(cat)) + return ("不支持 {}".format(cat)) def add_reply_subscribe_success(name): - return Message("添加 {} 成功".format(name)) + return ("添加 {} 成功".format(name)) add_reply_on_id_input_error="id输入错误" add_reply_on_platform_input_error="平台输入错误"