feat(douyu): unify account probes and lifecycle writes
Centralize Douyu client creation, CK session probing, identity refresh, role alias resolution, capability persistence, cache and batch throttling across collaboration, fulfillment, tasks and cookie management. Add the account-name copy action in the collaboration table.
This commit is contained in:
@@ -7,9 +7,9 @@ from pathlib import Path
|
||||
from typing import cast
|
||||
|
||||
from core.douyu import DouyuActivityClient
|
||||
from web.backend.models import User
|
||||
from web.backend.models import Account, User
|
||||
from web.backend.routers import douyu as douyu_api
|
||||
from web.backend.services import douyu_activity_query as query
|
||||
from web.backend.services.douyu_account_probe import probe_account
|
||||
|
||||
READ_METHODS = {
|
||||
"acf_ccn",
|
||||
@@ -70,19 +70,33 @@ class FakeActivityClient:
|
||||
}
|
||||
|
||||
|
||||
def test_exchange_eligibility_is_normalized_once():
|
||||
def test_account_probe_normalizes_exchange_eligibility_once():
|
||||
client = FakeActivityClient()
|
||||
|
||||
result = query.query_exchange_eligibility(
|
||||
cast(DouyuActivityClient, client),
|
||||
account = Account(
|
||||
id=1,
|
||||
username="probe-account",
|
||||
password="p",
|
||||
email="probe@example.com",
|
||||
email_password="ep",
|
||||
uid="100",
|
||||
cookie="acf_uid=100; acf_nickname=test",
|
||||
manual_id="manual-1",
|
||||
rid="room-1",
|
||||
)
|
||||
|
||||
assert result.elite_user_info["manual_type"] == 1
|
||||
assert result.points == 5200
|
||||
assert result.limited_ids == frozenset({"limited-1"})
|
||||
result = probe_account(
|
||||
account,
|
||||
{
|
||||
"manual_id": "manual-1",
|
||||
"rid": "room-1",
|
||||
},
|
||||
client=cast(DouyuActivityClient, client),
|
||||
session_checker=None,
|
||||
with_elite_role=False,
|
||||
with_eligibility=True,
|
||||
)
|
||||
|
||||
assert result["elite"]["raw"]["manual_type"] == 1
|
||||
assert result["eligibility"]["points"] == 5200
|
||||
assert result["eligibility"]["limited_ids"] == ["limited-1"]
|
||||
assert client.calls == [
|
||||
"acf_ccn",
|
||||
"elite_user_info",
|
||||
@@ -141,3 +155,50 @@ def test_douyu_read_queries_only_call_client_from_shared_module():
|
||||
)
|
||||
|
||||
assert violations == []
|
||||
|
||||
|
||||
def test_douyu_client_factory_and_role_query_stay_centralized():
|
||||
backend = Path(__file__).parents[1] / "web" / "backend"
|
||||
client_factory = backend / "services" / "douyu_activity_query.py"
|
||||
role_probe = backend / "services" / "douyu_account_probe.py"
|
||||
constructor_violations: list[str] = []
|
||||
role_query_violations: list[str] = []
|
||||
lifecycle_write_violations: list[str] = []
|
||||
|
||||
for path in [
|
||||
*backend.glob("services/douyu_*.py"),
|
||||
*backend.glob("routers/douyu*.py"),
|
||||
]:
|
||||
tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
|
||||
for node in ast.walk(tree):
|
||||
if not isinstance(node, ast.Call):
|
||||
continue
|
||||
func = node.func
|
||||
if (
|
||||
isinstance(func, ast.Name)
|
||||
and func.id == "DouyuActivityClient"
|
||||
and path != client_factory
|
||||
):
|
||||
constructor_violations.append(
|
||||
f"{path.relative_to(backend)}:{node.lineno}"
|
||||
)
|
||||
if (
|
||||
isinstance(func, ast.Name)
|
||||
and func.id == "query_bind_info"
|
||||
and path != role_probe
|
||||
):
|
||||
role_query_violations.append(
|
||||
f"{path.relative_to(backend)}:{node.lineno}"
|
||||
)
|
||||
if (
|
||||
isinstance(func, ast.Name)
|
||||
and func.id == "on_ck_verdict"
|
||||
and path != role_probe
|
||||
):
|
||||
lifecycle_write_violations.append(
|
||||
f"{path.relative_to(backend)}:{node.lineno}"
|
||||
)
|
||||
|
||||
assert constructor_violations == []
|
||||
assert role_query_violations == []
|
||||
assert lifecycle_write_violations == []
|
||||
|
||||
Reference in New Issue
Block a user