Files
live-hub-py/tests/test_huya_rpc_requests.py
T

74 lines
2.1 KiB
Python

"""虎牙 HTTP/WSS 共用 RPC 请求构造测试。"""
from core.huya.activity_structs import GetUserPrizeRecordsReq
from core.huya.rpc_requests import (
activity_records_request,
create_order_v6_request,
play_mall_allocation_request,
)
from core.huya.shop_structs import (
CreateOrderReqV6,
PlayMallAppInfo,
PlayMallQueryAllocationReq,
UserId,
)
def test_activity_records_request_maps_user_and_sid():
user = UserId()
rpc = activity_records_request(user, 2277)
assert rpc.service == "webActUI"
assert rpc.method == "getUserPrizeRecords"
assert isinstance(rpc.request, GetUserPrizeRecordsReq)
assert rpc.request.userId is user
assert rpc.request.sid == 2277
def test_play_mall_allocation_request_maps_tab_parameters():
app = PlayMallAppInfo()
rpc = play_mall_allocation_request(
UserId(),
app,
page_code="heping_baodian_credit_center_page",
scene=7,
page_id=343,
waterfall_tab_id=431,
)
assert rpc.service == "PlayMallUI"
assert rpc.method == "queryAllocation"
assert isinstance(rpc.request, PlayMallQueryAllocationReq)
assert rpc.request.appInfo is app
assert rpc.request.appInfo.scene == 7
assert rpc.request.blank7 == '{"waterfallTabId":"431"}'
assert rpc.request.flag9 == 343
assert rpc.request.flags11 == []
def test_create_order_v6_request_maps_items_across_transports():
rpc = create_order_v6_request(
UserId(),
object(),
pid=123,
items=[
{
"spu_id": "hy-8315982",
"sku_id": 7747527,
"item_count": 1,
"goods_type": 5,
"virtual_type": 507,
}
],
source_id="yellowcarlist",
biz_params="jifencenter",
)
assert rpc.service == "shopMiddleUI"
assert rpc.method == "createOrderV6"
assert isinstance(rpc.request, CreateOrderReqV6)
assert rpc.request.orderType == 6
assert rpc.request.orderScene == 3
assert rpc.request.items[0].spuId == "hy-8315982"
assert rpc.request.items[0].skuId == 7747527