fix(douyu): 升级工作台任务流并修正换绑冷却
This commit is contained in:
@@ -85,7 +85,8 @@ def test_refresh_writes_ck_elite_points_limited_and_bind_lifecycle(db):
|
||||
assert account.elite_opened is True
|
||||
assert account.points == 5200
|
||||
assert account.role_bind_status == "unbound"
|
||||
assert account.change_role_wait_time == 3600
|
||||
# 未确认绑定时 changeRoleWaitTime 是接口占位值,不应写成账号冷却。
|
||||
assert account.change_role_wait_time == 0
|
||||
assert account.role_change_available_at is None
|
||||
assert state.role_change_available_at is None
|
||||
assert state.role_change_blocked is False
|
||||
|
||||
@@ -129,6 +129,8 @@ def test_unbound_wait_time_is_not_a_real_cooldown():
|
||||
|
||||
assert derive_from_bind_info(parsed) == BIND_UNBOUND
|
||||
assert snapshot["bind_confirmed"] is False
|
||||
assert snapshot["change_role_wait_time"] == 0
|
||||
assert snapshot["can_change_time"] is None
|
||||
assert snapshot["is_change_cooling"] is False
|
||||
assert is_role_change_cooling(parsed) is False
|
||||
assert role_change_available_at(parsed) is None
|
||||
@@ -152,6 +154,8 @@ def test_scanned_role_is_pending_until_act_bind():
|
||||
assert snapshot["bind_phase"] == "role_ready"
|
||||
assert snapshot["bind_ready_for_confirm"] is True
|
||||
assert snapshot["bind_confirmed"] is False
|
||||
assert snapshot["change_role_wait_time"] == 0
|
||||
assert snapshot["can_change_time"] is None
|
||||
assert snapshot["is_change_cooling"] is False
|
||||
assert snapshot["role_name"] == "巫师基尔斯84"
|
||||
assert snapshot["game_channel"] == "微信 / 苹果(iOS)"
|
||||
|
||||
@@ -62,6 +62,74 @@ def _fixtures(db, *, status: str = "planned") -> tuple[User, Account, DouyuTask]
|
||||
return user, account, task
|
||||
|
||||
|
||||
def test_query_change_bind_time_ignores_unbound_placeholder_wait(db, monkeypatch):
|
||||
_, account, task = _fixtures(db, status="running")
|
||||
task.task_type = "query_change_bind_time"
|
||||
db.commit()
|
||||
|
||||
activity = {
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "",
|
||||
"is_bound_account": False,
|
||||
"is_bound_role": False,
|
||||
"is_bound_act": False,
|
||||
"need_bind_act": True,
|
||||
"need_bind_role": True,
|
||||
"change_role_wait_time": 2_592_000,
|
||||
"can_change_time": 0,
|
||||
"can_change_role": False,
|
||||
}
|
||||
legacy = {
|
||||
**activity,
|
||||
"act_alias": "cjm",
|
||||
"need_bind_act": False,
|
||||
"change_role_wait_time": 0,
|
||||
}
|
||||
role = {
|
||||
"status": "unbound",
|
||||
"query_act_aliases": ["20260120QYOOB", "cjm"],
|
||||
"bind_infos": [activity, legacy],
|
||||
"bind_info": activity,
|
||||
"candidates": [],
|
||||
"errors": [],
|
||||
"pending_role_name": "",
|
||||
}
|
||||
config = {
|
||||
"legacy_act_alias": "cjm",
|
||||
"confirm_act_alias": "20260120QYOOB",
|
||||
"bind_act_alias": "20260120QYOOB",
|
||||
}
|
||||
runner = DouyuBatchRunner(
|
||||
db,
|
||||
task.batch_id,
|
||||
task.task_type,
|
||||
close_db=False,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"web.backend.services.douyu_runner_bind.resolve_elite_role",
|
||||
lambda *_args, **_kwargs: role,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"web.backend.services.douyu_runner_bind.persist_probe_result",
|
||||
lambda *_args, **_kwargs: None,
|
||||
)
|
||||
|
||||
runner._execute_query_change_bind_time(
|
||||
db,
|
||||
task,
|
||||
account,
|
||||
account.cookie,
|
||||
config,
|
||||
)
|
||||
|
||||
assert task.status == "success"
|
||||
assert task.result["change_role_wait_time"] == 0
|
||||
assert task.result["change_role_wait_text"] == "0"
|
||||
assert task.result["can_change_time"] is None
|
||||
assert task.result["can_change_role"] is True
|
||||
assert "可换绑" in task.message
|
||||
|
||||
|
||||
def test_task_rows_commit_before_started_events(db, monkeypatch):
|
||||
user = User(username="event-order", password_hash="hash", role="operation")
|
||||
db.add(user)
|
||||
|
||||
@@ -6,7 +6,7 @@ import pytest
|
||||
from fastapi import HTTPException
|
||||
from sqlalchemy import func, or_
|
||||
|
||||
from web.backend.models import Account, DouyuTask, User
|
||||
from web.backend.models import Account, DouyuTask, DouyuWorkbenchAccount, User
|
||||
from web.backend.routers.douyu import (
|
||||
_split_task_scope_query,
|
||||
_visible_tasks_query,
|
||||
@@ -310,6 +310,68 @@ def test_support_task_list_matches_legacy_semantics(db):
|
||||
assert exc_info.value.status_code == 403
|
||||
|
||||
|
||||
def test_workbench_task_list_is_limited_to_selected_accounts(db):
|
||||
support, _, admin, _, tasks = _seed_tasks(db)
|
||||
support_account_id = tasks["assigned_elite"].account_id
|
||||
db.add(
|
||||
DouyuWorkbenchAccount(
|
||||
user_id=support.id,
|
||||
handbook_scope="elite",
|
||||
account_id=support_account_id,
|
||||
sort_order=0,
|
||||
)
|
||||
)
|
||||
db.add(
|
||||
DouyuWorkbenchAccount(
|
||||
user_id=admin.id,
|
||||
handbook_scope="elite",
|
||||
account_id=support_account_id,
|
||||
sort_order=0,
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
for user in (support, admin):
|
||||
result = list_tasks(
|
||||
batch_id=None,
|
||||
handbook_scope="elite",
|
||||
workbench_only=True,
|
||||
include_detail=False,
|
||||
page=1,
|
||||
page_size=100,
|
||||
db=db,
|
||||
current=user,
|
||||
)
|
||||
assert result["total"] == 2
|
||||
assert {item.account_id for item in result["items"]} == {support_account_id}
|
||||
assert {item.id for item in result["items"]} == {
|
||||
tasks["assigned_elite"].id,
|
||||
tasks["both_legacy_elite"].id,
|
||||
}
|
||||
|
||||
empty = list_tasks(
|
||||
batch_id=None,
|
||||
handbook_scope="elite",
|
||||
workbench_only=True,
|
||||
include_detail=False,
|
||||
page=1,
|
||||
page_size=100,
|
||||
db=db,
|
||||
current=User(
|
||||
username="task-list-no-workbench",
|
||||
password_hash="hash",
|
||||
role="super_admin",
|
||||
is_active=True,
|
||||
),
|
||||
)
|
||||
assert empty == {
|
||||
"items": [],
|
||||
"total": 0,
|
||||
"page": 1,
|
||||
"page_size": 100,
|
||||
}
|
||||
|
||||
|
||||
def test_empty_support_task_list_stays_empty(db):
|
||||
support = User(
|
||||
username="empty-task-support",
|
||||
|
||||
Reference in New Issue
Block a user