feat(fulfillment): 自动选号并补充精英宝典操作
- 增加直播履约自动选号 worker、重试与任务扫描 - 履约详情复用斗鱼任务能力开通宝典、充值和兑换皮肤 - 补充自动选号与精英宝典操作测试
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
"""直播账号履约自动选号 worker。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from web.backend.models import PlatformFulfillmentTask, User
|
||||
from web.backend.services.platform_fulfillment import auto_allocator
|
||||
|
||||
|
||||
def test_auto_allocator_only_scans_ready_unassigned_tasks(db):
|
||||
actor = User(username="auto-alloc-actor", password_hash="h", role="super_admin")
|
||||
ready = PlatformFulfillmentTask(
|
||||
source_system="order_site",
|
||||
source_order_id="1",
|
||||
source_order_item_id="1",
|
||||
platform_order_id="AUTO-1",
|
||||
internal_sku_key="skin",
|
||||
commodity_id="commodity-1",
|
||||
execution_status="ready",
|
||||
binding_status="not_started",
|
||||
exchange_status="not_started",
|
||||
updated_at=datetime.now(UTC) - timedelta(minutes=2),
|
||||
)
|
||||
mapped_pending = PlatformFulfillmentTask(
|
||||
source_system="order_site",
|
||||
source_order_id="2",
|
||||
source_order_item_id="2",
|
||||
platform_order_id="AUTO-2",
|
||||
internal_sku_key="skin",
|
||||
commodity_id="commodity-1",
|
||||
execution_status="pending_mapping",
|
||||
binding_status="not_started",
|
||||
exchange_status="not_started",
|
||||
updated_at=datetime.now(UTC) - timedelta(minutes=2),
|
||||
)
|
||||
db.add_all([actor, ready, mapped_pending])
|
||||
db.commit()
|
||||
|
||||
calls: list[int] = []
|
||||
with (
|
||||
patch.object(auto_allocator.service, "_integration_actor", return_value=actor),
|
||||
patch.object(
|
||||
auto_allocator.service,
|
||||
"allocate_task",
|
||||
side_effect=lambda _db, *, task_id, current: (
|
||||
calls.append(task_id)
|
||||
or {"task": {"account": {"id": 9}}}
|
||||
),
|
||||
),
|
||||
):
|
||||
result = auto_allocator.run_auto_allocation_once(db, limit=10)
|
||||
|
||||
assert calls == [ready.id]
|
||||
assert result == {"checked": 1, "allocated": 1, "failed": 0}
|
||||
Reference in New Issue
Block a user