Permalink
Browse files

[FIX] payment_*: tests

PAYPAL
------

The paypal tests are not working working for two reasons:
- we check that there is no date in pending state on payment
transaction, but since the refactoring in this commit: 0121634
the date is always set before the validation of transaction.
- Since the changes on dates, the datetime field doesn't return a string
anymore and the comparison fails. So we convert the datetime to string
for the comparison.

BUCKAROO
--------

The buckaroo tests were not working for multiple reasons.

STRIPE
------

The payment stripe tests were not working because:
- The reference set in transactions were not the same as the ones givent
to the payment provider.
- we were checking for a script tag in form that has been removed in
commit 7c639be

AUTHORIZE
---------

This test cannot be tested on runbot due to its server to server way of
working

closes #30105
  • Loading branch information...
pimodoo committed Jan 10, 2019
1 parent 5f72489 commit 132717c7b17f0e018b5e565646fa842e6227a079
@@ -188,7 +188,7 @@ def test_20_authorize_form_management(self):
self.assertEqual(tx.state, 'cancel', 'Authorize: erroneous validation did not put tx into error state')


@odoo.tests.tagged('post_install', '-at_install', '-standard', 'external')
@odoo.tests.tagged('post_install', '-at_install', '-standard')
class AuthorizeForm(AuthorizeCommon):
def test_30_authorize_s2s(self):
# be sure not to do stupid thing
@@ -32,12 +32,12 @@ def test_10_Buckaroo_form_render(self):
# ----------------------------------------

form_values = {
'add_returndata': None,
'add_returndata': '',
'Brq_websitekey': self.buckaroo.brq_websitekey,
'Brq_amount': '2240.0',
'Brq_currency': 'EUR',
'Brq_invoicenumber': 'SO004',
'Brq_signature': '1b8c10074c622d965272a91a9e88b5b3777d2474', # update me
'Brq_signature': 'aa6fe072afdd9d1b463d55f43e6df4b272d3529a', # update me
'brq_test': 'True',
'Brq_return': urls.url_join(base_url, BuckarooController._return_url),
'Brq_returncancel': urls.url_join(base_url, BuckarooController._cancel_url),
@@ -50,13 +50,14 @@ def test_10_Buckaroo_form_render(self):
res = self.buckaroo.render(
'SO004', 2240.0, self.currency_euro.id,
partner_id=None,
partner_values=self.buyer_values)

values=self.buyer_values)
# check form result
tree = objectify.fromstring(res)
self.assertEqual(tree.get('action'), 'https://testcheckout.buckaroo.nl/html/', 'Buckaroo: wrong form POST url')
data_set = tree.xpath("//input[@name='data_set']")
self.assertEqual(len(data_set), 1, 'paypal: Found %d "data_set" input instead of 1' % len(data_set))
self.assertEqual(data_set[0].get('data-action-url'), 'https://testcheckout.buckaroo.nl/html/', 'Buckaroo: wrong form POST url')
for form_input in tree.input:
if form_input.get('name') in ['submit']:
if form_input.get('name') in ['submit', 'data_set']:
continue
self.assertEqual(
form_input.get('value'),
@@ -78,17 +79,18 @@ def test_10_Buckaroo_form_render(self):
})

# render the button
res = self.buckaroo_id.render(
res = self.buckaroo.render(
'should_be_erased', 2240.0, self.currency_euro,
tx_id=tx.id,
partner_id=None,
partner_values=self.buyer_values)
values=self.buyer_values)

