mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 19:36:43 +08:00
fix test
This commit is contained in:
parent
5a4a3db332
commit
50b46c5f03
@ -1,4 +1,5 @@
|
||||
from nonebot import get_driver
|
||||
from nonebot.log import logger
|
||||
|
||||
from .config.config_legacy import start_up as legacy_db_startup
|
||||
from .config.db import upgrade_db
|
||||
@ -16,3 +17,4 @@ async def bootstrap():
|
||||
await init_scheduler()
|
||||
# start scheduler
|
||||
start_scheduler()
|
||||
logger.info("nonebot-bison bootstrap done")
|
||||
|
@ -4,7 +4,7 @@ from sqlalchemy.sql.functions import func
|
||||
from sqlmodel.sql.expression import select
|
||||
|
||||
|
||||
async def test_add_subscribe(app: App, db_migration):
|
||||
async def test_add_subscribe(app: App, init_scheduler):
|
||||
|
||||
from nonebot_bison.config.db_config import config
|
||||
from nonebot_bison.config.db_model import Subscribe, Target, User
|
||||
@ -72,7 +72,7 @@ async def test_add_subscribe(app: App, db_migration):
|
||||
assert conf.tags == ["tag"]
|
||||
|
||||
|
||||
async def test_del_subsribe(db_migration):
|
||||
async def test_del_subsribe(init_scheduler):
|
||||
from nonebot_bison.config.db_config import config
|
||||
from nonebot_bison.config.db_model import Subscribe, Target, User
|
||||
from nonebot_bison.types import Target as TTarget
|
||||
@ -95,7 +95,7 @@ async def test_del_subsribe(db_migration):
|
||||
)
|
||||
async with AsyncSession(get_engine()) as sess:
|
||||
assert (await sess.scalar(select(func.count()).select_from(Subscribe))) == 0
|
||||
assert (await sess.scalar(select(func.count()).select_from(Target))) == 0
|
||||
assert (await sess.scalar(select(func.count()).select_from(Target))) == 1
|
||||
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
|
@ -1,9 +1,9 @@
|
||||
import pytest
|
||||
|
||||
|
||||
async def test_migration(use_legacy_config, db_migration):
|
||||
async def test_migration(use_legacy_config):
|
||||
from nonebot_bison.config.config_legacy import config as config_legacy
|
||||
from nonebot_bison.config.db import data_migrate
|
||||
from nonebot_bison.config.db import data_migrate, upgrade_db
|
||||
from nonebot_bison.config.db_config import config
|
||||
|
||||
config_legacy.add_subscribe(
|
||||
@ -33,7 +33,8 @@ async def test_migration(use_legacy_config, db_migration):
|
||||
cats=[1],
|
||||
tags=[],
|
||||
)
|
||||
await data_migrate()
|
||||
# await data_migrate()
|
||||
await upgrade_db()
|
||||
user123_config = await config.list_subscribe(123, "group")
|
||||
assert len(user123_config) == 2
|
||||
for c in user123_config:
|
||||
|
@ -275,16 +275,15 @@ async def test_abort_add_on_tag(app: App, db_migration):
|
||||
async def test_abort_del_sub(app: App):
|
||||
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 import config
|
||||
from nonebot_bison.config_manager import del_sub_matcher
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
|
||||
config = Config()
|
||||
config.user_target.truncate()
|
||||
config.add_subscribe(
|
||||
await config.add_subscribe(
|
||||
10000,
|
||||
"group",
|
||||
"6279793937",
|
||||
T_Target("6279793937"),
|
||||
"明日方舟Arknights",
|
||||
"weibo",
|
||||
[platform_manager["weibo"].reverse_category["图文"]],
|
||||
@ -312,5 +311,5 @@ async def test_abort_del_sub(app: App):
|
||||
ctx.receive_event(bot, event_abort)
|
||||
ctx.should_call_send(event_abort, "删除中止", True)
|
||||
ctx.should_finished()
|
||||
subs = config.list_subscribe(10000, "group")
|
||||
subs = await config.list_subscribe(10000, "group")
|
||||
assert subs
|
||||
|
@ -397,17 +397,14 @@ async def test_add_with_get_id(app: App, db_migration):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_with_bilibili_target_parser(app: App):
|
||||
async def test_add_with_bilibili_target_parser(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 import config
|
||||
from nonebot_bison.config_manager import add_sub_matcher, common_platform
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.platform.bilibili import Bilibili
|
||||
|
||||
config = Config()
|
||||
config.user_target.truncate()
|
||||
|
||||
ak_list_router = respx.get(
|
||||
"https://api.bilibili.com/x/space/acc/info?mid=161775300"
|
||||
)
|
||||
@ -507,7 +504,7 @@ async def test_add_with_bilibili_target_parser(app: App):
|
||||
event_6, 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"] == "161775300"
|
||||
|
Loading…
x
Reference in New Issue
Block a user