Files
shanxia2.0/backend/tests/test_pl_brand_archive.py
T
2026-07-28 09:34:07 +08:00

65 lines
1.9 KiB
Python

from decimal import Decimal
import pytest
from app.services.pl_brand_archive import validate_brand_qty_rows
def test_required_allows_only_that_brand():
with pytest.raises(ValueError, match="指定品牌"):
validate_brand_qty_rows(
brand_mode="required",
required_brand_id="b1",
actual_qty=Decimal("10"),
rows=[{"brandId": "b2", "brandName": "红四方", "qty": Decimal("10")}],
)
def test_any_sum_must_match():
with pytest.raises(ValueError, match="合计"):
validate_brand_qty_rows(
brand_mode="any",
required_brand_id=None,
actual_qty=Decimal("10"),
rows=[
{"brandId": "b1", "brandName": "君正", "qty": Decimal("6")},
{"brandId": "b2", "brandName": "红四方", "qty": Decimal("3")},
],
)
def test_any_ok():
validate_brand_qty_rows(
brand_mode="any",
required_brand_id=None,
actual_qty=Decimal("10"),
rows=[
{"brandId": "b1", "brandName": "君正", "qty": Decimal("6")},
{"brandId": "b2", "brandName": "红四方", "qty": Decimal("4")},
],
)
def test_no_brand_ignores_rows():
validate_brand_qty_rows(
brand_mode=None,
required_brand_id=None,
actual_qty=Decimal("5"),
rows=[],
)
def test_apply_stock_change_outbound_insufficient():
from app.services.pl_inventory_service import assert_outbound_enough
with pytest.raises(ValueError, match="库存不足"):
assert_outbound_enough(stock_qty=Decimal("1"), outbound_qty=Decimal("2"), brand_label="君正")
def test_delta_for_plan_type():
from app.services.pl_inventory_service import qty_delta_for_plan
assert qty_delta_for_plan("inbound", Decimal("3")) == Decimal("3")
assert qty_delta_for_plan("outbound", Decimal("3")) == Decimal("-3")
assert qty_delta_for_plan("direct", Decimal("3")) == Decimal("0")