fix(weibo): 识别支付页拒绝并保护有效 CK 状态

This commit is contained in:
yml2213
2026-11-08 10:04:05 +08:00
parent b7f34df04d
commit ffbe0f41f5
4 changed files with 94 additions and 6 deletions
+30
View File
@@ -14,6 +14,7 @@ from core.weibo import (
WeiboExchangeResult,
WeiboHomeSnapshot,
WeiboPaymentStatus,
WeiboRechargeError,
WeiboRechargeOrder,
)
from web.backend.models import User, WeiboAccount
@@ -360,6 +361,35 @@ def test_manual_recharge_order_and_status_routes_serialize(
assert status["status"] == "PAY_STATUS_PENDING"
def test_recharge_failure_keeps_valid_ck_status(monkeypatch, 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()
def reject_recharge(*_args, **_kwargs):
raise WeiboRechargeError("微博支付页拒绝了当前账号")
monkeypatch.setattr(
StubWeiboClient,
"create_recharge_order",
reject_recharge,
raising=False,
)
with pytest.raises(WeiboRechargeError, match="支付页拒绝"):
weibo_service.create_weibo_recharge_order(
db,
account,
amount_yuan=1,
)
assert account.ck_check_status == "valid"
assert account.ck_check_message == ""
def test_manual_exchange_requires_confirm_and_serializes_result(
monkeypatch, db, current_user
):