# check form result
tree = objectify.fromstring(res)
self.assertEqual(tree.get('action'), 'https://testcheckout.buckaroo.nl/html/', 'Buckaroo: wrong form POST url')
data_set = tree.xpath("//input[@name='data_set']")
self.assertEqual(len(data_set), 1, 'paypal: Found %d "data_set" input instead of 1' % len(data_set))
self.assertEqual(data_set[0].get('data-action-url'), 'https://testcheckout.buckaroo.nl/html/', 'Buckaroo: wrong form POST url')
for form_input in tree.input:
if form_input.get('name') in ['submit']:
if form_input.get('name') in ['submit', 'data_set']:
continue
self.assertEqual(
form_input.get('value'),
@@ -116,7 +118,7 @@ def test_20_buckaroo_form_management(self):
'BRQ_SERVICE_PAYPAL_PAYERLASTNAME': u'Tester',
'BRQ_SERVICE_PAYPAL_PAYERMIDDLENAME': u'de',
'BRQ_SERVICE_PAYPAL_PAYERSTATUS': u'verified',
'Brq_signature': u'175d82dd53a02bad393fee32cb1eafa3b6fbbd91',
'Brq_signature': u'9e75e51cbcb6fbc798b40d1787cc5b7c36557d56',
'BRQ_STATUSCODE': u'190',
'BRQ_STATUSCODE_DETAIL': u'S001',
'BRQ_STATUSMESSAGE': u'Transaction successfully processed',
@@ -134,7 +136,7 @@ def test_20_buckaroo_form_management(self):
'amount': 2240.0,
'acquirer_id': self.buckaroo.id,
'currency_id': self.currency_euro.id,
'reference': 'SO004-1',
'reference': 'SO004',
'partner_name': 'Norbert Buyer',
'partner_country_id': self.country_france.id})

@@ -153,14 +155,14 @@ def test_20_buckaroo_form_management(self):
'partner_name': 'Norbert Buyer',
'partner_country_id': self.country_france.id})

buckaroo_post_data['BRQ_INVOICENUMBER'] = 'SO004-2'
# now buckaroo post is ok: try to modify the SHASIGN
buckaroo_post_data['BRQ_SIGNATURE'] = '54d928810e343acf5fb0c3ee75fd747ff159ef7a'
buckaroo_post_data['Brq_signature'] = '54d928810e343acf5fb0c3ee75fd747ff159ef7a'
with self.assertRaises(ValidationError):
tx.form_feedback(buckaroo_post_data, 'buckaroo')

# simulate an error
buckaroo_post_data['BRQ_STATUSCODE'] = 2
buckaroo_post_data['BRQ_SIGNATURE'] = '4164b52adb1e6a2221d3d8a39d8c3e18a9ecb90b'
buckaroo_post_data['BRQ_STATUSCODE'] = '2'
buckaroo_post_data['Brq_signature'] = '9138e2bf09a708a4eb485ce7777e5406898b689d'
tx.form_feedback(buckaroo_post_data, 'buckaroo')

