mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 11:26:43 +08:00
* 🚧 第一次尝试 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>
58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
import typing
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from nonebug.app import App
|
|
|
|
if typing.TYPE_CHECKING:
|
|
import sys
|
|
|
|
sys.path.append("./src/plugins")
|
|
from nonebot_bison.config.config_legacy import Config
|
|
|
|
|
|
@pytest.fixture
|
|
def config_legacy(app: App, use_legacy_config):
|
|
from nonebot_bison import config
|
|
from nonebot_bison.config import config_legacy as config
|
|
|
|
config.start_up()
|
|
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):
|
|
from nonebot_bison import types
|
|
from nonebot_bison.types import Target
|
|
|
|
config_legacy.add_subscribe(
|
|
user=123,
|
|
user_type="group",
|
|
target="weibo_id",
|
|
target_name="weibo_name",
|
|
target_type="weibo",
|
|
cats=[],
|
|
tags=[],
|
|
)
|
|
confs = config_legacy.list_subscribe(123, "group")
|
|
assert len(confs) == 1
|
|
assert config_legacy.target_user_cache["weibo"][Target("weibo_id")] == [
|
|
types.User(123, "group")
|
|
]
|
|
assert confs[0]["cats"] == []
|
|
config_legacy.update_subscribe(
|
|
user=123,
|
|
user_type="group",
|
|
target="weibo_id",
|
|
target_name="weibo_name",
|
|
target_type="weibo",
|
|
cats=["1"],
|
|
tags=[],
|
|
)
|
|
confs = config_legacy.list_subscribe(123, "group")
|
|
assert len(confs) == 1
|
|
assert confs[0]["cats"] == ["1"]
|