Files
shanxia2.0/backend/tests/test_pl_feedback_brand_qty.py
T

76 lines
2.0 KiB
Python

from decimal import Decimal
import pytest
from app.services.pl_feedback_brand_qty import format_brand_qty_summary, require_brand_qtys_if_needed
def test_format_brand_qty_summary():
s = format_brand_qty_summary([
{"brandName": "君正", "qty": Decimal("16")},
{"brandName": "红四方", "qty": Decimal("12.000")},
])
assert s == "君正 16 / 红四方 12"
def test_format_brand_qty_summary_empty():
assert format_brand_qty_summary([]) is None
def test_format_brand_qty_summary_zero_only():
assert format_brand_qty_summary([{"brandName": "君正", "qty": Decimal("0")}]) is None
def test_require_skips_when_no_brand_mode():
require_brand_qtys_if_needed(
brand_mode=None,
required_brand_id=None,
actual_qty=Decimal("10"),
rows=[],
enforce=True,
)
def test_require_skips_when_not_enforced():
require_brand_qtys_if_needed(
brand_mode="any",
required_brand_id=None,
actual_qty=Decimal("10"),
rows=[],
enforce=False,
)
def test_require_enforces_when_completed():
with pytest.raises(ValueError, match="至少一个品牌数量"):
require_brand_qtys_if_needed(
brand_mode="any",
required_brand_id=None,
actual_qty=Decimal("10"),
rows=[],
enforce=True,
)
def test_require_calls_validate_when_positive_rows(monkeypatch):
called = {}
def mock_validate(**kwargs):
called.update(kwargs)
monkeypatch.setattr(
"app.services.pl_feedback_brand_qty.validate_brand_qty_rows",
mock_validate,
)
rows = [{"brandId": "b1", "brandName": "君正", "qty": Decimal("10")}]
require_brand_qtys_if_needed(
brand_mode="any",
required_brand_id=None,
actual_qty=Decimal("10"),
rows=rows,
enforce=True,
)
assert called["brand_mode"] == "any"
assert called["actual_qty"] == Decimal("10")
assert called["rows"] == rows