From 7b4118493bc631e1d07000a635e4e319ed268ca4 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 26 Dec 2024 23:15:10 +0800 Subject: [PATCH] chore: fix test --- tests/test_dashboard.py | 27 +++++++++++++-------------- tests/test_pipeline.py | 4 ++-- tests/test_plugin_manager.py | 16 ++++------------ 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index 970ee2749..d4a38ad9b 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -7,20 +7,19 @@ from astrbot.core.core_lifecycle import AstrBotCoreLifecycle from astrbot.core import LogBroker from astrbot.core.star.star_handler import star_handlers_registry from astrbot.core.star.star import star_registry -from astrbot.core.updator import AstrBotUpdator @pytest.fixture(scope="module") -def core_lifecycle(): +def core_lifecycle_td(): db = SQLiteDatabase("data/data_v3.db") log_broker = LogBroker() - core_lifecycle = AstrBotCoreLifecycle(log_broker, db) - return core_lifecycle + core_lifecycle_td = AstrBotCoreLifecycle(log_broker, db) + return core_lifecycle_td @pytest.fixture(scope="module") -def app(core_lifecycle): +def app(core_lifecycle_td): db = SQLiteDatabase("data/data_v3.db") - server = AstrBotDashboard(core_lifecycle, db) + server = AstrBotDashboard(core_lifecycle_td, db) return server.app @pytest.fixture(scope="module") @@ -28,12 +27,12 @@ def header(): return {} @pytest.mark.asyncio -async def test_init_core_lifecycle(core_lifecycle): - await core_lifecycle.initialize() - assert core_lifecycle is not None +async def test_init_core_lifecycle_td(core_lifecycle_td): + await core_lifecycle_td.initialize() + assert core_lifecycle_td is not None @pytest.mark.asyncio -async def test_auth_login(app: Quart, core_lifecycle: AstrBotCoreLifecycle, header: dict): +async def test_auth_login(app: Quart, core_lifecycle_td: AstrBotCoreLifecycle, header: dict): test_client = app.test_client() response = await test_client.post('/api/auth/login', json={ "username": "wrong", @@ -43,8 +42,8 @@ async def test_auth_login(app: Quart, core_lifecycle: AstrBotCoreLifecycle, head assert data['status'] == 'error' response = await test_client.post('/api/auth/login', json={ - "username": core_lifecycle.astrbot_config['dashboard']['username'], - "password": core_lifecycle.astrbot_config['dashboard']['password'] + "username": core_lifecycle_td.astrbot_config['dashboard']['username'], + "password": core_lifecycle_td.astrbot_config['dashboard']['password'] }) data = await response.get_json() assert data['status'] == 'ok' and 'token' in data['data'] @@ -126,11 +125,11 @@ async def test_check_update(app: Quart, header: dict): assert data['status'] == 'success' @pytest.mark.asyncio -async def test_do_update(app: Quart, header: dict, core_lifecycle: AstrBotCoreLifecycle): +async def test_do_update(app: Quart, header: dict, core_lifecycle_td: AstrBotCoreLifecycle): global VERSION test_client = app.test_client() os.makedirs("data/astrbot_release", exist_ok=True) - core_lifecycle.astrbot_updator.MAIN_PATH = "data/astrbot_release" + core_lifecycle_td.astrbot_updator.MAIN_PATH = "data/astrbot_release" VERSION = "114.514.1919810" response = await test_client.post('/api/update/do', headers=header, json={ "version": "latest" diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index fa4fccb41..4d90fae88 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -220,5 +220,5 @@ async def test_commands(pipeline_scheduler: PipelineScheduler, caplog): mock_event = FakeAstrMessageEvent.create_fake_event(command[0], session_id=SESSION_ID_IN_WHITELIST) with caplog.at_level(logging.DEBUG): await pipeline_scheduler.execute(mock_event) - assert any("执行阶段 ProcessStage" in message for message in caplog.messages) - # assert any(command[1] in message for message in caplog.messages) \ No newline at end of file + # assert any("执行阶段 ProcessStage" in message for message in caplog.messages) + assert any(command[1] in message for message in caplog.messages) \ No newline at end of file diff --git a/tests/test_plugin_manager.py b/tests/test_plugin_manager.py index a77050070..5a26a00a6 100644 --- a/tests/test_plugin_manager.py +++ b/tests/test_plugin_manager.py @@ -8,21 +8,13 @@ from astrbot.core.config.astrbot_config import AstrBotConfig from astrbot.core.db.sqlite import SQLiteDatabase from asyncio import Queue -@pytest.fixture -def event_queue(): - return Queue() +event_queue = Queue() -@pytest.fixture -def config(): - return AstrBotConfig() +config = AstrBotConfig() -@pytest.fixture -def db(): - return SQLiteDatabase("data/data_v3.db") +db = SQLiteDatabase("data/data_v3.db") -@pytest.fixture -def star_context(event_queue, config, db): - return Context(event_queue, config, db) +star_context = Context(event_queue, config, db) @pytest.fixture def plugin_manager_pm(star_context, config):