perf(douyu): 加速外部协作单账号推荐
This commit is contained in:
@@ -136,6 +136,18 @@ class ProbeClient:
|
||||
return _bind("角色A", bound_act=True, bound_role=True)
|
||||
|
||||
|
||||
class LimitedOnlyClient(ProbeClient):
|
||||
def acf_ccn(self, **_kwargs):
|
||||
raise AssertionError("推荐探针不应查询积分令牌")
|
||||
|
||||
def query_points(self, **_kwargs):
|
||||
raise AssertionError("推荐探针不应查询积分接口")
|
||||
|
||||
def query_limited_goods(self, **_kwargs):
|
||||
self.calls += 1
|
||||
return {"limited_goods": [{"commodityId": "limited-goods"}]}
|
||||
|
||||
|
||||
def test_probe_account_reads_identity_and_does_not_call_activity_for_invalid_ck():
|
||||
account = Account(
|
||||
id=1,
|
||||
@@ -178,6 +190,34 @@ def test_probe_account_reads_identity_and_does_not_call_activity_for_invalid_ck(
|
||||
assert invalid_client.calls == 0
|
||||
|
||||
|
||||
def test_probe_limited_goods_does_not_run_full_eligibility_flow():
|
||||
account = Account(
|
||||
id=2,
|
||||
username="limited-only",
|
||||
password="p",
|
||||
email="limited@example.com",
|
||||
email_password="ep",
|
||||
cookie="acf_uid=200; acf_nickname=limited",
|
||||
)
|
||||
client = LimitedOnlyClient()
|
||||
|
||||
result = probe_account(
|
||||
account,
|
||||
CONFIG,
|
||||
client=client,
|
||||
session_checker=lambda _cookie: {
|
||||
"valid": True,
|
||||
"message": "有效",
|
||||
"checked_at": datetime.now(UTC),
|
||||
},
|
||||
with_eligibility=False,
|
||||
with_limited_goods=True,
|
||||
)
|
||||
|
||||
assert result["eligibility"]["limited_ids"] == ["limited-goods"]
|
||||
assert result["eligibility"]["points"] == 100
|
||||
|
||||
|
||||
def test_persist_probe_error_preserves_last_known_role(db):
|
||||
account = Account(
|
||||
username="preserve-role",
|
||||
|
||||
@@ -44,6 +44,15 @@ class FakeClient:
|
||||
"user_info": {"nickname": "斗鱼昵称"},
|
||||
}
|
||||
|
||||
def acf_ccn(self, **_):
|
||||
return "fake-csrf"
|
||||
|
||||
def query_points(self, **_):
|
||||
return {"points": self.points}
|
||||
|
||||
def query_limited_goods(self, **_):
|
||||
return {"limited_goods": []}
|
||||
|
||||
def bind_info(self, **_):
|
||||
return {
|
||||
"is_bound_account": True,
|
||||
|
||||
Reference in New Issue
Block a user