test_pl_trailer_cert_rules.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """挂车号分流:货拉拉免挂车证;自有正常挂车号强制;三方不强制。"""
  2. from __future__ import annotations
  3. import pytest
  4. from fastapi import HTTPException
  5. from app.services.pl_cert_required_service import (
  6. is_huolala_trailer_no,
  7. should_require_trailer_certs,
  8. should_show_trailer_cert_slots,
  9. validate_self_vehicle_required_certs,
  10. )
  11. def _complete_self_head_certs():
  12. return [
  13. {"cert_name": "行驶证", "expire_date": "2030-01-01", "vehicle_part": "head"},
  14. {"cert_name": "营运证", "expire_date": "2030-01-01", "vehicle_part": "head"},
  15. {"cert_name": "保险单", "expire_date": "2030-01-01", "vehicle_part": "head"},
  16. ]
  17. def test_huolala_trailer_helpers():
  18. assert is_huolala_trailer_no("货拉拉")
  19. assert is_huolala_trailer_no(" 货拉拉 ")
  20. assert not is_huolala_trailer_no("皖LP359")
  21. assert not should_show_trailer_cert_slots("货拉拉")
  22. assert should_show_trailer_cert_slots("皖LP359")
  23. assert not should_require_trailer_certs("self", "货拉拉")
  24. assert should_require_trailer_certs("self", "皖LP359")
  25. assert not should_require_trailer_certs("carrier", "皖LP359")
  26. def test_self_huolala_skips_trailer_required_certs():
  27. validate_self_vehicle_required_certs(
  28. _complete_self_head_certs(),
  29. trailer_no="货拉拉",
  30. )
  31. def test_self_normal_trailer_requires_trailer_certs():
  32. with pytest.raises(HTTPException) as ei:
  33. validate_self_vehicle_required_certs(
  34. _complete_self_head_certs(),
  35. trailer_no="皖LP359",
  36. )
  37. assert ei.value.status_code == 400
  38. assert "挂车" in ei.value.detail