# check state
@@ -2,24 +2,26 @@
<odoo>
<data noupdate="1">
<template id="buckaroo_form">
<input type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
<input type="hidden" name="Brq_websitekey" t-att-value="Brq_websitekey"/>
<input type="hidden" name="Brq_amount" t-att-value="Brq_amount"/>
<input type="hidden" name="Brq_currency" t-att-value="Brq_currency"/>
<input type="hidden" name="Brq_invoicenumber" t-att-value="Brq_invoicenumber"/>
<input type="hidden" name="Brq_signature" t-att-value="Brq_signature"/>
<input type="hidden" name="brq_test" t-att-value="brq_test"/>
<input type="hidden" name="Brq_culture" t-att-value="Brq_culture"/>
<!-- URLs -->
<input t-if="Brq_return" type="hidden" name='Brq_return'
t-att-value="Brq_return"/>
<input t-if="Brq_returncancel" type="hidden" name='Brq_returncancel'
t-att-value="Brq_returncancel"/>
<input t-if="Brq_returnerror" type="hidden" name='Brq_returnerror'
t-att-value="Brq_returnerror"/>
<input t-if="Brq_returnreject" type="hidden" name='Brq_returnreject'
t-att-value="Brq_returnreject"/>
<input type="hidden" name='add_returndata' t-att-value="add_returndata"/>
<div>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
<input type="hidden" name="Brq_websitekey" t-att-value="Brq_websitekey"/>
<input type="hidden" name="Brq_amount" t-att-value="Brq_amount"/>
<input type="hidden" name="Brq_currency" t-att-value="Brq_currency"/>
<input type="hidden" name="Brq_invoicenumber" t-att-value="Brq_invoicenumber"/>
<input type="hidden" name="Brq_signature" t-att-value="Brq_signature"/>
<input type="hidden" name="brq_test" t-att-value="brq_test"/>
<input type="hidden" name="Brq_culture" t-att-value="Brq_culture"/>
<!-- URLs -->
<input t-if="Brq_return" type="hidden" name='Brq_return'
t-att-value="Brq_return"/>
<input t-if="Brq_returncancel" type="hidden" name='Brq_returncancel'
t-att-value="Brq_returncancel"/>
<input t-if="Brq_returnerror" type="hidden" name='Brq_returnerror'
t-att-value="Brq_returnerror"/>
<input t-if="Brq_returnreject" type="hidden" name='Brq_returnreject'
t-att-value="Brq_returnreject"/>
<input type="hidden" name='add_returndata' t-att-value="add_returndata"/>
</div>
</template>
</data>
</odoo>
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from odoo import fields
from odoo.addons.payment.models.payment_acquirer import ValidationError
from odoo.addons.payment.tests.common import PaymentAcquirerCommon
from odoo.addons.payment_paypal.controllers.main import PaypalController
@@ -182,7 +183,6 @@ def test_20_paypal_form_management(self):
self.assertEqual(tx.state, 'pending', 'paypal: wrong state after receiving a valid pending notification')
self.assertEqual(tx.state_message, 'multi_currency', 'paypal: wrong state message after receiving a valid pending notification')
self.assertEqual(tx.acquirer_reference, '08D73520KX778924N', 'paypal: wrong txn_id after receiving a valid pending notification')
self.assertFalse(tx.date, 'paypal: validation date should not be updated whenr receiving pending notification')

# update tx
tx.write({
@@ -196,4 +196,4 @@ def test_20_paypal_form_management(self):
# check
self.assertEqual(tx.state, 'done', 'paypal: wrong state after receiving a valid pending notification')
self.assertEqual(tx.acquirer_reference, '08D73520KX778924N', 'paypal: wrong txn_id after receiving a valid pending notification')
self.assertEqual(tx.date, '2013-11-18 11:21:19', 'paypal: wrong validation date')
self.assertEqual(fields.Datetime.to_string(tx.date), '2013-11-18 11:21:19', 'paypal: wrong validation date')
@@ -59,9 +59,6 @@ def test_20_stripe_form_render(self):

# render the button
res = self.stripe.render('SO404', 320.0, self.currency_euro.id, values=self.buyer_values).decode('utf-8')
popup_script_src = 'script src="https://checkout.stripe.com/checkout.js"'
# check form result
self.assertIn(popup_script_src, res, "Stripe: popup script not found in template render")
# Generated and received
self.assertIn(self.buyer_values.get('partner_email'), res, 'Stripe: email input not found in rendered template')

@@ -87,7 +84,7 @@ def test_30_stripe_form_management(self):
u'id': u'ch_172xfnGMfVJxozLwEjSfpfxD',
u'invoice': None,
u'livemode': False,
u'metadata': {u'reference': u'SO100'},
u'metadata': {u'reference': u'SO100-1'},
u'object': u'charge',
u'paid': True,
u'receipt_email': None,
@@ -137,6 +134,7 @@ def test_30_stripe_form_management(self):
tx.form_feedback(stripe_post_data, 'stripe')
self.assertEqual(tx.state, 'done', 'Stripe: validation did not put tx into done state')
self.assertEqual(tx.acquirer_reference, stripe_post_data.get('id'), 'Stripe: validation did not update tx id')
stripe_post_data['metadata']['reference'] = u'SO100-2'
# reset tx
tx = self.env['payment.transaction'].create({
'amount': 4700,

0 comments on commit 132717c

Please sign in to comment.