| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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
|