fix(weibo): 将支付风控检测并入账号 CK 校验
This commit is contained in:
@@ -53,6 +53,7 @@ class StubWeiboClient:
|
||||
bind_url=BIND_URL,
|
||||
)
|
||||
scheme_errors: ClassVar[dict[str, str]] = {}
|
||||
payment_error: ClassVar[WeiboRechargeError | None] = None
|
||||
calls: ClassVar[list[tuple[str, str]]] = []
|
||||
|
||||
def __init__(self, cookie: str = "", **_kwargs):
|
||||
@@ -64,6 +65,12 @@ class StubWeiboClient:
|
||||
raise WeiboAuthError("未登陆")
|
||||
return self.snapshot
|
||||
|
||||
def check_payment_access(self, activity: str = "", *, home=None):
|
||||
_ = home
|
||||
self.calls.append(("payment", activity))
|
||||
if self.payment_error is not None:
|
||||
raise self.payment_error
|
||||
|
||||
def generate_bind_scheme(self, bind_url: str, account_type: str):
|
||||
self.calls.append(("scheme", account_type))
|
||||
error = self.scheme_errors.get(account_type)
|
||||
@@ -89,6 +96,7 @@ def current_user(db):
|
||||
def stub_client(monkeypatch):
|
||||
StubWeiboClient.calls = []
|
||||
StubWeiboClient.scheme_errors = {}
|
||||
StubWeiboClient.payment_error = None
|
||||
StubWeiboClient.snapshot = WeiboHomeSnapshot(
|
||||
uid="4014000001",
|
||||
nickname="测试微博",
|
||||
@@ -147,6 +155,37 @@ def test_import_reports_invalid_ck_per_line_and_keeps_valid_account(db, current_
|
||||
assert db.query(WeiboAccount).count() == 1
|
||||
|
||||
|
||||
def test_import_reports_payment_access_failure(db, current_user):
|
||||
StubWeiboClient.payment_error = WeiboRechargeError("触发微博账号风控")
|
||||
|
||||
result = import_cookies(
|
||||
WeiboCookieImport(text="SCF=a; SUB=b", tag=""),
|
||||
db=db,
|
||||
current=current_user,
|
||||
)
|
||||
|
||||
assert result.count == 0
|
||||
assert len(result.errors) == 1
|
||||
assert "触发微博账号风控" in result.errors[0].message
|
||||
assert db.query(WeiboAccount).count() == 0
|
||||
|
||||
|
||||
def test_refresh_marks_payment_access_failure(db, current_user):
|
||||
account_out = import_cookies(
|
||||
WeiboCookieImport(text="SCF=a; SUB=b", tag=""),
|
||||
db=db,
|
||||
current=current_user,
|
||||
).accounts[0]
|
||||
account = db.query(WeiboAccount).filter(WeiboAccount.id == account_out.id).one()
|
||||
StubWeiboClient.payment_error = WeiboRechargeError("触发微博账号风控")
|
||||
|
||||
with pytest.raises(WeiboRechargeError, match="触发微博账号风控"):
|
||||
weibo_service.refresh_weibo_account(db, account)
|
||||
|
||||
assert account.ck_check_status == "error"
|
||||
assert "触发微博账号风控" in account.ck_check_message
|
||||
|
||||
|
||||
def test_list_accounts_returns_parallel_page_shape(db, current_user):
|
||||
assert (
|
||||
import_cookies(
|
||||
|
||||
Reference in New Issue
Block a user