From b33480a431a3708681478b7b556e97b351c0e3b2 Mon Sep 17 00:00:00 2001 From: alsh-odoo Date: Wed, 27 Mar 2024 15:22:12 +0530 Subject: [PATCH] [FIX] payment_mercado_pago: fix traceback when the payment status is 404 This traceback arises when the payment status is 404 A comma at the end is forgotten while creating a tuple with single record, which leads to a typeerror traceback. Error:- "TypeError: 'in ' requires string as left operand, not int" https://github.com/odoo/odoo/blob/7e3267fc69324a3c98d36983705a50420b5143f9/addons/payment_mercado_pago/const.py#L35-L39 sentry-5103720097 closes odoo/odoo#159609 X-original-commit: 9094afe724a7ee9771ae8c035fe3829b1c556c59 Signed-off-by: Altaf Shaik (alsh) --- addons/payment_mercado_pago/const.py | 2 +- addons/payment_mercado_pago/tests/common.py | 3 +++ .../tests/test_payment_transaction.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/addons/payment_mercado_pago/const.py b/addons/payment_mercado_pago/const.py index 427c64c82196a..5340bff238447 100644 --- a/addons/payment_mercado_pago/const.py +++ b/addons/payment_mercado_pago/const.py @@ -36,7 +36,7 @@ 'pending': ('pending', 'in_process', 'in_mediation', 'authorized'), 'done': ('approved', 'refunded'), 'canceled': ('cancelled', 'null'), - 'error': ('rejected'), + 'error': ('rejected',), } # Mapping of error states to Mercado Pago error messages. diff --git a/addons/payment_mercado_pago/tests/common.py b/addons/payment_mercado_pago/tests/common.py index f9e675aa29ee1..323db231810d4 100644 --- a/addons/payment_mercado_pago/tests/common.py +++ b/addons/payment_mercado_pago/tests/common.py @@ -26,3 +26,6 @@ def setUpClass(cls): cls.verification_data = { 'status': 'approved', } + cls.verification_data_for_error_state = { + 'status': 404, + } diff --git a/addons/payment_mercado_pago/tests/test_payment_transaction.py b/addons/payment_mercado_pago/tests/test_payment_transaction.py index 5863ec73d5768..3df97a5b610c4 100644 --- a/addons/payment_mercado_pago/tests/test_payment_transaction.py +++ b/addons/payment_mercado_pago/tests/test_payment_transaction.py @@ -69,3 +69,15 @@ def test_processing_notification_data_confirms_transaction(self): ): tx._process_notification_data(self.redirect_notification_data) self.assertEqual(tx.state, 'done') + + @mute_logger('odoo.addons.payment_mercado_pago.models.payment_transaction') + def test_processing_notification_data_rejects_transaction(self): + """ Test that the transaction state is set to 'error' when the notification data indicate a status of + 404 error payment. """ + tx = self._create_transaction(flow='redirect') + with patch( + 'odoo.addons.payment_mercado_pago.models.payment_provider.PaymentProvider' + '._mercado_pago_make_request', return_value=self.verification_data_for_error_state + ): + tx._process_notification_data(self.redirect_notification_data) + self.assertEqual(tx.state, 'error')