feat(weibo): 增加工作台批量充值与批量导入

This commit is contained in:
yml
2026-11-11 20:11:35 +08:00
parent c9814ab4d2
commit 50bb829101
9 changed files with 1353 additions and 60 deletions
+88
View File
@@ -32,6 +32,7 @@ from web.backend.routers.weibo import (
enable_account,
get_account,
import_cookies,
import_workbench_accounts_by_text,
list_account_ids,
list_account_tags,
list_accounts,
@@ -52,6 +53,7 @@ from web.backend.schemas import (
WeiboPaymentStatusRequest,
WeiboRechargeRequest,
WeiboWorkbenchAccountsRequest,
WeiboWorkbenchBatchImportRequest,
)
from web.backend.services import weibo_service
@@ -476,6 +478,92 @@ def test_weibo_workbench_is_isolated_per_user(db, current_user):
assert [item.uid for item in pool_a["items"]] == [first.uid]
def test_batch_import_workbench_accounts_reports_each_identifier(db, current_user):
other_user = User(
username="weibo-batch-import-other",
password_hash="hash",
role="support",
is_active=True,
)
db.add(other_user)
db.commit()
added = WeiboAccount(
uid="4014000901",
nickname="批量导入新账号",
cookie="SCF=a; SUB=added",
)
existing = WeiboAccount(
uid="4014000902",
nickname="批量导入已存在",
cookie="SCF=b; SUB=existing",
)
occupied = WeiboAccount(
uid="4014000903",
nickname="批量导入被占用",
cookie="SCF=c; SUB=occupied",
)
disabled = WeiboAccount(
uid="4014000904",
nickname="批量导入停用",
cookie="SCF=d; SUB=disabled",
is_enabled=False,
)
duplicate_a = WeiboAccount(
uid="4014000905",
nickname="批量导入重名",
cookie="SCF=e; SUB=duplicate-a",
)
duplicate_b = WeiboAccount(
uid="4014000906",
nickname="批量导入重名",
cookie="SCF=f; SUB=duplicate-b",
)
db.add_all([added, existing, occupied, disabled, duplicate_a, duplicate_b])
db.commit()
db.add_all(
[
WeiboWorkbenchAccount(user_id=current_user.id, account_id=existing.id),
WeiboWorkbenchAccount(user_id=other_user.id, account_id=occupied.id),
]
)
db.commit()
result = import_workbench_accounts_by_text(
WeiboWorkbenchBatchImportRequest(
text=(
f"{added.nickname} {added.uid} {existing.uid},{occupied.uid}\n"
"不存在账号;批量导入重名 批量导入停用"
)
),
db=db,
current=current_user,
).model_dump()
assert result["requested"] == 7
assert result["added"] == 1
assert result["already_added"] == 1
assert result["failed"] == 5
assert result["account_ids"] == [added.id]
statuses = {item["identifier"]: item["status"] for item in result["items"]}
assert statuses == {
added.nickname: "added",
added.uid: "duplicate",
existing.uid: "already_added",
occupied.uid: "unavailable",
"不存在账号": "not_found",
"批量导入重名": "ambiguous",
"批量导入停用": "disabled",
}
workbench_ids = {
account_id
for (account_id,) in db.query(WeiboWorkbenchAccount.account_id)
.filter(WeiboWorkbenchAccount.user_id == current_user.id)
.all()
}
assert workbench_ids == {existing.id, added.id}
def test_batch_tag_updates_selected_accounts(db, current_user):
first = WeiboAccount(
uid="4014000201",