From 7625563f6a8bc8dbbca0d320ce81048e387b344f Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Tue, 30 Sep 2025 14:13:35 -0400 Subject: [PATCH] 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. --- make_post_sell/tests/test_invoice_deletion.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/make_post_sell/tests/test_invoice_deletion.py b/make_post_sell/tests/test_invoice_deletion.py index d18ef11..6d90f84 100644 --- a/make_post_sell/tests/test_invoice_deletion.py +++ b/make_post_sell/tests/test_invoice_deletion.py @@ -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)