test_migrate_protocol_payment_v1_to_v2.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """纯函数单测:v1→v2 金额均分 / 退费判定(不连库)。"""
  2. from decimal import Decimal
  3. from types import SimpleNamespace
  4. from scripts.migrate_protocol_payment_v1_to_v2 import (
  5. detail_has_refund,
  6. split_amount_across,
  7. )
  8. def test_split_amount_remainder_on_last():
  9. parts = split_amount_across(Decimal("100.00"), 3)
  10. assert parts == [Decimal("33.33"), Decimal("33.33"), Decimal("33.34")]
  11. assert sum(parts) == Decimal("100.00")
  12. def test_split_amount_none():
  13. assert split_amount_across(None, 2) == [None, None]
  14. def test_detail_has_refund_by_status():
  15. assert detail_has_refund(SimpleNamespace(
  16. pay_status="ytf",
  17. refund_amount=None,
  18. refund_attachments=None,
  19. refund_remark=None,
  20. refund_finance_confirm_attachments=None,
  21. refund_finance_remark=None,
  22. ))
  23. def test_detail_has_refund_by_amount():
  24. assert detail_has_refund(SimpleNamespace(
  25. pay_status="yjf",
  26. refund_amount=Decimal("1.00"),
  27. refund_attachments=None,
  28. refund_remark=None,
  29. refund_finance_confirm_attachments=None,
  30. refund_finance_remark=None,
  31. ))
  32. def test_detail_no_refund():
  33. assert not detail_has_refund(SimpleNamespace(
  34. pay_status="dfj",
  35. refund_amount=None,
  36. refund_attachments="",
  37. refund_remark="",
  38. refund_finance_confirm_attachments=None,
  39. refund_finance_remark=None,
  40. ))