mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-06 20:06:12 +08:00
添加了在添加订阅过程中添加id步骤输入 查询 时bot应回复消息的test
This commit is contained in:
parent
48bca04470
commit
098aa959cc
@ -303,3 +303,79 @@ async def test_platform_name_err(app: App):
|
|||||||
BotReply.add_reply_on_platform_input_error,
|
BotReply.add_reply_on_platform_input_error,
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@respx.mock
|
||||||
|
async def test_add_with_get_id(app: App):
|
||||||
|
from nonebot.adapters.onebot.v11.event import Sender
|
||||||
|
from nonebot.adapters.onebot.v11.message import Message,MessageSegment
|
||||||
|
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()
|
||||||
|
|
||||||
|
ak_list_router = respx.get(
|
||||||
|
"https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937"
|
||||||
|
)
|
||||||
|
ak_list_router.mock(
|
||||||
|
return_value=Response(200, json=get_json("weibo_ak_profile.json"))
|
||||||
|
)
|
||||||
|
ak_list_bad_router = respx.get(
|
||||||
|
"https://m.weibo.cn/api/container/getIndex?containerid=100505000"
|
||||||
|
)
|
||||||
|
ak_list_bad_router.mock(
|
||||||
|
return_value=Response(200, json=get_json("weibo_err_profile.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(BotReply.add_reply_on_platform(platform_manager=platform_manager,common_platform=common_platform)),
|
||||||
|
True,
|
||||||
|
)
|
||||||
|
event_3 = fake_group_message_event(
|
||||||
|
message=Message("weibo"), sender=fake_admin_user
|
||||||
|
)
|
||||||
|
ctx.receive_event(bot, event_3)
|
||||||
|
ctx.should_call_send(
|
||||||
|
event_3,
|
||||||
|
Message(BotReply.add_reply_on_id),
|
||||||
|
True,
|
||||||
|
)
|
||||||
|
event_4_query = fake_group_message_event(
|
||||||
|
message=Message("查询"), sender=fake_admin_user
|
||||||
|
)
|
||||||
|
ctx.receive_event(bot, event_4_query)
|
||||||
|
ctx.should_rejected()
|
||||||
|
ctx.should_call_send(
|
||||||
|
event_4_query,
|
||||||
|
[MessageSegment(*BotReply.add_reply_on_id_input_search())],
|
||||||
|
True
|
||||||
|
)
|
||||||
|
'''
|
||||||
|
line 362:
|
||||||
|
鬼知道为什么要在这里这样写,
|
||||||
|
没有[]的话assert不了(should_call_send使用[MessageSegment(...)]的格式进行比较)
|
||||||
|
不在这里MessageSegment()的话也assert不了(指不能让add_reply_on_id_input_search直接返回一个MessageSegment对象)
|
||||||
|
amen
|
||||||
|
'''
|
||||||
|
event_abort = fake_group_message_event(
|
||||||
|
message=Message("取消"), sender=Sender(card="", nickname="test", role="admin")
|
||||||
|
)
|
||||||
|
ctx.receive_event(bot, event_abort)
|
||||||
|
ctx.should_call_send(
|
||||||
|
event_abort,
|
||||||
|
BotReply.add_reply_abort,
|
||||||
|
True,
|
||||||
|
)
|
||||||
|
ctx.should_finished()
|
@ -70,7 +70,7 @@ from nonebot.adapters.onebot.v11.event import Sender
|
|||||||
fake_admin_user = Sender(nickname="test", role="admin")
|
fake_admin_user = Sender(nickname="test", role="admin")
|
||||||
fake_superuser = Sender(user_id=10001, nickname="superuser")
|
fake_superuser = Sender(user_id=10001, nickname="superuser")
|
||||||
|
|
||||||
from nonebot.adapters.onebot.v11.message import Message
|
from nonebot.adapters.onebot.v11.message import Message,MessageSegment
|
||||||
class BotReply:
|
class BotReply:
|
||||||
def add_reply_on_platform(platform_manager,common_platform):
|
def add_reply_on_platform(platform_manager,common_platform):
|
||||||
return (
|
return (
|
||||||
@ -94,11 +94,19 @@ class BotReply:
|
|||||||
])
|
])
|
||||||
|
|
||||||
def add_reply_on_id_input_search():
|
def add_reply_on_id_input_search():
|
||||||
search_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"
|
search_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"
|
||||||
search_title="Bison所支持的平台UID"
|
search_title="Bison所支持的平台UID"
|
||||||
search_content="查询相关平台的uid格式或获取方式"
|
search_content="查询相关平台的uid格式或获取方式"
|
||||||
search_image="https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
|
search_image="https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
|
||||||
return (f"[CQ:share,url={search_url},title={search_title},content={search_content},image={search_image}")
|
type='share'
|
||||||
|
data={
|
||||||
|
'url':search_url,
|
||||||
|
'title':search_title,
|
||||||
|
'content':search_content,
|
||||||
|
'image':search_image
|
||||||
|
}
|
||||||
|
msg=[type,data]
|
||||||
|
return msg
|
||||||
|
|
||||||
def add_reply_on_target_confirm(platform,name,id):
|
def add_reply_on_target_confirm(platform,name,id):
|
||||||
return (f"即将订阅的用户为:{platform} {name} {id}\n如有错误请输入“取消”重新订阅")
|
return (f"即将订阅的用户为:{platform} {name} {id}\n如有错误请输入“取消”重新订阅")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user