diff options
| author | Thibault Delavallée <tde@openerp.com> | 2016-07-05 13:13:42 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2016-07-06 15:10:46 +0200 |
| commit | 76d124299b99dd2bfe0594b3ce9600bda7a56689 (patch) | |
| tree | dd2d34c4ce4abbab94800ec09045fe9aa483c69b /addons/payment_authorize | |
| parent | ad93be5df913668e46c5567b7e5d80670e09470d (diff) | |
[CLN] payment_authorize: cleaning and guidelines
As this module is already in new API only small linting is performed.
Diffstat (limited to 'addons/payment_authorize')
| -rw-r--r-- | addons/payment_authorize/controllers/main.py | 4 | ||||
| -rw-r--r-- | addons/payment_authorize/models/payment.py | 21 | ||||
| -rw-r--r-- | addons/payment_authorize/tests/__init__.py | 3 | ||||
| -rw-r--r-- | addons/payment_authorize/tests/test_authorize.py | 56 |
4 files changed, 36 insertions, 48 deletions
diff --git a/addons/payment_authorize/controllers/main.py b/addons/payment_authorize/controllers/main.py index 93b3d105f9a..aec2aa1f777 100644 --- a/addons/payment_authorize/controllers/main.py +++ b/addons/payment_authorize/controllers/main.py @@ -3,8 +3,8 @@ import pprint import logging import urlparse -from openerp import http -from openerp.http import request +from odoo import http +from odoo.http import request _logger = logging.getLogger(__name__) diff --git a/addons/payment_authorize/models/payment.py b/addons/payment_authorize/models/payment.py index b9a16ee37fb..b7488937e61 100644 --- a/addons/payment_authorize/models/payment.py +++ b/addons/payment_authorize/models/payment.py @@ -6,10 +6,10 @@ import logging import time import urlparse -from openerp import api, fields, models -from openerp.addons.payment.models.payment_acquirer import ValidationError -from openerp.addons.payment_authorize.controllers.main import AuthorizeController -from openerp.tools.float_utils import float_compare +from odoo import api, fields, models +from odoo.addons.payment.models.payment_acquirer import ValidationError +from odoo.addons.payment_authorize.controllers.main import AuthorizeController +from odoo.tools.float_utils import float_compare _logger = logging.getLogger(__name__) @@ -17,6 +17,10 @@ _logger = logging.getLogger(__name__) class PaymentAcquirerAuthorize(models.Model): _inherit = 'payment.acquirer' + provider = fields.Selection(selection_add=[('authorize', 'Authorize.Net')]) + authorize_login = fields.Char(string='API Login Id', required_if_provider='authorize') + authorize_transaction_key = fields.Char(string='API Transaction Key', required_if_provider='authorize') + def _get_authorize_urls(self, environment): """ Authorize URLs """ if environment == 'prod': @@ -24,15 +28,6 @@ class PaymentAcquirerAuthorize(models.Model): else: return {'authorize_form_url': 'https://test.authorize.net/gateway/transact.dll'} - @api.model - def _get_providers(self): - providers = super(PaymentAcquirerAuthorize, self)._get_providers() - providers.append(['authorize', 'Authorize.Net']) - return providers - - authorize_login = fields.Char(string='API Login Id', required_if_provider='authorize') - authorize_transaction_key = fields.Char(string='API Transaction Key', required_if_provider='authorize') - def _authorize_generate_hashing(self, values): data = '^'.join([ values['x_login'], diff --git a/addons/payment_authorize/tests/__init__.py b/addons/payment_authorize/tests/__init__.py index 32a44646439..10e174a320e 100644 --- a/addons/payment_authorize/tests/__init__.py +++ b/addons/payment_authorize/tests/__init__.py @@ -1,4 +1,3 @@ # -*- coding: utf-8 -*- -from openerp.addons.payment_authorize.tests import test_authorize - +from . import test_authorize diff --git a/addons/payment_authorize/tests/test_authorize.py b/addons/payment_authorize/tests/test_authorize.py index fa477692f4d..464a794d481 100644 --- a/addons/payment_authorize/tests/test_authorize.py +++ b/addons/payment_authorize/tests/test_authorize.py @@ -6,28 +6,27 @@ import time import urlparse from lxml import objectify -import openerp -from openerp.addons.payment.models.payment_acquirer import ValidationError -from openerp.addons.payment.tests.common import PaymentAcquirerCommon -from openerp.addons.payment_authorize.controllers.main import AuthorizeController -from openerp.tools import mute_logger +import odoo +from odoo.addons.payment.models.payment_acquirer import ValidationError +from odoo.addons.payment.tests.common import PaymentAcquirerCommon +from odoo.addons.payment_authorize.controllers.main import AuthorizeController +from odoo.tools import mute_logger -@openerp.tests.common.at_install(True) -@openerp.tests.common.post_install(True) +@odoo.tests.common.at_install(True) +@odoo.tests.common.post_install(True) class AuthorizeCommon(PaymentAcquirerCommon): def setUp(self): super(AuthorizeCommon, self).setUp() - self.base_url = self.env['ir.config_parameter'].get_param('web.base.url') # authorize only support USD in test environment self.currency_usd = self.env['res.currency'].search([('name', '=', 'USD')], limit=1)[0] # get the authorize account - model, self.authorize_id = self.env['ir.model.data'].get_object_reference('payment', 'payment_acquirer_authorize') + self.authorize = self.env.ref('payment.payment_acquirer_authorize') -@openerp.tests.common.at_install(True) -@openerp.tests.common.post_install(True) +@odoo.tests.common.at_install(True) +@odoo.tests.common.post_install(True) class AuthorizeForm(AuthorizeCommon): def _authorize_generate_hashing(self, values): @@ -40,25 +39,25 @@ class AuthorizeForm(AuthorizeCommon): return hmac.new(str(values['x_trans_key']), data, hashlib.md5).hexdigest() def test_10_Authorize_form_render(self): - authorize = self.env['payment.acquirer'].browse(self.authorize_id) - self.assertEqual(authorize.environment, 'test', 'test without test environment') + self.assertEqual(self.authorize.environment, 'test', 'test without test environment') # ---------------------------------------- # Test: button direct rendering # ---------------------------------------- + base_url = self.env['ir.config_parameter'].get_param('web.base.url') form_values = { - 'x_login': authorize.authorize_login, - 'x_trans_key': authorize.authorize_transaction_key, + 'x_login': self.authorize.authorize_login, + 'x_trans_key': self.authorize.authorize_transaction_key, 'x_amount': '320.0', 'x_show_form': 'PAYMENT_FORM', 'x_type': 'AUTH_CAPTURE', 'x_method': 'CC', - 'x_fp_sequence': '%s%s' % (authorize.id, int(time.time())), + 'x_fp_sequence': '%s%s' % (self.authorize.id, int(time.time())), 'x_version': '3.1', 'x_relay_response': 'TRUE', 'x_fp_timestamp': str(int(time.time())), - 'x_relay_url': '%s' % urlparse.urljoin(self.base_url, AuthorizeController._return_url), - 'x_cancel_url': '%s' % urlparse.urljoin(self.base_url, AuthorizeController._cancel_url), + 'x_relay_url': '%s' % urlparse.urljoin(base_url, AuthorizeController._return_url), + 'x_cancel_url': '%s' % urlparse.urljoin(base_url, AuthorizeController._cancel_url), 'return_url': None, 'x_currency_code': 'USD', 'x_invoice_num': 'SO004', @@ -84,10 +83,7 @@ class AuthorizeForm(AuthorizeCommon): form_values['x_fp_hash'] = self._authorize_generate_hashing(form_values) # render the button - cr, uid, context = self.env.cr, self.env.uid, {} - res = self.payment_acquirer.render( - cr, uid, self.authorize_id, 'SO004', 320.0, self.currency_usd.id, - values=self.buyer_values, context=context) + res = self.authorize.render('SO004', 320.0, self.currency_usd.id, values=self.buyer_values) # check form result tree = objectify.fromstring(res) self.assertEqual(tree.get('action'), 'https://test.authorize.net/gateway/transact.dll', 'Authorize: wrong form POST url') @@ -101,12 +97,10 @@ class AuthorizeForm(AuthorizeCommon): 'Authorize: wrong value for input %s: received %s instead of %s' % (values[1], values[2], form_values[values[1]]) ) - @mute_logger('openerp.addons.payment_authorize.models.authorize', 'ValidationError') + @mute_logger('openerp.addons.payment_authorize.models.payment', 'ValidationError') def test_20_authorize_form_management(self): - cr, uid, context = self.env.cr, self.env.uid, {} # be sure not to do stupid thing - authorize = self.env['payment.acquirer'].browse(self.authorize_id) - self.assertEqual(authorize.environment, 'test', 'test without test environment') + self.assertEqual(self.authorize.environment, 'test', 'test without test environment') # typical data posted by authorize after client has successfully paid authorize_post_data = { @@ -157,17 +151,17 @@ class AuthorizeForm(AuthorizeCommon): # should raise error about unknown tx with self.assertRaises(ValidationError): - self.payment_transaction.form_feedback(cr, uid, authorize_post_data, 'authorize', context=context) + self.env['payment.transaction'].form_feedback(authorize_post_data, 'authorize') tx = self.env['payment.transaction'].create({ 'amount': 320.0, - 'acquirer_id': self.authorize_id, + 'acquirer_id': self.authorize.id, 'currency_id': self.currency_usd.id, 'reference': 'SO004', 'partner_name': 'Norbert Buyer', - 'partner_country_id': self.country_france_id}) + 'partner_country_id': self.country_france.id}) # validate it - self.payment_transaction.form_feedback(cr, uid, authorize_post_data, 'authorize', context=context) + self.env['payment.transaction'].form_feedback(authorize_post_data, 'authorize') # check state self.assertEqual(tx.state, 'done', 'Authorize: validation did not put tx into done state') self.assertEqual(tx.acquirer_reference, authorize_post_data.get('x_trans_id'), 'Authorize: validation did not update tx payid') @@ -177,6 +171,6 @@ class AuthorizeForm(AuthorizeCommon): # simulate an error authorize_post_data['x_response_code'] = u'3' - self.payment_transaction.form_feedback(cr, uid, authorize_post_data, 'authorize', context=context) + self.env['payment.transaction'].form_feedback(authorize_post_data, 'authorize') # check state self.assertEqual(tx.state, 'error', 'Authorize: erroneous validation did not put tx into error state') |
