Files
odoo_source/addons/payment_ogone/tests/test_ogone.py
T
Arnaud JosetandAntoine Vandevenne 61a02a7330 [REF] payment_ogone: migrate Ogone to the new payment API
In this commit, we take the opportunity to replace the previous unsecure
API with the new FlexCheckout API that implements payment methods
validation in a hosted page. Payment processing is still done with the
DirectLink API.

This commit also renames the module `payment_ingenico` to
`payment_ogone` as well as the referring strings ("Ogone" instead
of "Ingenico", ...).
A dedicated [MOV] commit is not used because neither the [MOV] commit
nor the adapted [REF] would be valid on its own.

See the merge commit for more details.

task-2333029
task-2313907
task-2334015

Co-authored-by: Antoine Vandevenne <anv@odoo.com>
2021-03-30 09:25:51 +02:00

71 lines
2.9 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from freezegun import freeze_time
from odoo.tests import tagged
from odoo.tools import mute_logger
from odoo.addons.payment import utils as payment_utils
from .common import OgoneCommon
from ..controllers.main import OgoneController
@tagged('post_install', '-at_install')
class OgoneTest(OgoneCommon):
def test_validation_amount(self):
self.assertEqual(self.ogone._get_validation_amount(), 1.0)
# freeze time for consistent singularize_prefix behavior during the test
@freeze_time("2011-11-02 12:00:21")
def test_reference(self):
tx = self.create_transaction(flow="redirect", reference="")
self.assertEqual(tx.reference, "tx-20111102120021",
"Ogone: transaction reference wasn't correctly singularized.")
# Test prefixes of length > 40 chars
reference = self.env['payment.transaction']._compute_reference(
provider=self.ogone.provider,
prefix="This is a reference of more than 40 characters to annoy ogone",
)
self.assertEqual(reference, "This is a reference of mo-20111102120021")
self.assertEqual(len(reference), 40)
# freeze time for consistent singularize_prefix behavior during the test
@freeze_time("2011-11-02 12:00:21")
def test_redirect_form_values(self):
return_url = self._build_url(OgoneController._flexcheckout_return_url)
expected_values = {
'ACCOUNT_PSPID': self.ogone.ogone_pspid,
'ALIAS_ALIASID': payment_utils.singularize_reference_prefix(prefix='ODOO-ALIAS'),
'ALIAS_ORDERID': self.reference,
'ALIAS_STOREPERMANENTLY': 'N', # 'Y' if self.tokenize
'CARD_PAYMENTMETHOD': 'CreditCard',
'LAYOUT_LANGUAGE': self.partner.lang,
'PARAMETERS_ACCEPTURL': return_url,
'PARAMETERS_EXCEPTIONURL': return_url,
}
expected_values['SHASIGNATURE_SHASIGN'] = self.ogone._ogone_generate_signature(
expected_values, incoming=False, format_keys=True
).upper()
tx = self.create_transaction(flow="redirect")
with mute_logger('odoo.addons.payment.models.payment_transaction'):
processing_values = tx._get_processing_values()
form_info = self._extract_values_from_html_form(processing_values['redirect_form_html'])
self.assertEqual(form_info['action'], 'https://ogone.test.v-psp.com/Tokenization/HostedPage')
inputs = form_info['inputs']
self.assertEqual(len(expected_values), len(inputs))
for rendering_key, value in expected_values.items():
form_key = rendering_key.replace('_', '.')
self.assertEqual(
inputs[form_key],
value,
"Ogone: received value %s for input %s (expected %s)" % (
inputs[form_key], form_key, value,
)
)