test_payment_transaction.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.tests.common import MercadoPagoCommon
  7. @tagged('post_install', '-at_install')
  8. class TestPaymentTransaction(MercadoPagoCommon, PaymentHttpCommon):
  9. def test_no_item_missing_from_preference_request_payload(self):
  10. """ Test that the request values are conform to the transaction fields. """
  11. tx = self._create_transaction(flow='redirect')
  12. request_payload = tx._mercado_pago_prepare_preference_request_payload()
  13. self.maxDiff = 10000 # Allow comparing large dicts.
  14. return_url = self._build_url('/payment/mercado_pago/return')
  15. webhook_url = self._build_url('/payment/mercado_pago/webhook')
  16. self.assertDictEqual(request_payload, {
  17. 'auto_return': 'all',
  18. 'back_urls': {
  19. 'failure': return_url,
  20. 'pending': return_url,
  21. 'success': return_url,
  22. },
  23. 'external_reference': tx.reference,
  24. 'items': [{
  25. 'currency_id': tx.currency_id.name,
  26. 'quantity': 1,
  27. 'title': tx.reference,
  28. 'unit_price': tx.amount,
  29. }],
  30. 'notification_url': f'{webhook_url}/{tx.reference}',
  31. 'payer': {
  32. 'address': {'street_name': tx.partner_address, 'zip_code': tx.partner_zip},
  33. 'email': tx.partner_email,
  34. 'name': tx.partner_name,
  35. 'phone': {'number': tx.partner_phone},
  36. },
  37. 'payment_methods': {'installments': 1},
  38. })
  39. @mute_logger('odoo.addons.payment.models.payment_transaction')
  40. def test_no_input_missing_from_redirect_form(self):
  41. """ Test that the `api_url` key is not omitted from the rendering values. """
  42. tx = self._create_transaction(flow='redirect')
  43. with patch(
  44. 'odoo.addons.payment_mercado_pago.models.payment_transaction.PaymentTransaction'
  45. '._get_specific_rendering_values', return_value={'api_url': 'https://dummy.com'}
  46. ):
  47. processing_values = tx._get_processing_values()
  48. form_info = self._extract_values_from_html_form(processing_values['redirect_form_html'])
  49. self.assertEqual(form_info['action'], 'https://dummy.com')
  50. self.assertEqual(form_info['method'], 'post')
  51. self.assertDictEqual(form_info['inputs'], {})
  52. def test_processing_notification_data_confirms_transaction(self):
  53. """ Test that the transaction state is set to 'done' when the notification data indicate a
  54. successful payment. """
  55. tx = self._create_transaction(flow='redirect')
  56. with patch(
  57. 'odoo.addons.payment_mercado_pago.models.payment_provider.Paymentprovider'
  58. '._mercado_pago_make_request', return_value=self.verification_data
  59. ):
  60. tx._process_notification_data(self.redirect_notification_data)
  61. self.assertEqual(tx.state, 'done')