feat(huya): 统一实时商品目录并增加兑换代理开关
This commit is contained in:
@@ -6,6 +6,7 @@ from types import SimpleNamespace
|
||||
|
||||
from web.backend.models import HuyaAccount
|
||||
from web.backend.services import huya_points_exchange as exchange
|
||||
from web.backend.services import huya_runner_goods
|
||||
from web.backend.services.huya_runner import HuyaBatchRunner
|
||||
from web.backend.services.huya_shop_flow import ShopOrderOutcome
|
||||
|
||||
@@ -79,6 +80,29 @@ def _state(*, full: bool, precondition: bool = True, plans=None):
|
||||
)
|
||||
|
||||
|
||||
def _mock_live_goods(
|
||||
monkeypatch,
|
||||
*,
|
||||
product_id: str = "hy-8315982",
|
||||
name: str = "幸运币礼包(小)",
|
||||
):
|
||||
monkeypatch.setattr(
|
||||
huya_runner_goods,
|
||||
"fetch_points_center_catalog",
|
||||
lambda *_args, **_kwargs: SimpleNamespace(
|
||||
goods=[
|
||||
{
|
||||
"product_id": product_id,
|
||||
"name": name,
|
||||
"price": 20,
|
||||
"remain_text": "100",
|
||||
}
|
||||
],
|
||||
message="已拉取 1 个礼包",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def test_points_enough_uses_create_order_v6_without_payment(monkeypatch):
|
||||
client = _Client([_state(full=True)])
|
||||
purchase_called = False
|
||||
@@ -209,6 +233,7 @@ def test_precondition_failure_does_not_create_order():
|
||||
|
||||
def test_runner_uses_points_exchange_service_for_direct_redeem(monkeypatch):
|
||||
client = _Client([_state(full=True)])
|
||||
_mock_live_goods(monkeypatch)
|
||||
runner = HuyaBatchRunner(
|
||||
db=None,
|
||||
batch_id="exchange-direct",
|
||||
@@ -261,6 +286,7 @@ def test_runner_waits_points_payment_then_redeems(monkeypatch):
|
||||
_state(full=True),
|
||||
]
|
||||
)
|
||||
_mock_live_goods(monkeypatch)
|
||||
runner = HuyaBatchRunner(
|
||||
db=None,
|
||||
batch_id="exchange-pay",
|
||||
@@ -325,8 +351,6 @@ def test_runner_waits_points_payment_then_redeems(monkeypatch):
|
||||
|
||||
|
||||
def test_runner_refresh_goods_uses_points_center_query(monkeypatch):
|
||||
from web.backend.services import huya_collab_service
|
||||
|
||||
runner = HuyaBatchRunner(
|
||||
db=None,
|
||||
batch_id="refresh-points-goods",
|
||||
@@ -351,12 +375,12 @@ def test_runner_refresh_goods_uses_points_center_query(monkeypatch):
|
||||
added.append(item)
|
||||
|
||||
monkeypatch.setattr(
|
||||
huya_collab_service,
|
||||
"fetch_points_center_gifts",
|
||||
huya_runner_goods,
|
||||
"fetch_points_center_catalog",
|
||||
lambda uid, cookie, **kwargs: (
|
||||
calls.append((uid, cookie, kwargs))
|
||||
or (
|
||||
[
|
||||
or SimpleNamespace(
|
||||
goods=[
|
||||
{
|
||||
"product_id": "hy-8315982",
|
||||
"name": "幸运币礼包(小)",
|
||||
@@ -365,7 +389,7 @@ def test_runner_refresh_goods_uses_points_center_query(monkeypatch):
|
||||
"stock": 11197,
|
||||
}
|
||||
],
|
||||
"已拉取 1 个礼包",
|
||||
message="已拉取 1 个礼包",
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user