mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-13 20:38:39 +08:00
⬆️ 升级至 NoneBug 0.3
* 🚧 第一次尝试 50/82 * 62/82 调整了清除数据库的位置 * 🚧 pytest-mock * 🚧 fix test_send * 🚧 intruduce app request * 🚧 close and remove tinydb after each test * 🚧 clean ScheduleTimeWeight table * 🚧 reload http module to test proxy * ✅ 合并 main 的代码 * 🚧 在每次测试结束后关闭browser * 🧑💻 在mcbbsnews渲染异常时添加logger --------- Co-authored-by: hemengyang <hmy0119@gmail.com> Co-authored-by: Azide <rukuy@qq.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import typing
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
@@ -16,7 +17,11 @@ def config_legacy(app: App, use_legacy_config):
|
||||
from nonebot_bison.config import config_legacy as config
|
||||
|
||||
config.start_up()
|
||||
return config.Config()
|
||||
yield config.Config()
|
||||
|
||||
config.Config().db.close()
|
||||
legacy_config = Path(config.get_config_path()[0])
|
||||
legacy_config.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def test_create_and_get(config_legacy: "Config", app: App):
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
from datetime import time
|
||||
|
||||
from nonebug import App
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
|
||||
async def test_create_config(app: App, init_scheduler):
|
||||
async def test_create_config(init_scheduler):
|
||||
from nonebot_bison.config.db_config import TimeWeightConfig, WeightConfig, config
|
||||
from nonebot_bison.config.db_model import Subscribe, Target, User
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
@@ -52,7 +53,7 @@ async def test_create_config(app: App, init_scheduler):
|
||||
assert test_config1.time_config == []
|
||||
|
||||
|
||||
async def test_get_current_weight(app: App, init_scheduler):
|
||||
async def test_get_current_weight(init_scheduler, mocker: MockerFixture):
|
||||
from datetime import time
|
||||
|
||||
from nonebot_bison.config import db_config
|
||||
@@ -99,19 +100,19 @@ async def test_get_current_weight(app: App, init_scheduler):
|
||||
],
|
||||
),
|
||||
)
|
||||
app.monkeypatch.setattr(db_config, "_get_time", lambda: time(1, 30))
|
||||
mocker.patch.object(db_config, "_get_time", return_value=time(1, 30))
|
||||
weight = await config.get_current_weight_val(["weibo", "bilibili"])
|
||||
assert len(weight) == 3
|
||||
assert weight["weibo-weibo_id"] == 20
|
||||
assert weight["weibo-weibo_id1"] == 10
|
||||
assert weight["bilibili-weibo_id1"] == 10
|
||||
app.monkeypatch.setattr(db_config, "_get_time", lambda: time(4, 0))
|
||||
mocker.patch.object(db_config, "_get_time", return_value=time(4, 0))
|
||||
weight = await config.get_current_weight_val(["weibo", "bilibili"])
|
||||
assert len(weight) == 3
|
||||
assert weight["weibo-weibo_id"] == 30
|
||||
assert weight["weibo-weibo_id1"] == 10
|
||||
assert weight["bilibili-weibo_id1"] == 10
|
||||
app.monkeypatch.setattr(db_config, "_get_time", lambda: time(5, 0))
|
||||
mocker.patch.object(db_config, "_get_time", return_value=time(5, 0))
|
||||
weight = await config.get_current_weight_val(["weibo", "bilibili"])
|
||||
assert len(weight) == 3
|
||||
assert weight["weibo-weibo_id"] == 10
|
||||
|
||||
Reference in New Issue
Block a user