"""纯函数单测:v1→v2 金额均分 / 退费判定(不连库)。""" from decimal import Decimal from types import SimpleNamespace from scripts.migrate_protocol_payment_v1_to_v2 import ( detail_has_refund, split_amount_across, ) def test_split_amount_remainder_on_last(): parts = split_amount_across(Decimal("100.00"), 3) assert parts == [Decimal("33.33"), Decimal("33.33"), Decimal("33.34")] assert sum(parts) == Decimal("100.00") def test_split_amount_none(): assert split_amount_across(None, 2) == [None, None] def test_detail_has_refund_by_status(): assert detail_has_refund(SimpleNamespace( pay_status="ytf", refund_amount=None, refund_attachments=None, refund_remark=None, refund_finance_confirm_attachments=None, refund_finance_remark=None, )) def test_detail_has_refund_by_amount(): assert detail_has_refund(SimpleNamespace( pay_status="yjf", refund_amount=Decimal("1.00"), refund_attachments=None, refund_remark=None, refund_finance_confirm_attachments=None, refund_finance_remark=None, )) def test_detail_no_refund(): assert not detail_has_refund(SimpleNamespace( pay_status="dfj", refund_amount=None, refund_attachments="", refund_remark="", refund_finance_confirm_attachments=None, refund_finance_remark=None, ))