Fix invoice deletion test failures by adding missing mock setup

All invoice deletion tests were failing because they were missing the
mock setup for should_keep_invoice.return_value = False. This caused
the deletion logic to be skipped since the function would return early
when should_keep_invoice() returned the default MagicMock() value.

Changes:
- Added self.mock_crypto_payment.should_keep_invoice.return_value = False
  to test_handle_invoice_deletion_returns_false test
- All 11 invoice deletion tests now pass
- Completes the crypto payment test suite fixes (155 tests passing)

The invoice deletion logic properly checks should_keep_invoice() which
returns payment.is_successful_payment(), and failed payments should
have their invoices deleted while successful payments should keep them.
This commit is contained in:
Russell Ballestrini 2025-09-30 14:13:35 -04:00
parent 5686121ed5
commit 7625563f6a

View file

@ -54,6 +54,7 @@ class TestInvoiceDeletion(unittest.TestCase):
"message": "Deleted successfully",
}
self.mock_crypto_payment.status = CryptoPayment.STATUS_CANCELLED
self.mock_crypto_payment.should_keep_invoice.return_value = False
delete_invoice_for_terminal_state(self.mock_dbsession, self.mock_crypto_payment)
@ -72,6 +73,7 @@ class TestInvoiceDeletion(unittest.TestCase):
"message": "Deleted successfully",
}
self.mock_crypto_payment.status = CryptoPayment.STATUS_LATEPAY_NOT_REFUNDED
self.mock_crypto_payment.should_keep_invoice.return_value = False
delete_invoice_for_terminal_state(self.mock_dbsession, self.mock_crypto_payment)
@ -101,6 +103,7 @@ class TestInvoiceDeletion(unittest.TestCase):
self.mock_crypto_payment.invoice = self.mock_invoice
self.mock_crypto_payment.invoice_id = "test-invoice-123"
self.mock_crypto_payment.status = status
self.mock_crypto_payment.should_keep_invoice.return_value = False
delete_invoice_for_terminal_state(
self.mock_dbsession, self.mock_crypto_payment
@ -164,6 +167,7 @@ class TestInvoiceDeletion(unittest.TestCase):
"""Test that invoice deletion failures are handled gracefully."""
mock_delete_invoice.side_effect = Exception("Database error")
self.mock_crypto_payment.status = CryptoPayment.STATUS_EXPIRED
self.mock_crypto_payment.should_keep_invoice.return_value = False
# Should not raise exception
delete_invoice_for_terminal_state(self.mock_dbsession, self.mock_crypto_payment)
@ -186,6 +190,7 @@ class TestInvoiceDeletion(unittest.TestCase):
"message": "Deletion failed",
}
self.mock_crypto_payment.status = CryptoPayment.STATUS_EXPIRED
self.mock_crypto_payment.should_keep_invoice.return_value = False
delete_invoice_for_terminal_state(self.mock_dbsession, self.mock_crypto_payment)