test_payumoney.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. from werkzeug.exceptions import Forbidden
  3. from odoo.tests import tagged
  4. from odoo.tools import mute_logger
  5. from odoo.addons.payment import utils as payment_utils
  6. from odoo.addons.payment.tests.http_common import PaymentHttpCommon
  7. from odoo.addons.payment_payumoney.controllers.main import PayUMoneyController
  8. from odoo.addons.payment_payumoney.tests.common import PayumoneyCommon
  9. @tagged('post_install', '-at_install')
  10. class PayUMoneyTest(PayumoneyCommon, PaymentHttpCommon):
  11. def test_compatible_providers(self):
  12. providers = self.env['payment.provider']._get_compatible_providers(
  13. self.company.id, self.partner.id, self.amount, currency_id=self.currency.id
  14. )
  15. self.assertIn(self.payumoney, providers)
  16. providers = self.env['payment.provider']._get_compatible_providers(
  17. self.company.id, self.partner.id, self.amount, currency_id=self.currency_euro.id
  18. )
  19. self.assertNotIn(self.payumoney, providers)
  20. def test_redirect_form_values(self):
  21. tx = self._create_transaction(flow='redirect')
  22. with mute_logger('odoo.addons.payment.models.payment_transaction'):
  23. processing_values = tx._get_processing_values()
  24. form_info = self._extract_values_from_html_form(processing_values['redirect_form_html'])
  25. first_name, last_name = payment_utils.split_partner_name(self.partner.name)
  26. return_url = self._build_url(PayUMoneyController._return_url)
  27. expected_values = {
  28. 'key': self.payumoney.payumoney_merchant_key,
  29. 'txnid': self.reference,
  30. 'amount': str(self.amount),
  31. 'productinfo': self.reference,
  32. 'firstname': first_name,
  33. 'lastname': last_name,
  34. 'email': self.partner.email,
  35. 'phone': self.partner.phone,
  36. 'surl': return_url,
  37. 'furl': return_url,
  38. 'service_provider': 'payu_paisa',
  39. }
  40. expected_values['hash'] = self.payumoney._payumoney_generate_sign(
  41. expected_values, incoming=False,
  42. )
  43. self.assertEqual(form_info['action'],
  44. 'https://sandboxsecure.payu.in/_payment')
  45. self.assertDictEqual(form_info['inputs'], expected_values,
  46. "PayUMoney: invalid inputs specified in the redirect form.")
  47. def test_accept_notification_with_valid_signature(self):
  48. """ Test the verification of a notification with a valid signature. """
  49. tx = self._create_transaction('redirect')
  50. self._assert_does_not_raise(
  51. Forbidden,
  52. PayUMoneyController._verify_notification_signature,
  53. self.notification_data,
  54. tx,
  55. )
  56. @mute_logger('odoo.addons.payment_payumoney.controllers.main')
  57. def test_reject_notification_with_missing_signature(self):
  58. """ Test the verification of a notification with a missing signature. """
  59. tx = self._create_transaction('redirect')
  60. payload = dict(self.notification_data, hash=None)
  61. self.assertRaises(
  62. Forbidden, PayUMoneyController._verify_notification_signature, payload, tx
  63. )
  64. @mute_logger('odoo.addons.payment_payumoney.controllers.main')
  65. def test_reject_notification_with_invalid_signature(self):
  66. """ Test the verification of a notification with an invalid signature. """
  67. tx = self._create_transaction('redirect')
  68. payload = dict(self.notification_data, hash='dummy')
  69. self.assertRaises(
  70. Forbidden, PayUMoneyController._verify_notification_signature, payload, tx
  71. )