Debian Codegraph @

addons/payment_mercado_pago/tests/test_processing_flows.py

raw
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from unittest.mock import patch
4
5 from odoo.tests import tagged
6 from odoo.tools import mute_logger
7
8 from odoo.addons.payment.tests.http_common import PaymentHttpCommon
9 from odoo.addons.payment_mercado_pago import const
10 from odoo.addons.payment_mercado_pago.tests.common import MercadoPagoCommon
11
12
13 @tagged('post_install', '-at_install')
14 class TestProcessingFlows(MercadoPagoCommon, PaymentHttpCommon):
15
16 @mute_logger('odoo.addons.payment_mercado_pago.controllers.main')
17 def test_redirect_notification_triggers_processing(self):
18 """ Test that receiving a redirect notification triggers the processing of the notification
19 data. """
20 self._create_transaction(flow='redirect')
21 url = self._build_url(const.PAYMENT_RETURN_ROUTE)
22 with patch(
23 'odoo.addons.payment.models.payment_provider.PaymentProvider._send_api_request',
24 return_value=self.verification_data,
25 ), patch(
26 'odoo.addons.payment.models.payment_transaction.PaymentTransaction._process'
27 ) as process_mock:
28 self._make_http_get_request(url, params=self.redirect_payment_data)
29 self.assertEqual(process_mock.call_count, 1)
30
31 @mute_logger('odoo.addons.payment_mercado_pago.controllers.main')
32 def test_webhook_notification_triggers_processing(self):
33 """ Test that receiving a valid webhook notification triggers the processing of the
34 payment data. """
35 tx = self._create_transaction(flow='redirect')
36 url = self._build_url(f'{const.WEBHOOK_ROUTE}/{tx.reference}')
37 with patch(
38 'odoo.addons.payment.models.payment_provider.PaymentProvider._send_api_request',
39 return_value=self.verification_data,
40 ), patch(
41 'odoo.addons.payment.models.payment_transaction.PaymentTransaction._process'
42 ) as process_mock:
43 self._make_json_request(url, data=self.webhook_payment_data)
44 self.assertEqual(process_mock.call_count, 1)