mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 10:17:56 +08:00
reconstruct config module
This commit is contained in:
+12
-12
@@ -7,24 +7,24 @@ if typing.TYPE_CHECKING:
|
||||
import sys
|
||||
|
||||
sys.path.append("./src/plugins")
|
||||
import nonebot_bison
|
||||
from nonebot_bison.config import Config
|
||||
from nonebot_bison.config.config_legacy import Config
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config(app: App):
|
||||
def config_legacy(app: App):
|
||||
from nonebot_bison import config
|
||||
from nonebot_bison.config import config_legacy as config
|
||||
|
||||
config.start_up()
|
||||
return config.Config()
|
||||
|
||||
|
||||
def test_create_and_get(config: "Config", app: App):
|
||||
def test_create_and_get(config_legacy: "Config", app: App):
|
||||
from nonebot_bison import types
|
||||
from nonebot_bison.types import Target
|
||||
|
||||
config.add_subscribe(
|
||||
user="123",
|
||||
config_legacy.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
target="weibo_id",
|
||||
target_name="weibo_name",
|
||||
@@ -32,14 +32,14 @@ def test_create_and_get(config: "Config", app: App):
|
||||
cats=[],
|
||||
tags=[],
|
||||
)
|
||||
confs = config.list_subscribe("123", "group")
|
||||
confs = config_legacy.list_subscribe(123, "group")
|
||||
assert len(confs) == 1
|
||||
assert config.target_user_cache["weibo"][Target("weibo_id")] == [
|
||||
types.User("123", "group")
|
||||
assert config_legacy.target_user_cache["weibo"][Target("weibo_id")] == [
|
||||
types.User(123, "group")
|
||||
]
|
||||
assert confs[0]["cats"] == []
|
||||
config.update_subscribe(
|
||||
user="123",
|
||||
config_legacy.update_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
target="weibo_id",
|
||||
target_name="weibo_name",
|
||||
@@ -47,6 +47,6 @@ def test_create_and_get(config: "Config", app: App):
|
||||
cats=["1"],
|
||||
tags=[],
|
||||
)
|
||||
confs = config.list_subscribe("123", "group")
|
||||
confs = config_legacy.list_subscribe(123, "group")
|
||||
assert len(confs) == 1
|
||||
assert confs[0]["cats"] == ["1"]
|
||||
|
||||
@@ -72,11 +72,10 @@ async def test_configurable_at_me_false(app: App):
|
||||
async def test_add_with_target(app: App):
|
||||
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
|
||||
|
||||
config = Config()
|
||||
config.user_target.truncate()
|
||||
|
||||
ak_list_router = respx.get(
|
||||
@@ -199,11 +198,10 @@ async def test_add_with_target(app: App):
|
||||
async def test_add_with_target_no_cat(app: App):
|
||||
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
|
||||
|
||||
config = Config()
|
||||
config.user_target.truncate()
|
||||
|
||||
ncm_router = respx.get("https://music.163.com/api/artist/albums/32540734")
|
||||
@@ -266,11 +264,10 @@ async def test_add_with_target_no_cat(app: App):
|
||||
async def test_add_no_target(app: App):
|
||||
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
|
||||
|
||||
config = Config()
|
||||
config.user_target.truncate()
|
||||
|
||||
async with app.test_matcher(add_sub_matcher) as ctx:
|
||||
@@ -331,11 +328,10 @@ async def test_add_no_target(app: App):
|
||||
async def test_platform_name_err(app: App):
|
||||
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
|
||||
|
||||
config = Config()
|
||||
config.user_target.truncate()
|
||||
async with app.test_matcher(add_sub_matcher) as ctx:
|
||||
bot = ctx.create_bot()
|
||||
@@ -378,11 +374,10 @@ async def test_platform_name_err(app: App):
|
||||
@pytest.mark.asyncio
|
||||
async def test_query_sub(app: App):
|
||||
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 query_sub_matcher
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
config = Config()
|
||||
config.user_target.truncate()
|
||||
config.add_subscribe(
|
||||
10000,
|
||||
@@ -408,11 +403,10 @@ async def test_query_sub(app: App):
|
||||
async def test_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
|
||||
|
||||
config = Config()
|
||||
config.user_target.truncate()
|
||||
config.add_subscribe(
|
||||
10000,
|
||||
|
||||
Reference in New Issue
Block a user