| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
from odoo.exceptions import ValidationError |
| 4 |
from odoo.tests import tagged |
| 5 |
|
| 6 |
from odoo.addons.payment_mercado_pago.tests.common import MercadoPagoCommon |
| 7 |
|
| 8 |
|
| 9 |
@tagged('post_install', '-at_install') |
| 10 |
class TestPaymentProvider(MercadoPagoCommon): |
| 11 |
|
| 12 |
def test_allow_enabling_if_credentials_are_set(self): |
| 13 |
""" Test that enabling a Mercado Pago provider with credentials succeeds. """ |
| 14 |
self._assert_does_not_raise(ValidationError, self.provider.write({'state': 'enabled'})) |
| 15 |
|
| 16 |
def test_prevent_enabling_if_credentials_are_not_set(self): |
| 17 |
""" Test that enabling a Mercado Pago provider without credentials raises a ValidationError. |
| 18 |
""" |
| 19 |
# Reset the state and credentials together to avoid triggering the constraint outside of the |
| 20 |
# 'assertRaises'. |
| 21 |
self.provider.action_reset_credentials() |
| 22 |
with self.assertRaises(ValidationError): |
| 23 |
self.provider.state = 'enabled' |
| 24 |
|
| 25 |
def test_incompatible_with_unsupported_currencies(self): |
| 26 |
""" Test that Mercado Pago providers are filtered out from compatible providers when the |
| 27 |
currency is not supported. """ |
| 28 |
compatible_providers = self.env['payment.provider']._get_compatible_providers( |
| 29 |
self.company_id, self.partner.id, self.amount, currency_id=self.env.ref('base.AFN').id |
| 30 |
) |
| 31 |
self.assertNotIn(self.provider, compatible_providers) |