feat(weibo): 修正绑定小程序码并增加账号批量操作
This commit is contained in:
@@ -11,6 +11,7 @@ from sqlalchemy import text
|
||||
from core.weibo import (
|
||||
WeiboAuthError,
|
||||
WeiboBindError,
|
||||
WeiboBindQrCode,
|
||||
WeiboExchangeResult,
|
||||
WeiboHomeSnapshot,
|
||||
WeiboPaymentStatus,
|
||||
@@ -90,6 +91,17 @@ class StubWeiboClient:
|
||||
)
|
||||
return prefix
|
||||
|
||||
def generate_bind_qrcode(self, bind_url: str, account_type: str):
|
||||
self.calls.append(("qrcode", account_type))
|
||||
error = self.scheme_errors.get(account_type)
|
||||
if error:
|
||||
raise WeiboBindError(error)
|
||||
mime = "png" if account_type == "wx" else "jpeg"
|
||||
return WeiboBindQrCode(
|
||||
image_src=f"data:image/{mime};base64,test-{account_type}",
|
||||
token=f"token-{account_type}",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def current_user(db):
|
||||
@@ -333,6 +345,32 @@ def test_bind_qrcodes_returns_both_channels_and_partial_error(db, current_user):
|
||||
assert by_channel["qq"]["error"] == "QQ Scheme 暂时不可用"
|
||||
|
||||
|
||||
def test_bind_qrcodes_selected_channel_returns_scannable_image(db, current_user):
|
||||
account = import_cookies(
|
||||
WeiboCookieImport(text="SCF=a; SUB=b", tag=""),
|
||||
db=db,
|
||||
current=current_user,
|
||||
).accounts[0]
|
||||
|
||||
result = create_bind_qrcodes(
|
||||
account.id,
|
||||
channel="qq",
|
||||
db=db,
|
||||
current=current_user,
|
||||
)
|
||||
|
||||
dumped = result.model_dump()
|
||||
assert len(dumped["schemes"]) == 1
|
||||
qq = dumped["schemes"][0]
|
||||
assert qq["channel"] == "qq"
|
||||
assert qq["qrcode_image"] == "data:image/jpeg;base64,test-qq"
|
||||
assert qq["qrcode_token"] == "token-qq"
|
||||
assert qq["scheme"].startswith("mqqapi://miniapp/open")
|
||||
assert [call for call in StubWeiboClient.calls if call[0] == "qrcode"] == [
|
||||
("qrcode", "qq")
|
||||
]
|
||||
|
||||
|
||||
def test_bind_qrcodes_rejects_bound_account_without_rebind(db, current_user):
|
||||
account = import_cookies(
|
||||
WeiboCookieImport(text="SCF=a; SUB=b", tag=""),
|
||||
|
||||
Reference in New Issue
Block a user