|
|
@@ -5,13 +5,37 @@ 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="指定品牌"):
|
|
|
+def test_required_allows_other_brand_when_sum_matches():
|
|
|
+ validate_brand_qty_rows(
|
|
|
+ brand_mode="required",
|
|
|
+ required_brand_id="b1",
|
|
|
+ actual_qty=Decimal("10"),
|
|
|
+ rows=[{"brandId": "b2", "brandName": "红四方", "qty": Decimal("10")}],
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def test_required_allows_multi_brand_when_sum_matches():
|
|
|
+ validate_brand_qty_rows(
|
|
|
+ brand_mode="required",
|
|
|
+ required_brand_id="b1",
|
|
|
+ actual_qty=Decimal("10"),
|
|
|
+ rows=[
|
|
|
+ {"brandId": "b1", "brandName": "君正", "qty": Decimal("6")},
|
|
|
+ {"brandId": "b2", "brandName": "红四方", "qty": Decimal("4")},
|
|
|
+ ],
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def test_required_sum_must_match():
|
|
|
+ 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")}],
|
|
|
+ rows=[
|
|
|
+ {"brandId": "b1", "brandName": "君正", "qty": Decimal("6")},
|
|
|
+ {"brandId": "b2", "brandName": "红四方", "qty": Decimal("3")},
|
|
|
+ ],
|
|
|
)
|
|
|
|
|
|
|