🚧 use saa-send

This commit is contained in:
felinae98
2023-05-09 18:04:27 +08:00
parent 5010ca1ac5
commit 2ba9542b63
7 changed files with 37 additions and 33 deletions
+4 -5
View File
@@ -30,7 +30,6 @@ 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
@@ -55,10 +54,10 @@ async def app(tmp_path: Path, request: pytest.FixtureRequest, mocker: MockerFixt
if not param.get("no_init_db"):
await init_db()
if not param.get("refresh_bot"):
import nonebot_bison.utils.get_bot
mocker.patch.object(nonebot_bison.utils.get_bot, "refresh_bots")
# if not param.get("refresh_bot"):
# import nonebot_bison.utils.get_bot
#
# mocker.patch.object(nonebot_bison.utils.get_bot, "refresh_bots")
yield App()
+1 -1
View File
@@ -1,8 +1,8 @@
import pytest
import respx
from httpx import Response
from nonebot_plugin_saa.nonebug import should_send_saa
from nonebug.app import App
from nonebug_saa import should_send_saa
from .platforms.utils import get_json
from .utils import BotReply, fake_admin_user, fake_group_message_event
+4 -2
View File
@@ -544,6 +544,7 @@ async def test_add_with_bilibili_target_parser(app: App, init_scheduler):
async def test_add_with_bilibili_live_target_parser(app: App, init_scheduler):
from nonebot.adapters.onebot.v11.event import Sender
from nonebot.adapters.onebot.v11.message import Message
from nonebot_plugin_saa import TargetQQGroup
from nonebot_bison.config import config
from nonebot_bison.config_manager import add_sub_matcher, common_platform
@@ -621,7 +622,7 @@ async def test_add_with_bilibili_live_target_parser(app: App, init_scheduler):
event_5_ok, BotReply.add_reply_subscribe_success("明日方舟"), True
)
ctx.should_finished()
subs = await config.list_subscribe(10000, "group")
subs = await config.list_subscribe(TargetQQGroup(group_id=10000))
assert len(subs) == 1
sub = subs[0]
assert sub.target.target == "161775300"
@@ -638,6 +639,7 @@ async def test_add_with_bilibili_live_target_parser(app: App, init_scheduler):
async def test_add_with_bilibili_bangumi_target_parser(app: App, init_scheduler):
from nonebot.adapters.onebot.v11.event import Sender
from nonebot.adapters.onebot.v11.message import Message
from nonebot_plugin_saa import TargetQQGroup
from nonebot_bison.config import config
from nonebot_bison.config_manager import add_sub_matcher, common_platform
@@ -708,7 +710,7 @@ async def test_add_with_bilibili_bangumi_target_parser(app: App, init_scheduler)
event_4_ok, BotReply.add_reply_subscribe_success("汉化日记 第三季"), True
)
ctx.should_finished()
subs = await config.list_subscribe(10000, "group")
subs = await config.list_subscribe(TargetQQGroup(group_id=10000))
assert len(subs) == 1
sub = subs[0]
assert sub.target.target == "28235413"
+2 -3
View File
@@ -1,8 +1,8 @@
import pytest
import respx
from httpx import Response
from nonebot_plugin_saa.nonebug import should_send_saa
from nonebug.app import App
from nonebug_saa import should_send_saa
from .platforms.utils import get_json
from .utils import fake_admin_user, fake_group_message_event
@@ -28,8 +28,7 @@ async def test_query_sub(app: App, init_scheduler):
["明日方舟"],
)
async with app.test_matcher(query_sub_matcher) as ctx:
adapter = get_driver()._adapters[str(SupportedAdapters.onebot_v11)]
bot = ctx.create_bot(base=Bot, adapter=adapter)
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event(message=Message("查询订阅"), to_me=True)
ctx.receive_event(bot, event)
+16 -12
View File
@@ -3,8 +3,8 @@ import typing
import pytest
from flaky import flaky
from nonebot_plugin_saa.nonebug import should_send_saa
from nonebug import App
from nonebug_saa import should_send_saa
from pytest_mock.plugin import MockerFixture
@@ -12,6 +12,7 @@ from pytest_mock.plugin import MockerFixture
async def test_send_no_queue(app: App, mocker: MockerFixture):
from nonebot.adapters.onebot.v11.bot import Bot
from nonebot_plugin_saa import MessageFactory, TargetQQGroup, TargetQQPrivate
from nonebot_plugin_saa.utils.auto_select_bot import refresh_bots
from nonebot_bison.plugin_config import plugin_config
from nonebot_bison.send import send_msgs
@@ -27,10 +28,8 @@ async def test_send_no_queue(app: App, mocker: MockerFixture):
should_send_saa(ctx, MessageFactory("msg1"), bot, target=group_target)
should_send_saa(ctx, MessageFactory("msg2"), bot, target=group_target)
should_send_saa(ctx, MessageFactory("priv"), bot, target=private_target)
await send_msgs(
bot, group_target, [MessageFactory("msg1"), MessageFactory("msg2")]
)
await send_msgs(bot, private_target, [MessageFactory("priv")])
await send_msgs(group_target, [MessageFactory("msg1"), MessageFactory("msg2")])
await send_msgs(private_target, [MessageFactory("priv")])
assert ctx.wait_list.empty()
@@ -39,6 +38,7 @@ async def test_send_queue(app: App, mocker: MockerFixture):
import nonebot
from nonebot.adapters.onebot.v11.bot import Bot
from nonebot_plugin_saa import MessageFactory, TargetQQGroup
from nonebot_plugin_saa.utils.auto_select_bot import refresh_bots
from nonebot_bison.plugin_config import plugin_config
from nonebot_bison.send import MESSGE_SEND_INTERVAL, send_msgs
@@ -46,6 +46,7 @@ async def test_send_queue(app: App, mocker: MockerFixture):
mocker.patch.object(plugin_config, "bison_use_queue", True)
async with app.test_api() as ctx:
new_bot = ctx.create_bot(base=Bot)
await refresh_bots()
mocker.patch.object(nonebot, "get_bot", lambda: new_bot)
bot = nonebot.get_bot()
assert isinstance(bot, Bot)
@@ -55,8 +56,8 @@ async def test_send_queue(app: App, mocker: MockerFixture):
should_send_saa(ctx, MessageFactory("msg"), bot, target=target)
should_send_saa(ctx, MessageFactory("msg2"), bot, target=target)
await send_msgs(bot, target, [MessageFactory("msg")])
await send_msgs(bot, target, [MessageFactory("msg2")])
await send_msgs(target, [MessageFactory("msg")])
await send_msgs(target, [MessageFactory("msg2")])
assert not ctx.wait_list.empty()
await asyncio.sleep(2 * MESSGE_SEND_INTERVAL)
assert ctx.wait_list.empty()
@@ -72,6 +73,7 @@ async def test_send_merge_no_queue(app: App):
TargetQQGroup,
Text,
)
from nonebot_plugin_saa.utils.auto_select_bot import refresh_bots
from nonebot_bison.plugin_config import plugin_config
from nonebot_bison.send import send_msgs
@@ -81,6 +83,7 @@ async def test_send_merge_no_queue(app: App):
async with app.test_api() as ctx:
bot = ctx.create_bot(base=Bot, self_id="8888")
await refresh_bots()
assert isinstance(bot, Bot)
target = TargetQQGroup(group_id=633)
@@ -90,7 +93,7 @@ async def test_send_merge_no_queue(app: App):
]
should_send_saa(ctx, message[0], bot, target=target)
should_send_saa(ctx, message[1], bot, target=target)
await send_msgs(bot, target, message)
await send_msgs(target, message)
message = [
MessageFactory(Text("test msg")),
@@ -99,8 +102,7 @@ async def test_send_merge_no_queue(app: App):
]
should_send_saa(ctx, message[0], bot, target=target)
should_send_saa(ctx, AggregatedMessageFactory(message[1:]), bot, target=target)
# import ipdb; ipdb.set_trace()
await send_msgs(bot, target, message)
await send_msgs(target, message)
message = [
MessageFactory(Text("test msg")),
@@ -110,7 +112,7 @@ async def test_send_merge_no_queue(app: App):
]
should_send_saa(ctx, message[0], bot, target=target)
should_send_saa(ctx, AggregatedMessageFactory(message[1:]), bot, target=target)
await send_msgs(bot, target, message)
await send_msgs(target, message)
async def test_send_merge2_no_queue(app: App):
@@ -122,6 +124,7 @@ async def test_send_merge2_no_queue(app: App):
TargetQQGroup,
Text,
)
from nonebot_plugin_saa.utils.auto_select_bot import refresh_bots
from nonebot_bison.plugin_config import plugin_config
from nonebot_bison.send import send_msgs
@@ -132,6 +135,7 @@ async def test_send_merge2_no_queue(app: App):
async with app.test_api() as ctx:
bot = ctx.create_bot(base=Bot, self_id="8888")
assert isinstance(bot, Bot)
await refresh_bots()
target = TargetQQGroup(group_id=633)
message = [
@@ -140,4 +144,4 @@ async def test_send_merge2_no_queue(app: App):
MessageFactory(Image("https://picsum.photos/200/300")),
]
should_send_saa(ctx, AggregatedMessageFactory(message), bot, target=target)
await send_msgs(bot, target, message)
await send_msgs(target, message)