test_processing_flows.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. from unittest.mock import patch
  3. from odoo.tests import tagged
  4. from odoo.tools import mute_logger
  5. from odoo.addons.payment.tests.http_common import PaymentHttpCommon
  6. from odoo.addons.payment_mercado_pago.controllers.main import MercadoPagoController
  7. from odoo.addons.payment_mercado_pago.tests.common import MercadoPagoCommon
  8. @tagged('post_install', '-at_install')
  9. class TestProcessingFlows(MercadoPagoCommon, PaymentHttpCommon):
  10. @mute_logger('odoo.addons.payment_mercado_pago.controllers.main')
  11. def test_redirect_notification_triggers_processing(self):
  12. """ Test that receiving a redirect notification triggers the processing of the notification
  13. data. """
  14. self._create_transaction(flow='redirect')
  15. url = self._build_url(MercadoPagoController._return_url)
  16. with patch(
  17. 'odoo.addons.payment.models.payment_transaction.PaymentTransaction'
  18. '._handle_notification_data'
  19. ) as handle_notification_data_mock:
  20. self._make_http_get_request(url, params=self.redirect_notification_data)
  21. self.assertEqual(handle_notification_data_mock.call_count, 1)
  22. @mute_logger('odoo.addons.payment_mercado_pago.controllers.main')
  23. def test_webhook_notification_triggers_processing(self):
  24. """ Test that receiving a valid webhook notification triggers the processing of the
  25. notification data. """
  26. tx = self._create_transaction(flow='redirect')
  27. url = self._build_url(f'{MercadoPagoController._webhook_url}/{tx.reference}')
  28. with patch(
  29. 'odoo.addons.payment.models.payment_transaction.PaymentTransaction'
  30. '._handle_notification_data'
  31. ) as handle_notification_data_mock:
  32. self._make_json_request(url, data=self.webhook_notification_data)
  33. self.assertEqual(handle_notification_data_mock.call_count, 1)