mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
🚧 sunset get_bot
This commit is contained in:
@@ -30,6 +30,7 @@ def load_adapters(nonebug_init: None):
|
||||
async def app(tmp_path: Path, request: pytest.FixtureRequest, mocker: MockerFixture):
|
||||
sys.path.append(str(Path(__file__).parent.parent / "src" / "plugins"))
|
||||
|
||||
nonebot.require("nonebot_plugin_saa")
|
||||
nonebot.require("nonebot_bison")
|
||||
from nonebot_plugin_datastore.config import plugin_config as datastore_config
|
||||
from nonebot_plugin_datastore.db import create_session, init_db
|
||||
|
||||
@@ -22,81 +22,3 @@ async def test_get_bots(app: App) -> None:
|
||||
|
||||
assert botv11 in bot
|
||||
assert botv12 not in bot
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("app", [{"refresh_bot": True}], indirect=True)
|
||||
async def test_refresh_bots(app: App) -> None:
|
||||
from nonebot import get_driver
|
||||
from nonebot.adapters.onebot.v11 import Bot as BotV11
|
||||
from nonebot.adapters.onebot.v12 import Bot as BotV12
|
||||
from nonebot_plugin_saa import TargetQQGroup, TargetQQPrivate
|
||||
|
||||
from nonebot_bison.utils.get_bot import get_bot, get_groups, refresh_bots
|
||||
|
||||
async with app.test_api() as ctx:
|
||||
botv11 = ctx.create_bot(base=BotV11, self_id="v11")
|
||||
botv12 = ctx.create_bot(base=BotV12, self_id="v12", platform="qq", impl="walle")
|
||||
|
||||
driver = get_driver()
|
||||
driver._bots = {botv11.self_id: botv11, botv12.self_id: botv12}
|
||||
|
||||
ctx.should_call_api("get_group_list", {}, [{"group_id": 1}])
|
||||
ctx.should_call_api("get_friend_list", {}, [{"user_id": 2}])
|
||||
|
||||
assert get_bot(TargetQQGroup(group_id=1)) is None
|
||||
assert get_bot(TargetQQPrivate(user_id=2)) is None
|
||||
|
||||
await refresh_bots()
|
||||
|
||||
assert get_bot(TargetQQGroup(group_id=1)) == botv11
|
||||
assert get_bot(TargetQQPrivate(user_id=2)) == botv11
|
||||
|
||||
# 测试获取群列表
|
||||
ctx.should_call_api("get_group_list", {}, [{"group_id": 3}])
|
||||
|
||||
groups = await get_groups()
|
||||
|
||||
assert groups == [{"group_id": 3}]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("app", [{"refresh_bot": True}], indirect=True)
|
||||
async def test_get_bot_two_bots(app: App) -> None:
|
||||
from nonebot import get_driver
|
||||
from nonebot.adapters.onebot.v11 import Bot as BotV11
|
||||
from nonebot.adapters.onebot.v12 import Bot as BotV12
|
||||
from nonebot_plugin_saa import TargetQQGroup, TargetQQPrivate
|
||||
|
||||
from nonebot_bison.utils.get_bot import get_bot, get_groups, refresh_bots
|
||||
|
||||
async with app.test_api() as ctx:
|
||||
bot1 = ctx.create_bot(base=BotV11, self_id="1")
|
||||
bot2 = ctx.create_bot(base=BotV11, self_id="2")
|
||||
botv12 = ctx.create_bot(base=BotV12, self_id="v12", platform="qq", impl="walle")
|
||||
|
||||
driver = get_driver()
|
||||
driver._bots = {bot1.self_id: bot1, bot2.self_id: bot2, botv12.self_id: botv12}
|
||||
|
||||
ctx.should_call_api("get_group_list", {}, [{"group_id": 1}, {"group_id": 2}])
|
||||
ctx.should_call_api("get_friend_list", {}, [{"user_id": 1}, {"user_id": 2}])
|
||||
ctx.should_call_api("get_group_list", {}, [{"group_id": 2}, {"group_id": 3}])
|
||||
ctx.should_call_api("get_friend_list", {}, [{"user_id": 2}, {"user_id": 3}])
|
||||
|
||||
await refresh_bots()
|
||||
|
||||
assert get_bot(TargetQQGroup(group_id=0)) is None
|
||||
assert get_bot(TargetQQGroup(group_id=1)) == bot1
|
||||
assert get_bot(TargetQQGroup(group_id=2)) in (bot1, bot2)
|
||||
assert get_bot(TargetQQGroup(group_id=3)) == bot2
|
||||
assert get_bot(TargetQQPrivate(user_id=0)) is None
|
||||
assert get_bot(TargetQQPrivate(user_id=1)) == bot1
|
||||
assert get_bot(TargetQQPrivate(user_id=2)) in (bot1, bot2)
|
||||
assert get_bot(TargetQQPrivate(user_id=3)) == bot2
|
||||
|
||||
ctx.should_call_api("get_group_list", {}, [{"group_id": 1}, {"group_id": 2}])
|
||||
ctx.should_call_api("get_group_list", {}, [{"group_id": 2}, {"group_id": 3}])
|
||||
|
||||
groups = await get_groups()
|
||||
|
||||
assert groups == [{"group_id": 1}, {"group_id": 2}, {"group_id": 3}]
|
||||
|
||||
Reference in New Issue
Block a user