mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 19:36:43 +08:00
update
This commit is contained in:
parent
cf35432757
commit
e61f9ea8fd
@ -52,6 +52,9 @@ class Config(metaclass=Singleton):
|
||||
migrate_version = 2
|
||||
|
||||
def __init__(self):
|
||||
self._do_init()
|
||||
|
||||
def _do_init(self):
|
||||
path = get_config_path()
|
||||
if Path(path).exists():
|
||||
self.available = True
|
||||
|
@ -46,3 +46,14 @@ async def db_migration(app: App):
|
||||
await sess.execute(delete(Target))
|
||||
await sess.commit()
|
||||
await sess.close()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def use_legacy_config(app: App):
|
||||
import aiofiles
|
||||
from nonebot_bison.config.config_legacy import config, get_config_path
|
||||
|
||||
async with aiofiles.open(get_config_path(), "w") as f:
|
||||
await f.write("{}")
|
||||
|
||||
config._do_init()
|
||||
|
@ -11,7 +11,7 @@ if typing.TYPE_CHECKING:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config_legacy(app: App):
|
||||
def config_legacy(app: App, use_legacy_config):
|
||||
from nonebot_bison import config
|
||||
from nonebot_bison.config import config_legacy as config
|
||||
|
||||
|
@ -10,15 +10,12 @@ from .utils import BotReply, fake_admin_user, fake_group_message_event
|
||||
# 选择platform阶段中止
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_abort_add_on_platform(app: App):
|
||||
async def test_abort_add_on_platform(app: App, db_migration):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
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.user_target.truncate()
|
||||
|
||||
ak_list_router = respx.get(
|
||||
"https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937"
|
||||
)
|
||||
@ -60,15 +57,12 @@ async def test_abort_add_on_platform(app: App):
|
||||
# 输入id阶段中止
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_abort_add_on_id(app: App):
|
||||
async def test_abort_add_on_id(app: App, db_migration):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
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.user_target.truncate()
|
||||
|
||||
ak_list_router = respx.get(
|
||||
"https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937"
|
||||
)
|
||||
@ -119,15 +113,12 @@ async def test_abort_add_on_id(app: App):
|
||||
# 输入订阅类别阶段中止
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_abort_add_on_cats(app: App):
|
||||
async def test_abort_add_on_cats(app: App, db_migration):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
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.user_target.truncate()
|
||||
|
||||
ak_list_router = respx.get(
|
||||
"https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937"
|
||||
)
|
||||
@ -198,15 +189,12 @@ async def test_abort_add_on_cats(app: App):
|
||||
# 输入标签阶段中止
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_abort_add_on_tag(app: App):
|
||||
async def test_abort_add_on_tag(app: App, db_migration):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
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.user_target.truncate()
|
||||
|
||||
ak_list_router = respx.get(
|
||||
"https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937"
|
||||
)
|
||||
|
@ -58,15 +58,13 @@ async def test_configurable_at_me_false(app: App):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_with_target(app: App):
|
||||
async def test_add_with_target(app: App, db_migration):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
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.user_target.truncate()
|
||||
|
||||
ak_list_router = respx.get(
|
||||
"https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937"
|
||||
)
|
||||
@ -160,29 +158,27 @@ async def test_add_with_target(app: App):
|
||||
event_6, BotReply.add_reply_subscribe_success("明日方舟Arknights"), True
|
||||
)
|
||||
ctx.should_finished()
|
||||
subs = config.list_subscribe(10000, "group")
|
||||
subs = await config.list_subscribe(10000, "group")
|
||||
assert len(subs) == 1
|
||||
sub = subs[0]
|
||||
assert sub["target"] == "6279793937"
|
||||
assert sub["tags"] == []
|
||||
assert sub["cats"] == [platform_manager["weibo"].reverse_category["图文"]] + [
|
||||
assert sub.target.target == "6279793937"
|
||||
assert sub.tags == []
|
||||
assert sub.categories == [platform_manager["weibo"].reverse_category["图文"]] + [
|
||||
platform_manager["weibo"].reverse_category["文字"]
|
||||
]
|
||||
assert sub["target_type"] == "weibo"
|
||||
assert sub["target_name"] == "明日方舟Arknights"
|
||||
assert sub.target.platform_name == "weibo"
|
||||
assert sub.target.target_name == "明日方舟Arknights"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_with_target_no_cat(app: App):
|
||||
async def test_add_with_target_no_cat(app: App, db_migration):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
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.user_target.truncate()
|
||||
|
||||
ncm_router = respx.get("https://music.163.com/api/artist/albums/32540734")
|
||||
ncm_router.mock(return_value=Response(200, json=get_json("ncm_siren.json")))
|
||||
|
||||
@ -222,27 +218,25 @@ async def test_add_with_target_no_cat(app: App):
|
||||
event_4_ok, BotReply.add_reply_subscribe_success("塞壬唱片-MSR"), True
|
||||
)
|
||||
ctx.should_finished()
|
||||
subs = config.list_subscribe(10000, "group")
|
||||
subs = await config.list_subscribe(10000, "group")
|
||||
assert len(subs) == 1
|
||||
sub = subs[0]
|
||||
assert sub["target"] == "32540734"
|
||||
assert sub["tags"] == []
|
||||
assert sub["cats"] == []
|
||||
assert sub["target_type"] == "ncm-artist"
|
||||
assert sub["target_name"] == "塞壬唱片-MSR"
|
||||
assert sub.target.target == "32540734"
|
||||
assert sub.tags == []
|
||||
assert sub.categories == []
|
||||
assert sub.target.platform_name == "ncm-artist"
|
||||
assert sub.target.target_name == "塞壬唱片-MSR"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_no_target(app: App):
|
||||
async def test_add_no_target(app: App, db_migration):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
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.user_target.truncate()
|
||||
|
||||
async with app.test_matcher(add_sub_matcher) as ctx:
|
||||
bot = ctx.create_bot()
|
||||
event_1 = fake_group_message_event(
|
||||
@ -274,25 +268,23 @@ async def test_add_no_target(app: App):
|
||||
event_4, BotReply.add_reply_subscribe_success("明日方舟游戏信息"), True
|
||||
)
|
||||
ctx.should_finished()
|
||||
subs = config.list_subscribe(10000, "group")
|
||||
subs = await config.list_subscribe(10000, "group")
|
||||
assert len(subs) == 1
|
||||
sub = subs[0]
|
||||
assert sub["target"] == "default"
|
||||
assert sub["tags"] == []
|
||||
assert sub["cats"] == [platform_manager["arknights"].reverse_category["游戏公告"]]
|
||||
assert sub["target_type"] == "arknights"
|
||||
assert sub["target_name"] == "明日方舟游戏信息"
|
||||
assert sub.target.target == "default"
|
||||
assert sub.tags == []
|
||||
assert sub.categories == [platform_manager["arknights"].reverse_category["游戏公告"]]
|
||||
assert sub.target.platform_name == "arknights"
|
||||
assert sub.target.target_name == "明日方舟游戏信息"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_platform_name_err(app: App):
|
||||
async def test_platform_name_err(app: App, db_migration):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
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.user_target.truncate()
|
||||
async with app.test_matcher(add_sub_matcher) as ctx:
|
||||
bot = ctx.create_bot()
|
||||
event_1 = fake_group_message_event(
|
||||
@ -322,15 +314,13 @@ async def test_platform_name_err(app: App):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_with_get_id(app: App):
|
||||
async def test_add_with_get_id(app: App, db_migration):
|
||||
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.user_target.truncate()
|
||||
|
||||
ak_list_router = respx.get(
|
||||
"https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937"
|
||||
)
|
||||
@ -398,5 +388,5 @@ async def test_add_with_get_id(app: App):
|
||||
True,
|
||||
)
|
||||
ctx.should_finished()
|
||||
subs = config.list_subscribe(10000, "group")
|
||||
subs = await config.list_subscribe(10000, "group")
|
||||
assert len(subs) == 0
|
||||
|
@ -8,17 +8,17 @@ from .utils import fake_admin_user, fake_group_message_event
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_query_sub(app: App):
|
||||
async def test_query_sub(app: App, db_migration):
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.config_manager import query_sub_matcher
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.types import Target
|
||||
|
||||
config.user_target.truncate()
|
||||
config.add_subscribe(
|
||||
await config.add_subscribe(
|
||||
10000,
|
||||
"group",
|
||||
"6279793937",
|
||||
Target("6279793937"),
|
||||
"明日方舟Arknights",
|
||||
"weibo",
|
||||
[platform_manager["weibo"].reverse_category["图文"]],
|
||||
@ -36,18 +36,18 @@ async def test_query_sub(app: App):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_del_sub(app: App):
|
||||
async def test_del_sub(app: App, db_migration):
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.config_manager import del_sub_matcher
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.types import Target
|
||||
|
||||
config.user_target.truncate()
|
||||
config.add_subscribe(
|
||||
await config.add_subscribe(
|
||||
10000,
|
||||
"group",
|
||||
"6279793937",
|
||||
Target("6279793937"),
|
||||
"明日方舟Arknights",
|
||||
"weibo",
|
||||
[platform_manager["weibo"].reverse_category["图文"]],
|
||||
@ -81,5 +81,5 @@ async def test_del_sub(app: App):
|
||||
ctx.receive_event(bot, event_1_ok)
|
||||
ctx.should_call_send(event_1_ok, "删除成功", True)
|
||||
ctx.should_finished()
|
||||
subs = config.list_subscribe(10000, "group")
|
||||
subs = await config.list_subscribe(10000, "group")
|
||||
assert len(subs) == 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user