mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
🚧 remove User type
This commit is contained in:
@@ -4,6 +4,7 @@ from nonebug.app import App
|
||||
|
||||
async def test_add_subscribe(app: App, init_scheduler):
|
||||
from nonebot_plugin_datastore.db import get_engine
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
from sqlalchemy.sql.expression import select
|
||||
|
||||
@@ -12,8 +13,7 @@ async def test_add_subscribe(app: App, init_scheduler):
|
||||
from nonebot_bison.types import Target as TTarget
|
||||
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=TTarget("weibo_id"),
|
||||
target_name="weibo_name",
|
||||
platform_name="weibo",
|
||||
@@ -21,15 +21,14 @@ async def test_add_subscribe(app: App, init_scheduler):
|
||||
tags=[],
|
||||
)
|
||||
await config.add_subscribe(
|
||||
user=234,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=234),
|
||||
target=TTarget("weibo_id"),
|
||||
target_name="weibo_name",
|
||||
platform_name="weibo",
|
||||
cats=[],
|
||||
tags=[],
|
||||
)
|
||||
confs = await config.list_subscribe(123, "group")
|
||||
confs = await config.list_subscribe(TargetQQGroup(group_id=123))
|
||||
assert len(confs) == 1
|
||||
conf: Subscribe = confs[0]
|
||||
async with AsyncSession(get_engine()) as sess:
|
||||
@@ -39,22 +38,23 @@ async def test_add_subscribe(app: App, init_scheduler):
|
||||
related_target_obj = await sess.scalar(
|
||||
select(Target).where(Target.id == conf.target_id)
|
||||
)
|
||||
assert related_user_obj.uid == 123
|
||||
assert related_user_obj
|
||||
assert related_target_obj
|
||||
assert related_user_obj.user_target["group_id"] == 123
|
||||
assert related_target_obj.target_name == "weibo_name"
|
||||
assert related_target_obj.target == "weibo_id"
|
||||
assert conf.target.target == "weibo_id"
|
||||
assert conf.categories == []
|
||||
|
||||
await config.update_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=TTarget("weibo_id"),
|
||||
platform_name="weibo",
|
||||
target_name="weibo_name2",
|
||||
cats=[1],
|
||||
tags=["tag"],
|
||||
)
|
||||
confs = await config.list_subscribe(123, "group")
|
||||
confs = await config.list_subscribe(TargetQQGroup(group_id=123))
|
||||
assert len(confs) == 1
|
||||
conf: Subscribe = confs[0]
|
||||
async with AsyncSession(get_engine()) as sess:
|
||||
@@ -64,7 +64,9 @@ async def test_add_subscribe(app: App, init_scheduler):
|
||||
related_target_obj = await sess.scalar(
|
||||
select(Target).where(Target.id == conf.target_id)
|
||||
)
|
||||
assert related_user_obj.uid == 123
|
||||
assert related_user_obj
|
||||
assert related_target_obj
|
||||
assert related_user_obj.user_target["group_id"] == 123
|
||||
assert related_target_obj.target_name == "weibo_name2"
|
||||
assert related_target_obj.target == "weibo_id"
|
||||
assert conf.target.target == "weibo_id"
|
||||
@@ -73,12 +75,13 @@ async def test_add_subscribe(app: App, init_scheduler):
|
||||
|
||||
|
||||
async def test_add_dup_sub(init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config.db_config import SubscribeDupException, config
|
||||
from nonebot_bison.types import Target as TTarget
|
||||
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=TTarget("weibo_id"),
|
||||
target_name="weibo_name",
|
||||
platform_name="weibo",
|
||||
@@ -88,8 +91,7 @@ async def test_add_dup_sub(init_scheduler):
|
||||
|
||||
with pytest.raises(SubscribeDupException):
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=TTarget("weibo_id"),
|
||||
target_name="weibo_name",
|
||||
platform_name="weibo",
|
||||
@@ -100,6 +102,7 @@ async def test_add_dup_sub(init_scheduler):
|
||||
|
||||
async def test_del_subsribe(init_scheduler):
|
||||
from nonebot_plugin_datastore.db import get_engine
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
from sqlalchemy.sql.expression import select
|
||||
from sqlalchemy.sql.functions import func
|
||||
@@ -109,8 +112,7 @@ async def test_del_subsribe(init_scheduler):
|
||||
from nonebot_bison.types import Target as TTarget
|
||||
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=TTarget("weibo_id"),
|
||||
target_name="weibo_name",
|
||||
platform_name="weibo",
|
||||
@@ -118,8 +120,7 @@ async def test_del_subsribe(init_scheduler):
|
||||
tags=[],
|
||||
)
|
||||
await config.del_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=TTarget("weibo_id"),
|
||||
platform_name="weibo",
|
||||
)
|
||||
@@ -128,8 +129,7 @@ async def test_del_subsribe(init_scheduler):
|
||||
assert (await sess.scalar(select(func.count()).select_from(Target))) == 1
|
||||
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=TTarget("weibo_id"),
|
||||
target_name="weibo_name",
|
||||
platform_name="weibo",
|
||||
@@ -138,8 +138,7 @@ async def test_del_subsribe(init_scheduler):
|
||||
)
|
||||
|
||||
await config.add_subscribe(
|
||||
user=124,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=124),
|
||||
target=TTarget("weibo_id"),
|
||||
target_name="weibo_name_new",
|
||||
platform_name="weibo",
|
||||
@@ -148,8 +147,7 @@ async def test_del_subsribe(init_scheduler):
|
||||
)
|
||||
|
||||
await config.del_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=TTarget("weibo_id"),
|
||||
platform_name="weibo",
|
||||
)
|
||||
@@ -157,5 +155,6 @@ async def test_del_subsribe(init_scheduler):
|
||||
async with AsyncSession(get_engine()) as sess:
|
||||
assert (await sess.scalar(select(func.count()).select_from(Subscribe))) == 1
|
||||
assert (await sess.scalar(select(func.count()).select_from(Target))) == 1
|
||||
target: Target = await sess.scalar(select(Target))
|
||||
target = await sess.scalar(select(Target))
|
||||
assert target
|
||||
assert target.target_name == "weibo_name_new"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
async def test_migration(use_legacy_config):
|
||||
from nonebot_plugin_datastore.db import init_db
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config.config_legacy import Config
|
||||
from nonebot_bison.config.db_config import config
|
||||
@@ -34,7 +35,7 @@ async def test_migration(use_legacy_config):
|
||||
)
|
||||
# await data_migrate()
|
||||
await init_db()
|
||||
user123_config = await config.list_subscribe(123, "group")
|
||||
user123_config = await config.list_subscribe(TargetQQGroup(group_id=123))
|
||||
assert len(user123_config) == 2
|
||||
for c in user123_config:
|
||||
if c.target.target == "weibo_id":
|
||||
@@ -47,7 +48,7 @@ async def test_migration(use_legacy_config):
|
||||
assert c.target.target_name == "weibo_name2"
|
||||
assert c.target.platform_name == "weibo"
|
||||
assert c.tags == ["tag"]
|
||||
user234_config = await config.list_subscribe(234, "group")
|
||||
user234_config = await config.list_subscribe(TargetQQGroup(group_id=234))
|
||||
assert len(user234_config) == 1
|
||||
assert user234_config[0].categories == [1]
|
||||
assert user234_config[0].target.target == "weibo_id"
|
||||
@@ -57,6 +58,7 @@ async def test_migration(use_legacy_config):
|
||||
|
||||
async def test_migrate_dup(use_legacy_config):
|
||||
from nonebot_plugin_datastore.db import init_db
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config.config_legacy import Config
|
||||
from nonebot_bison.config.db_config import config
|
||||
@@ -82,5 +84,5 @@ async def test_migrate_dup(use_legacy_config):
|
||||
)
|
||||
# await data_migrate()
|
||||
await init_db()
|
||||
user123_config = await config.list_subscribe(123, "group")
|
||||
user123_config = await config.list_subscribe(TargetQQGroup(group_id=123))
|
||||
assert len(user123_config) == 1
|
||||
|
||||
@@ -6,14 +6,14 @@ from pytest_mock import MockerFixture
|
||||
|
||||
async def test_create_config(init_scheduler):
|
||||
from nonebot_plugin_datastore.db import get_engine
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
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
|
||||
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=T_Target("weibo_id"),
|
||||
target_name="weibo_name",
|
||||
platform_name="weibo",
|
||||
@@ -21,8 +21,7 @@ async def test_create_config(init_scheduler):
|
||||
tags=[],
|
||||
)
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=T_Target("weibo_id1"),
|
||||
target_name="weibo_name1",
|
||||
platform_name="weibo",
|
||||
@@ -58,6 +57,7 @@ async def test_get_current_weight(init_scheduler, mocker: MockerFixture):
|
||||
from datetime import time
|
||||
|
||||
from nonebot_plugin_datastore.db import get_engine
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import db_config
|
||||
from nonebot_bison.config.db_config import TimeWeightConfig, WeightConfig, config
|
||||
@@ -65,8 +65,7 @@ async def test_get_current_weight(init_scheduler, mocker: MockerFixture):
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=T_Target("weibo_id"),
|
||||
target_name="weibo_name",
|
||||
platform_name="weibo",
|
||||
@@ -74,8 +73,7 @@ async def test_get_current_weight(init_scheduler, mocker: MockerFixture):
|
||||
tags=[],
|
||||
)
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=T_Target("weibo_id1"),
|
||||
target_name="weibo_name1",
|
||||
platform_name="weibo",
|
||||
@@ -83,8 +81,7 @@ async def test_get_current_weight(init_scheduler, mocker: MockerFixture):
|
||||
tags=[],
|
||||
)
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=T_Target("weibo_id1"),
|
||||
target_name="weibo_name2",
|
||||
platform_name="bilibili",
|
||||
@@ -124,6 +121,7 @@ async def test_get_current_weight(init_scheduler, mocker: MockerFixture):
|
||||
|
||||
async def test_get_platform_target(app: App, init_scheduler):
|
||||
from nonebot_plugin_datastore.db import get_engine
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
from sqlalchemy.sql.expression import select
|
||||
|
||||
@@ -133,8 +131,7 @@ async def test_get_platform_target(app: App, init_scheduler):
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=T_Target("weibo_id"),
|
||||
target_name="weibo_name",
|
||||
platform_name="weibo",
|
||||
@@ -142,8 +139,7 @@ async def test_get_platform_target(app: App, init_scheduler):
|
||||
tags=[],
|
||||
)
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=T_Target("weibo_id1"),
|
||||
target_name="weibo_name1",
|
||||
platform_name="weibo",
|
||||
@@ -151,8 +147,7 @@ async def test_get_platform_target(app: App, init_scheduler):
|
||||
tags=[],
|
||||
)
|
||||
await config.add_subscribe(
|
||||
user=245,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=245),
|
||||
target=T_Target("weibo_id1"),
|
||||
target_name="weibo_name1",
|
||||
platform_name="weibo",
|
||||
@@ -161,10 +156,14 @@ async def test_get_platform_target(app: App, init_scheduler):
|
||||
)
|
||||
res = await config.get_platform_target("weibo")
|
||||
assert len(res) == 2
|
||||
await config.del_subscribe(123, "group", T_Target("weibo_id1"), "weibo")
|
||||
await config.del_subscribe(
|
||||
TargetQQGroup(group_id=123), T_Target("weibo_id1"), "weibo"
|
||||
)
|
||||
res = await config.get_platform_target("weibo")
|
||||
assert len(res) == 2
|
||||
await config.del_subscribe(123, "group", T_Target("weibo_id"), "weibo")
|
||||
await config.del_subscribe(
|
||||
TargetQQGroup(group_id=123), T_Target("weibo_id"), "weibo"
|
||||
)
|
||||
res = await config.get_platform_target("weibo")
|
||||
assert len(res) == 1
|
||||
|
||||
@@ -175,6 +174,7 @@ async def test_get_platform_target(app: App, init_scheduler):
|
||||
|
||||
async def test_get_platform_target_subscribers(app: App, init_scheduler):
|
||||
from nonebot_plugin_datastore.db import get_engine
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
from sqlalchemy.sql.expression import select
|
||||
|
||||
@@ -182,12 +182,10 @@ async def test_get_platform_target_subscribers(app: App, 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
|
||||
from nonebot_bison.types import User as T_User
|
||||
from nonebot_bison.types import UserSubInfo
|
||||
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=T_Target("weibo_id"),
|
||||
target_name="weibo_name",
|
||||
platform_name="weibo",
|
||||
@@ -195,8 +193,7 @@ async def test_get_platform_target_subscribers(app: App, init_scheduler):
|
||||
tags=["tag1"],
|
||||
)
|
||||
await config.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=123),
|
||||
target=T_Target("weibo_id1"),
|
||||
target_name="weibo_name1",
|
||||
platform_name="weibo",
|
||||
@@ -204,8 +201,7 @@ async def test_get_platform_target_subscribers(app: App, init_scheduler):
|
||||
tags=["tag2"],
|
||||
)
|
||||
await config.add_subscribe(
|
||||
user=245,
|
||||
user_type="group",
|
||||
TargetQQGroup(group_id=245),
|
||||
target=T_Target("weibo_id1"),
|
||||
target_name="weibo_name1",
|
||||
platform_name="weibo",
|
||||
@@ -215,9 +211,9 @@ async def test_get_platform_target_subscribers(app: App, init_scheduler):
|
||||
|
||||
res = await config.get_platform_target_subscribers("weibo", T_Target("weibo_id"))
|
||||
assert len(res) == 1
|
||||
assert res[0] == UserSubInfo(T_User(123, "group"), [1], ["tag1"])
|
||||
assert res[0] == UserSubInfo(TargetQQGroup(group_id=123), [1], ["tag1"])
|
||||
|
||||
res = await config.get_platform_target_subscribers("weibo", T_Target("weibo_id1"))
|
||||
assert len(res) == 2
|
||||
assert UserSubInfo(T_User(123, "group"), [2], ["tag2"]) in res
|
||||
assert UserSubInfo(T_User(245, "group"), [3], ["tag3"]) in res
|
||||
assert UserSubInfo(TargetQQGroup(group_id=123), [2], ["tag2"]) in res
|
||||
assert UserSubInfo(TargetQQGroup(group_id=245), [3], ["tag3"]) in res
|
||||
|
||||
Reference in New Issue
Block a user