test_pl_transport_stop_feedback.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """运输计划按段现场回传校验"""
  2. import pytest
  3. from app.services.pl_transport_stop_feedback_service import (
  4. _dump_product_feedbacks,
  5. _parse_product_feedbacks,
  6. save_site_stop_feedback,
  7. )
  8. def test_parse_and_dump_driver_stop_product_feedbacks():
  9. raw = _dump_product_feedbacks(
  10. [
  11. {
  12. "stopProductId": "sp1",
  13. "actualQty": 12.5,
  14. "brandQtys": [{"brandId": "b1", "brandName": "品牌A", "qty": 12.5}],
  15. }
  16. ]
  17. )
  18. parsed = _parse_product_feedbacks(raw)
  19. assert "sp1" in parsed
  20. assert parsed["sp1"]["actualQty"] == 12.5
  21. assert parsed["sp1"]["brandQtys"][0]["brandName"] == "品牌A"
  22. def test_save_site_stop_feedback_requires_quantity_before_attachments():
  23. with pytest.raises(ValueError, match="请先填写数量"):
  24. save_site_stop_feedback(
  25. db=None, # type: ignore[arg-type]
  26. tenant_no="t1",
  27. transport_id="tr1",
  28. plan_id="p1",
  29. stop_type="load",
  30. stop_id="s1",
  31. business_type="出库",
  32. quantity=None,
  33. attachment_urls=["a.jpg"],
  34. )
  35. def test_save_site_stop_feedback_requires_product_qty_before_attachments():
  36. with pytest.raises(ValueError, match="请先填写数量"):
  37. save_site_stop_feedback(
  38. db=None, # type: ignore[arg-type]
  39. tenant_no="t1",
  40. transport_id="tr1",
  41. plan_id="p1",
  42. stop_type="load",
  43. stop_id="s1",
  44. business_type="出库",
  45. products=[{"stopProductId": "sp1", "actualQty": 0}],
  46. attachment_urls=["a.jpg"],
  47. )