feat(weibo): 修正绑定小程序码并增加账号批量操作
This commit is contained in:
@@ -11,6 +11,7 @@ from core.weibo import (
|
||||
WeiboApiError,
|
||||
WeiboAuthError,
|
||||
WeiboBindError,
|
||||
WeiboBindQrCode,
|
||||
WeiboClient,
|
||||
WeiboExchangeError,
|
||||
WeiboExchangeUncertainError,
|
||||
@@ -187,6 +188,61 @@ def test_generate_bind_scheme_rejects_missing_url_scheme():
|
||||
client.generate_bind_scheme(BIND_URL, "qq")
|
||||
|
||||
|
||||
def test_generate_bind_qrcode_posts_channel_and_preserves_raw_query():
|
||||
session = FakeSession(
|
||||
[
|
||||
{
|
||||
"iRet": 0,
|
||||
"sMsg": "ok",
|
||||
"jData": {
|
||||
"qrcode": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB",
|
||||
"qrcodeToken": "token-1",
|
||||
},
|
||||
}
|
||||
]
|
||||
)
|
||||
client = WeiboClient(session=session)
|
||||
|
||||
qrcode = client.generate_bind_qrcode(BIND_URL, "qq")
|
||||
|
||||
assert isinstance(qrcode, WeiboBindQrCode)
|
||||
assert qrcode.image_src == (
|
||||
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB"
|
||||
)
|
||||
assert qrcode.token == "token-1"
|
||||
method, url, kwargs = session.calls[0]
|
||||
assert method == "POST"
|
||||
assert url == "https://livelinkbind.game.qq.com/api/qrcode/getMiniAppQrcode"
|
||||
body = kwargs["json"]
|
||||
raw_url = extract_bind_raw_url(BIND_URL)
|
||||
assert body["queryString"].startswith(f"{raw_url}&sessionId=")
|
||||
assert body["accountType"] == "qq"
|
||||
assert kwargs["headers"]["Gap-Act-Id"] == "16722"
|
||||
assert kwargs["headers"]["Gap-Plat-Id"] == "weiyouxi"
|
||||
assert kwargs["headers"]["Gap-User-From"] == "pc"
|
||||
assert "Cookie" not in kwargs["headers"]
|
||||
|
||||
|
||||
def test_generate_bind_qrcode_supports_jpeg_and_server_rate_limit():
|
||||
jpeg_session = FakeSession(
|
||||
[
|
||||
{
|
||||
"iRet": 0,
|
||||
"sMsg": "ok",
|
||||
"jData": {"qrcode": "/9j/4AAQSkZJRgABAQ", "qrcodeToken": "token-2"},
|
||||
}
|
||||
]
|
||||
)
|
||||
qrcode = WeiboClient(session=jpeg_session).generate_bind_qrcode(BIND_URL, "wx")
|
||||
assert qrcode.image_src == "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ"
|
||||
|
||||
rate_limited = FakeSession(
|
||||
[{"iRet": -1140603, "sMsg": "刷新二维码频率过快,请间隔5秒后重试"}]
|
||||
)
|
||||
with pytest.raises(WeiboBindError, match="间隔5秒"):
|
||||
WeiboClient(session=rate_limited).generate_bind_qrcode(BIND_URL, "qq")
|
||||
|
||||
|
||||
def test_mall_exchange_and_point_queries():
|
||||
session = FakeSession(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user