138 lines
4.2 KiB
Python
138 lines
4.2 KiB
Python
"""接口 2:从表 2 取 push_status=0,组装文档报文。不连 Oracle,不发 HTTP。"""
|
||
from __future__ import annotations
|
||
|
||
from decimal import Decimal
|
||
|
||
from app.outbound.cart_settlement import (
|
||
MAX_BATCH,
|
||
build_cart_settlement_envelope,
|
||
load_cart_settlement_envelope,
|
||
)
|
||
from app.outbound.memory_repo import MemoryCartSettlementRepo
|
||
|
||
|
||
def _row(**overrides):
|
||
row = {
|
||
"fid": 100001,
|
||
"operate_type": 1,
|
||
"oms_id": 20260928000001,
|
||
"platform_type": 48,
|
||
"supplier_name": "示例供应商",
|
||
"bar_code": "06901234567890",
|
||
"purchase_price": Decimal("128.5000"),
|
||
"purchase_qty": 10,
|
||
"purchase_total": Decimal("1285.0000"),
|
||
"status": 1,
|
||
"fail_reason": None,
|
||
"pay_order_no": None,
|
||
"pay_order_dtl_id": None,
|
||
"org_code": "901",
|
||
"push_status": 0,
|
||
"multi_platform_flag": 0,
|
||
}
|
||
row.update(overrides)
|
||
return row
|
||
|
||
|
||
def test_assembles_unpushed_rows_as_document_envelope():
|
||
repo = MemoryCartSettlementRepo(
|
||
[
|
||
_row(),
|
||
_row(
|
||
fid=100002,
|
||
operate_type=2,
|
||
platform_type=66,
|
||
status=None,
|
||
pay_order_no="PAY20260928000001",
|
||
pay_order_dtl_id="1233",
|
||
),
|
||
]
|
||
)
|
||
envelope = load_cart_settlement_envelope(repo)
|
||
assert envelope == {
|
||
"data": [
|
||
{
|
||
"fid": 100001,
|
||
"operateType": 1,
|
||
"omsId": 20260928000001,
|
||
"platformType": 48,
|
||
"supplierName": "示例供应商",
|
||
"barCode": "06901234567890",
|
||
"purchasePrice": "128.5000",
|
||
"purchaseQty": 10,
|
||
"purchaseTotal": "1285.0000",
|
||
"status": 1,
|
||
"failReason": None,
|
||
"payOrderNo": None,
|
||
"payOrderDtlId": None,
|
||
"orgCode": "901",
|
||
},
|
||
{
|
||
"fid": 100002,
|
||
"operateType": 2,
|
||
"omsId": 20260928000001,
|
||
"platformType": 66,
|
||
"supplierName": "示例供应商",
|
||
"barCode": "06901234567890",
|
||
"purchasePrice": "128.5000",
|
||
"purchaseQty": 10,
|
||
"purchaseTotal": "1285.0000",
|
||
"status": None,
|
||
"failReason": None,
|
||
"payOrderNo": "PAY20260928000001",
|
||
"payOrderDtlId": "1233",
|
||
"orgCode": "901",
|
||
},
|
||
]
|
||
}
|
||
|
||
|
||
def test_skips_already_pushed_rows():
|
||
repo = MemoryCartSettlementRepo(
|
||
[
|
||
_row(fid=1, push_status=1),
|
||
_row(fid=2, oms_id=20260928000002, push_status=0),
|
||
]
|
||
)
|
||
envelope = load_cart_settlement_envelope(repo)
|
||
assert [item["fid"] for item in envelope["data"]] == [2]
|
||
|
||
|
||
def test_keeps_same_oms_id_in_one_envelope():
|
||
rows = [
|
||
_row(fid=1, oms_id=1, platform_type=48, multi_platform_flag=1),
|
||
_row(fid=2, oms_id=1, platform_type=66, multi_platform_flag=1),
|
||
_row(fid=3, oms_id=2, platform_type=48),
|
||
]
|
||
envelope = build_cart_settlement_envelope(rows, limit=2)
|
||
fids = [item["fid"] for item in envelope["data"]]
|
||
assert fids == [1, 2]
|
||
|
||
|
||
def test_does_not_split_oms_id_group_across_batch_limit():
|
||
rows = [
|
||
_row(fid=1, oms_id=1, platform_type=48),
|
||
_row(fid=2, oms_id=2, platform_type=48, multi_platform_flag=1),
|
||
_row(fid=3, oms_id=2, platform_type=66, multi_platform_flag=1),
|
||
]
|
||
envelope = build_cart_settlement_envelope(rows, limit=2)
|
||
assert [item["fid"] for item in envelope["data"]] == [1]
|
||
|
||
|
||
def test_batch_cap_is_500():
|
||
assert MAX_BATCH == 500
|
||
rows = [_row(fid=i, oms_id=i) for i in range(1, 502)]
|
||
envelope = build_cart_settlement_envelope(rows)
|
||
assert len(envelope["data"]) == 500
|
||
assert envelope["data"][0]["fid"] == 1
|
||
assert envelope["data"][-1]["fid"] == 500
|
||
|
||
|
||
def test_payload_omits_table_only_columns():
|
||
envelope = build_cart_settlement_envelope([_row()])
|
||
item = envelope["data"][0]
|
||
assert "pushStatus" not in item
|
||
assert "push_status" not in item
|
||
assert "multiPlatformFlag" not in item
|
||
assert "createTime" not in item
|