mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
🔀 merge
This commit is contained in:
@@ -18,6 +18,7 @@ def pytest_configure(config: pytest.Config) -> None:
|
||||
"superusers": {"10001"},
|
||||
"command_start": {""},
|
||||
"log_level": "TRACE",
|
||||
"bison_use_browser": True,
|
||||
}
|
||||
|
||||
|
||||
@@ -113,3 +114,12 @@ async def use_legacy_config(app: App):
|
||||
|
||||
# 清除单例的缓存
|
||||
Singleton._instances.clear()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def _no_browser(app: App, mocker: MockerFixture):
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.platform import _get_unavailable_platforms
|
||||
|
||||
mocker.patch.object(plugin_config, "bison_use_browser", False)
|
||||
mocker.patch("nonebot_bison.platform.unavailable_paltforms", _get_unavailable_platforms())
|
||||
|
||||
@@ -183,7 +183,7 @@ async def test_retry_for_352(app: App, mocker: MockerFixture):
|
||||
|
||||
fakebili.set_raise352(True)
|
||||
|
||||
for state in test_state_list:
|
||||
for state in test_state_list[:-3]:
|
||||
logger.info(f"\n\nnow state should be {state}")
|
||||
assert _retry_fsm.current_state == state
|
||||
|
||||
@@ -194,6 +194,13 @@ async def test_retry_for_352(app: App, mocker: MockerFixture):
|
||||
if state == RetryState.BACKOFF:
|
||||
freeze_start += timedelta_length * (_retry_fsm.addon.backoff_count + 1) ** 2
|
||||
|
||||
for state in test_state_list[-3:]:
|
||||
logger.info(f"\n\nnow state should be {state}")
|
||||
assert _retry_fsm.current_state == state
|
||||
|
||||
with pytest.raises(ApiCode352Error):
|
||||
await fakebili.get_sub_list(Target("t1")) # type: ignore
|
||||
|
||||
assert client_mgr.refresh_client_call_count == 4 * 3 + 3 # refresh + raise
|
||||
assert client_mgr.get_client_call_count == 2 + 4 * 3 + 3 # previous + refresh + raise
|
||||
|
||||
|
||||
@@ -88,9 +88,21 @@ async def test_fetch_new_1(
|
||||
assert post1.title is None
|
||||
assert (
|
||||
post1.content
|
||||
== "【#統合戦略】 引き続き新テーマ「ミヅキと紺碧の樹」の新要素及びシステムの変更点を一部ご紹介します!"
|
||||
" 今回は「灯火」、「ダイス」、「記号認識」、「鍵」についてです。詳細は添付の画像をご確認ください。"
|
||||
"#アークナイツ https://t.co/ARmptV0Zvu"
|
||||
== "【#統合戦略】 <br />引き続き新テーマ「ミヅキと紺碧の樹」の新要素及びシステムの変更点を一部ご紹介します! "
|
||||
"<br /><br />"
|
||||
"今回は「灯火」、「ダイス」、「記号認識」、「鍵」についてです。<br />詳細は添付の画像をご確認ください。"
|
||||
"<br /><br />"
|
||||
"#アークナイツ https://t.co/ARmptV0Zvu<br />"
|
||||
'<img src="https://pbs.twimg.com/media/FwZG9YAacAIXDw2?format=jpg&name=orig" />'
|
||||
)
|
||||
plain_content = await post1.get_plain_content()
|
||||
assert (
|
||||
plain_content == "【#統合戦略】 \n"
|
||||
"引き続き新テーマ「ミヅキと紺碧の樹」の新要素及びシステムの変更点を一部ご紹介します! \n\n"
|
||||
"今回は「灯火」、「ダイス」、「記号認識」、「鍵」についてです。\n"
|
||||
"詳細は添付の画像をご確認ください。\n\n"
|
||||
"#アークナイツ https://t.co/ARmptV0Zvu\n"
|
||||
"[图片]"
|
||||
)
|
||||
|
||||
|
||||
@@ -174,7 +186,9 @@ async def test_fetch_new_4(
|
||||
assert len(res2[0][1]) == 1
|
||||
post1 = res2[0][1][0]
|
||||
assert post1.url == "https://wallhaven.cc/w/85rjej"
|
||||
assert post1.content == "85rjej.jpg"
|
||||
assert post1.content == '<img alt="loading" class="lazyload" src="https://th.wallhaven.cc/small/85/85rjej.jpg" />'
|
||||
plain_content = await post1.get_plain_content()
|
||||
assert plain_content == "[图片]"
|
||||
|
||||
|
||||
def test_similar_text_process():
|
||||
|
||||
@@ -615,3 +615,48 @@ async def test_add_with_bilibili_bangumi_target_parser(app: App, init_scheduler)
|
||||
assert sub.tags == []
|
||||
assert sub.target.platform_name == "bilibili-bangumi"
|
||||
assert sub.target.target_name == "汉化日记 第三季"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_subscribe_platform_requires_browser(app: App, mocker: MockerFixture):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.sub_manager import add_sub_matcher, common_platform
|
||||
from nonebot_bison.platform import platform_manager, unavailable_paltforms
|
||||
|
||||
mocker.patch.object(plugin_config, "bison_use_browser", False)
|
||||
mocker.patch.dict(unavailable_paltforms, {"bilibili": "需要启用 bison_use_browser"})
|
||||
|
||||
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,
|
||||
BotReply.add_reply_on_platform(platform_manager=platform_manager, common_platform=common_platform),
|
||||
True,
|
||||
)
|
||||
event_2 = fake_group_message_event(
|
||||
message=Message("全部"), sender=Sender(card="", nickname="test", role="admin")
|
||||
)
|
||||
ctx.receive_event(bot, event_2)
|
||||
ctx.should_rejected()
|
||||
ctx.should_call_send(
|
||||
event_2,
|
||||
BotReply.add_reply_on_platform_input_allplatform(platform_manager),
|
||||
True,
|
||||
)
|
||||
event_3 = fake_group_message_event(message=Message("bilibili"), sender=fake_admin_user)
|
||||
ctx.receive_event(bot, event_3)
|
||||
ctx.should_call_send(
|
||||
event_3,
|
||||
BotReply.add_reply_platform_unavailable("bilibili", "需要启用 bison_use_browser"),
|
||||
True,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import pytest
|
||||
from nonebug import App
|
||||
|
||||
from ..utils import BotReply, fake_admin_user, fake_group_message_event
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_with_permission(app: App):
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.sub_manager import add_sub_matcher, common_platform, no_permission_matcher
|
||||
|
||||
async with app.test_matcher([add_sub_matcher, no_permission_matcher]) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
event = fake_group_message_event(message=Message("添加订阅"), sender=fake_admin_user, to_me=True)
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_call_send(
|
||||
event,
|
||||
BotReply.add_reply_on_platform(platform_manager, common_platform),
|
||||
True,
|
||||
)
|
||||
ctx.should_pass_rule()
|
||||
ctx.should_pass_permission()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_without_permission(app: App):
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
|
||||
from nonebot_bison.sub_manager import add_sub_matcher, no_permission_matcher
|
||||
|
||||
async with app.test_matcher([add_sub_matcher, no_permission_matcher]) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
event = fake_group_message_event(message=Message("添加订阅"), to_me=True)
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_call_send(
|
||||
event,
|
||||
BotReply.no_permission,
|
||||
True,
|
||||
)
|
||||
ctx.should_pass_rule()
|
||||
ctx.should_pass_permission()
|
||||
@@ -146,6 +146,10 @@ class BotReply:
|
||||
extra_text = ("1." + target_promot + "\n2.") if target_promot else ""
|
||||
return extra_text + base_text
|
||||
|
||||
@staticmethod
|
||||
def add_reply_platform_unavailable(platform: str, reason: str) -> str:
|
||||
return f"无法订阅 {platform},{reason}"
|
||||
|
||||
add_reply_on_id_input_error = "id输入错误"
|
||||
add_reply_on_target_parse_input_error = "不能从你的输入中提取出id,请检查你输入的内容是否符合预期"
|
||||
add_reply_on_platform_input_error = "平台输入错误"
|
||||
@@ -154,3 +158,4 @@ class BotReply:
|
||||
)
|
||||
add_reply_on_tags_need_more_info = "订阅标签直接输入标签内容\n屏蔽标签请在标签名称前添加~号\n详见https://nonebot-bison.netlify.app/usage/#%E5%B9%B3%E5%8F%B0%E8%AE%A2%E9%98%85%E6%A0%87%E7%AD%BE-tag"
|
||||
add_reply_abort = "已中止订阅"
|
||||
no_permission = "您没有权限进行此操作,请联系 Bot 管理员"
|
||||
|
||||
Reference in New Issue
Block a user