56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
"""Tests for protocol invoice request CRUD helpers."""
|
|
|
|
import unittest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
|
class TestInstallmentSummary(unittest.TestCase):
|
|
def test_build_installment_summary_single(self):
|
|
from app.crud.collection_protocol import build_installment_summary
|
|
|
|
self.assertEqual(build_installment_summary([1]), "第1期")
|
|
|
|
def test_build_installment_summary_multi(self):
|
|
from app.crud.collection_protocol import build_installment_summary
|
|
|
|
self.assertEqual(build_installment_summary([1, 2, 3]), "第1、2、3期")
|
|
|
|
def test_build_installment_summary_lump_sum(self):
|
|
from app.crud.collection_protocol import build_installment_summary
|
|
|
|
self.assertEqual(build_installment_summary([None]), "趸交")
|
|
|
|
|
|
class TestCreateInvoiceRequestValidation(unittest.TestCase):
|
|
def test_rejects_empty_payment_detail_ids(self):
|
|
from app.crud.collection_protocol import create_invoice_request
|
|
|
|
mock_db = MagicMock()
|
|
with self.assertRaises(ValueError) as ctx:
|
|
create_invoice_request(
|
|
mock_db,
|
|
collection_protocol_id="proto-1",
|
|
payment_detail_ids=[],
|
|
tenant_no="t1",
|
|
)
|
|
self.assertIn("至少选择", str(ctx.exception))
|
|
|
|
@patch("app.crud.collection_protocol._active_invoiced_payment_detail_ids", return_value={"pd-1"})
|
|
def test_rejects_duplicate_payment_detail_in_active_request(self, _mock_active):
|
|
from app.crud.collection_protocol import create_invoice_request
|
|
|
|
mock_db = MagicMock()
|
|
with self.assertRaises(ValueError) as ctx:
|
|
create_invoice_request(
|
|
mock_db,
|
|
collection_protocol_id="proto-1",
|
|
payment_detail_ids=["pd-1"],
|
|
tenant_no="t1",
|
|
user_info={"user_id": "u1"},
|
|
)
|
|
self.assertIn("已申请开票", str(ctx.exception))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|