mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-21 04:32:07 +02:00
19.0 vanilla
This commit is contained in:
parent
d1963a3c3a
commit
2d3ee4855a
7430 changed files with 2687981 additions and 2965473 deletions
|
|
@ -1,11 +1,11 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
from unittest.mock import patch
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
|
||||
from freezegun import freeze_time
|
||||
|
||||
from odoo.tests import tagged
|
||||
from odoo.tests import JsonRpcException, tagged
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
from odoo.addons.payment.controllers.portal import PaymentPortal
|
||||
|
|
@ -26,34 +26,31 @@ class TestFlows(PaymentHttpCommon):
|
|||
route_values = self._prepare_pay_values()
|
||||
|
||||
# /payment/pay
|
||||
tx_context = self._get_tx_checkout_context(**route_values)
|
||||
for key, val in tx_context.items():
|
||||
payment_context = self._get_portal_pay_context(**route_values)
|
||||
for key, val in payment_context.items():
|
||||
if key in route_values:
|
||||
self.assertEqual(val, route_values[key])
|
||||
|
||||
self.assertIn(self.provider.id, tx_context['provider_ids'])
|
||||
|
||||
# Route values are taken from tx_context result of /pay route to correctly simulate the flow
|
||||
# Route values are taken from payment_context result of /pay route to correctly simulate the flow
|
||||
route_values = {
|
||||
k: tx_context[k]
|
||||
k: payment_context[k]
|
||||
for k in [
|
||||
'amount',
|
||||
'currency_id',
|
||||
'reference_prefix',
|
||||
'partner_id',
|
||||
'access_token',
|
||||
'landing_route',
|
||||
'reference_prefix',
|
||||
'access_token',
|
||||
]
|
||||
}
|
||||
route_values.update({
|
||||
'provider_id': self.provider.id,
|
||||
'payment_method_id': self.payment_method_id if flow != 'token' else None,
|
||||
'token_id': self._create_token().id if flow == 'token' else None,
|
||||
'flow': flow,
|
||||
'payment_option_id': self.provider.id,
|
||||
'tokenization_requested': False,
|
||||
})
|
||||
|
||||
if flow == 'token':
|
||||
route_values['payment_option_id'] = self._create_token().id
|
||||
|
||||
with mute_logger('odoo.addons.payment.models.payment_transaction'):
|
||||
processing_values = self._get_processing_values(**route_values)
|
||||
tx_sudo = self._get_tx(processing_values['reference'])
|
||||
|
|
@ -71,6 +68,7 @@ class TestFlows(PaymentHttpCommon):
|
|||
self.assertEqual(processing_values['currency_id'], self.currency.id)
|
||||
self.assertEqual(processing_values['partner_id'], self.partner.id)
|
||||
self.assertEqual(processing_values['reference'], self.reference)
|
||||
self.assertFalse(processing_values['should_tokenize'])
|
||||
|
||||
# Verify computed values not provided, but added during the flow
|
||||
self.assertIn("tx_id=", tx_sudo.landing_route)
|
||||
|
|
@ -163,26 +161,28 @@ class TestFlows(PaymentHttpCommon):
|
|||
validation_amount = self.provider._get_validation_amount()
|
||||
validation_currency = self.provider._get_validation_currency()
|
||||
|
||||
tx_context = self._get_tx_manage_context()
|
||||
payment_context = self._get_portal_payment_method_context()
|
||||
expected_values = {
|
||||
'partner_id': self.partner.id,
|
||||
'access_token': self._generate_test_access_token(self.partner.id, None, None),
|
||||
'reference_prefix': expected_reference
|
||||
}
|
||||
for key, val in tx_context.items():
|
||||
for key, val in payment_context.items():
|
||||
if key in expected_values:
|
||||
self.assertEqual(val, expected_values[key])
|
||||
|
||||
transaction_values = {
|
||||
'provider_id': self.provider.id,
|
||||
'payment_method_id': self.payment_method_id,
|
||||
'token_id': None,
|
||||
'amount': None,
|
||||
'currency_id': None,
|
||||
'partner_id': tx_context['partner_id'],
|
||||
'access_token': tx_context['access_token'],
|
||||
'partner_id': payment_context['partner_id'],
|
||||
'access_token': payment_context['access_token'],
|
||||
'flow': flow,
|
||||
'payment_option_id': self.provider.id,
|
||||
'tokenization_requested': True,
|
||||
'reference_prefix': tx_context['reference_prefix'],
|
||||
'landing_route': tx_context['landing_route'],
|
||||
'landing_route': payment_context['landing_route'],
|
||||
'reference_prefix': payment_context['reference_prefix'],
|
||||
'is_validation': True,
|
||||
}
|
||||
with mute_logger('odoo.addons.payment.models.payment_transaction'):
|
||||
|
|
@ -196,7 +196,6 @@ class TestFlows(PaymentHttpCommon):
|
|||
self.assertEqual(tx_sudo.partner_id.id, self.partner.id)
|
||||
self.assertEqual(tx_sudo.reference, expected_reference)
|
||||
# processing_values == given values
|
||||
self.assertEqual(processing_values['provider_id'], self.provider.id)
|
||||
self.assertEqual(processing_values['amount'], validation_amount)
|
||||
self.assertEqual(processing_values['currency_id'], validation_currency.id)
|
||||
self.assertEqual(processing_values['partner_id'], self.partner.id)
|
||||
|
|
@ -237,7 +236,7 @@ class TestFlows(PaymentHttpCommon):
|
|||
|
||||
# Pay without a partner specified (but logged) --> pay with the partner of current user.
|
||||
self.authenticate(self.portal_user.login, self.portal_user.login)
|
||||
tx_context = self._get_tx_checkout_context(**route_values)
|
||||
tx_context = self._get_portal_pay_context(**route_values)
|
||||
self.assertEqual(tx_context['partner_id'], self.portal_partner.id)
|
||||
|
||||
def test_pay_no_token(self):
|
||||
|
|
@ -253,7 +252,7 @@ class TestFlows(PaymentHttpCommon):
|
|||
|
||||
# Pay without a partner specified (but logged) --> pay with the partner of current user.
|
||||
self.authenticate(self.portal_user.login, self.portal_user.login)
|
||||
tx_context = self._get_tx_checkout_context(**route_values)
|
||||
tx_context = self._get_portal_pay_context(**route_values)
|
||||
self.assertEqual(tx_context['partner_id'], self.portal_partner.id)
|
||||
|
||||
def test_pay_wrong_token(self):
|
||||
|
|
@ -279,30 +278,37 @@ class TestFlows(PaymentHttpCommon):
|
|||
|
||||
def test_transaction_wrong_flow(self):
|
||||
transaction_values = self._prepare_pay_values()
|
||||
transaction_values.pop('reference')
|
||||
transaction_values.update({
|
||||
'flow': 'this flow does not exist',
|
||||
'payment_option_id': self.provider.id,
|
||||
'tokenization_requested': False,
|
||||
'reference_prefix': 'whatever',
|
||||
'landing_route': 'whatever',
|
||||
'reference_prefix': 'whatever',
|
||||
})
|
||||
# Transaction step with a wrong flow --> UserError
|
||||
with mute_logger('odoo.http'):
|
||||
response = self._portal_transaction(**transaction_values)
|
||||
self.assertIn(
|
||||
"odoo.exceptions.UserError: The payment should either be direct, with redirection, or made by a token.",
|
||||
response.text)
|
||||
with mute_logger("odoo.http"), self.assertRaises(
|
||||
JsonRpcException,
|
||||
msg='odoo.exceptions.UserError: The payment should either be direct, with redirection, or made by a token.',
|
||||
):
|
||||
self._portal_transaction(**transaction_values)
|
||||
|
||||
@mute_logger('odoo.http')
|
||||
def test_transaction_route_rejects_unexpected_kwarg(self):
|
||||
route_kwargs = {
|
||||
**self._prepare_pay_values(),
|
||||
'custom_create_values': 'whatever', # This should be rejected.
|
||||
}
|
||||
with self.assertRaises(JsonRpcException, msg='odoo.exceptions.ValidationError'):
|
||||
self._portal_transaction(**route_kwargs)
|
||||
|
||||
def test_transaction_wrong_token(self):
|
||||
route_values = self._prepare_pay_values()
|
||||
route_values['access_token'] = "abcde"
|
||||
|
||||
# Transaction step with a wrong access token --> ValidationError
|
||||
with mute_logger('odoo.http'):
|
||||
response = self._portal_transaction(**route_values)
|
||||
self.assertIn(
|
||||
"odoo.exceptions.ValidationError: The access token is invalid.",
|
||||
response.text)
|
||||
with mute_logger('odoo.http'), self.assertRaises(JsonRpcException, msg='odoo.exceptions.ValidationError: The access token is invalid.'):
|
||||
self._portal_transaction(**route_values)
|
||||
|
||||
def test_access_disabled_providers_tokens(self):
|
||||
self.partner = self.portal_partner
|
||||
|
|
@ -311,31 +317,27 @@ class TestFlows(PaymentHttpCommon):
|
|||
self.authenticate(self.portal_user.login, self.portal_user.login)
|
||||
|
||||
token = self._create_token()
|
||||
provider_b = self.provider.copy()
|
||||
provider_b.state = 'test'
|
||||
provider_b = self.provider.copy({'is_published': True, 'state': 'test'})
|
||||
token_b = self._create_token(provider_id=provider_b.id)
|
||||
|
||||
# User must see both enabled providers and tokens
|
||||
manage_context = self._get_tx_manage_context()
|
||||
self.assertEqual(manage_context['partner_id'], self.partner.id)
|
||||
self.assertIn(self.provider.id, manage_context['provider_ids'])
|
||||
self.assertIn(provider_b.id, manage_context['provider_ids'])
|
||||
self.assertIn(token.id, manage_context['token_ids'])
|
||||
self.assertIn(token_b.id, manage_context['token_ids'])
|
||||
# User must see both tokens and compatible payment methods.
|
||||
payment_context = self._get_portal_payment_method_context()
|
||||
self.assertEqual(payment_context['partner_id'], self.partner.id)
|
||||
self.assertIn(token.id, payment_context['token_ids'])
|
||||
self.assertIn(token_b.id, payment_context['token_ids'])
|
||||
self.assertIn(self.payment_method_id, payment_context['payment_method_ids'])
|
||||
|
||||
# Token of disabled provider(s) & disabled providers should not be shown
|
||||
# Token of disabled provider(s) should not be shown.
|
||||
self.provider.state = 'disabled'
|
||||
manage_context = self._get_tx_manage_context()
|
||||
self.assertEqual(manage_context['partner_id'], self.partner.id)
|
||||
self.assertEqual(manage_context['provider_ids'], [provider_b.id])
|
||||
self.assertEqual(manage_context['token_ids'], [token_b.id])
|
||||
payment_context = self._get_portal_payment_method_context()
|
||||
self.assertEqual(payment_context['partner_id'], self.partner.id)
|
||||
self.assertEqual(payment_context['token_ids'], [token_b.id])
|
||||
|
||||
# Archived tokens must be hidden from the user
|
||||
token_b.active = False
|
||||
manage_context = self._get_tx_manage_context()
|
||||
self.assertEqual(manage_context['partner_id'], self.partner.id)
|
||||
self.assertEqual(manage_context['provider_ids'], [provider_b.id])
|
||||
self.assertEqual(manage_context['token_ids'], [])
|
||||
payment_context = self._get_portal_payment_method_context()
|
||||
self.assertEqual(payment_context['partner_id'], self.partner.id)
|
||||
self.assertEqual(payment_context['token_ids'], [])
|
||||
|
||||
@mute_logger('odoo.addons.payment.models.payment_transaction')
|
||||
def test_direct_payment_triggers_no_payment_request(self):
|
||||
|
|
@ -344,10 +346,10 @@ class TestFlows(PaymentHttpCommon):
|
|||
self.user = self.portal_user
|
||||
with patch(
|
||||
'odoo.addons.payment.models.payment_transaction.PaymentTransaction'
|
||||
'._send_payment_request'
|
||||
'._charge_with_token'
|
||||
) as patched:
|
||||
self._portal_transaction(
|
||||
**self._prepare_transaction_values(self.provider.id, 'direct')
|
||||
**self._prepare_transaction_values(self.payment_method_id, None, 'direct')
|
||||
)
|
||||
self.assertEqual(patched.call_count, 0)
|
||||
|
||||
|
|
@ -358,10 +360,10 @@ class TestFlows(PaymentHttpCommon):
|
|||
self.user = self.portal_user
|
||||
with patch(
|
||||
'odoo.addons.payment.models.payment_transaction.PaymentTransaction'
|
||||
'._send_payment_request'
|
||||
'._charge_with_token'
|
||||
) as patched:
|
||||
self._portal_transaction(
|
||||
**self._prepare_transaction_values(self.provider.id, 'redirect')
|
||||
**self._prepare_transaction_values(self.payment_method_id, None, 'redirect')
|
||||
)
|
||||
self.assertEqual(patched.call_count, 0)
|
||||
|
||||
|
|
@ -372,23 +374,30 @@ class TestFlows(PaymentHttpCommon):
|
|||
self.user = self.portal_user
|
||||
with patch(
|
||||
'odoo.addons.payment.models.payment_transaction.PaymentTransaction'
|
||||
'._send_payment_request'
|
||||
'._charge_with_token'
|
||||
) as patched:
|
||||
self._portal_transaction(
|
||||
**self._prepare_transaction_values(self._create_token().id, 'token')
|
||||
**self._prepare_transaction_values(None, self._create_token().id, 'token')
|
||||
)
|
||||
self.assertEqual(patched.call_count, 1)
|
||||
|
||||
def test_tokenization_input_is_show_to_logged_in_users(self):
|
||||
def test_tokenization_input_is_shown_to_logged_in_users(self):
|
||||
# Test both for portal and internal users
|
||||
self.user = self.portal_user
|
||||
self.provider.allow_tokenization = True
|
||||
show_tokenize_input = PaymentPortal._compute_show_tokenize_input_mapping(
|
||||
self.provider, logged_in=True
|
||||
)
|
||||
|
||||
show_tokenize_input = PaymentPortal._compute_show_tokenize_input_mapping(self.provider)
|
||||
self.assertDictEqual(show_tokenize_input, {self.provider.id: True})
|
||||
|
||||
def test_tokenization_input_is_hidden_for_logged_out_users(self):
|
||||
self.provider.allow_tokenization = False
|
||||
show_tokenize_input = PaymentPortal._compute_show_tokenize_input_mapping(
|
||||
self.provider, logged_in=True
|
||||
)
|
||||
self.assertDictEqual(show_tokenize_input, {self.provider.id: False})
|
||||
self.user = self.internal_user
|
||||
self.provider.allow_tokenization = True
|
||||
|
||||
show_tokenize_input = PaymentPortal._compute_show_tokenize_input_mapping(self.provider)
|
||||
self.assertDictEqual(show_tokenize_input, {self.provider.id: True})
|
||||
|
||||
def test_tokenization_input_is_shown_to_logged_out_users(self):
|
||||
self.user = self.public_user
|
||||
self.provider.allow_tokenization = True
|
||||
|
||||
show_tokenize_input = PaymentPortal._compute_show_tokenize_input_mapping(self.provider)
|
||||
self.assertDictEqual(show_tokenize_input, {self.provider.id: True})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue