feat(douyu): 精英宝典导入支持按多行账户名筛选

对齐 Cookie 自定义 CK 的粘贴导入方式,按账户名精确匹配并保持粘贴顺序。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
yml2213
2026-09-29 15:02:53 +08:00
co-authored by Cursor
parent 1ac6a13a2c
commit 4806d4bbf1
4 changed files with 238 additions and 59 deletions
+84
View File
@@ -0,0 +1,84 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from web.backend.database import Base
from web.backend.models import Account, LoginTask, User
from web.backend.routers.douyu import (
_parse_account_names,
list_task_account_ids,
list_task_accounts,
)
class TestDouyuAccountNameFilter:
def setup_method(self):
self.engine = create_engine("sqlite://")
Base.metadata.create_all(self.engine)
self.session = sessionmaker(bind=self.engine)()
self.user = User(username="admin", password_hash="hash", role="super_admin")
self.session.add(self.user)
self.session.commit()
self.accounts = {}
for name in ("account-a", "account-b", "account-c"):
account = Account(
username=name,
password="password",
email=f"{name}@example.com",
email_password="mail-password",
)
self.session.add(account)
self.session.flush()
self.session.add(
LoginTask(
batch_id=f"login-{name}",
account_id=account.id,
created_by=self.user.id,
status="success",
cookie="acf_uid=1",
)
)
self.accounts[name] = account
self.session.commit()
def teardown_method(self):
self.session.close()
Base.metadata.drop_all(self.engine)
self.engine.dispose()
def test_parse_account_names_trims_and_dedupes(self):
assert _parse_account_names(
"account-c\n\naccount-a\r\naccount-c\n account-b "
) == [
"account-c",
"account-a",
"account-b",
]
def test_list_task_accounts_follows_paste_order(self):
result = list_task_accounts(
search="",
tag="",
ids="",
account_names="account-c\naccount-a",
page=1,
page_size=50,
db=self.session,
current=self.user,
)
assert result["total"] == 2
assert [item.username for item in result["items"]] == ["account-c", "account-a"]
def test_list_task_account_ids_follows_paste_order(self):
result = list_task_account_ids(
search="",
tag="",
account_names="account-c\nmissing-name\naccount-a",
db=self.session,
current=self.user,
)
assert result["account_ids"] == [
self.accounts["account-c"].id,
self.accounts["account-a"].id,
]
assert result["total"] == 2