Unify and refactor exception handling in framework and addons. The generic `except_osv` is now deprecated, and replaced by more specialized exception subtypes: - `UserError` (renamed from Warning, as it conflicts with the built-in `Warning`) raised when a non-technical error occurs during a business operation. It could be a missing information in the data provided by the user, or a misconfiguration. - `AccessError`: raised when any operation is denied because the user conducting it does not have the required access rights. - `AccessDenied`: raised when an operation that requires authenticated access is attempted via an unauthenticated request. - `MissingError`: raised when an operation is attempted on a record that does not exist. - `ValidationError`: raised when an operation violates a SQL or Python constraint. - All other exceptions are internal errors due to a system problem or bug, and raised untouched to the client-side, which should display a traceback. All exceptions take a single message argument. The `test_exceptions` module has been updated to showcase both new and old (deprecated) exceptions. A great many old `except_osv` had a useless title with "Error!" or "Warning", those have been removed, as this is handled by the client-side widget that displays the messages. This commit introduces a more consistent policy for logging errors and warnings: - All messages that do not require administrator attention should be logged at INFO level or lower. This includes all errors that are notified to the user in a friendly manner, even for access right problems or validation errors during business operations. - All messages that indicate a likely misconfiguration or malicious use by the users should be logged at WARNING level, as they typically require administrator attention. - All other unhandled internal errors cannot typically be handled by the user and should be logged at ERROR or higher level, as they require immediate administrator attention.
100 lines
4.2 KiB
Python
100 lines
4.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from lxml import objectify
|
|
import urlparse
|
|
|
|
from openerp.addons.payment.models.payment_acquirer import ValidationError
|
|
from openerp.addons.payment.tests.common import PaymentAcquirerCommon
|
|
from openerp.addons.payment_adyen.controllers.main import AdyenController
|
|
from openerp.tools import mute_logger
|
|
|
|
|
|
class AdyenCommon(PaymentAcquirerCommon):
|
|
|
|
def setUp(self):
|
|
super(AdyenCommon, self).setUp()
|
|
cr, uid = self.cr, self.uid
|
|
self.base_url = self.registry('ir.config_parameter').get_param(cr, uid, 'web.base.url')
|
|
|
|
# get the adyen account
|
|
model, self.adyen_id = self.registry('ir.model.data').get_object_reference(cr, uid, 'payment_adyen', 'payment_acquirer_adyen')
|
|
|
|
# some CC (always use expiration date 06 / 2016, cvc 737, cid 7373 (amex))
|
|
self.amex = (('370000000000002', '7373'))
|
|
self.dinersclub = (('36006666333344', '737'))
|
|
self.discover = (('6011601160116611', '737'), ('644564456445644', '737'))
|
|
self.jcb = (('3530111333300000', '737'))
|
|
self.mastercard = (('5555444433331111', '737'), ('5555555555554444', '737'))
|
|
self.visa = (('4111 1111 1111 1111', '737'), ('4444333322221111', '737'))
|
|
self.mcdebit = (('5500000000000004', '737'))
|
|
self.visadebit = (('4400000000000008', '737'))
|
|
self.maestro = (('6731012345678906', '737'))
|
|
self.laser = (('630495060000000000', '737'))
|
|
self.hipercard = (('6062828888666688', '737'))
|
|
self.dsmastercard = (('521234567890 1234', '737', 'user', 'password'))
|
|
self.dsvisa = (('4212345678901237', '737', 'user', 'password'))
|
|
self.mistercash = (('6703444444444449', None, 'user', 'password'))
|
|
|
|
|
|
class AdyenServer2Server(AdyenCommon):
|
|
|
|
def test_00_tx_management(self):
|
|
cr, uid, context = self.cr, self.uid, {}
|
|
|
|
|
|
class AdyenForm(AdyenCommon):
|
|
|
|
def test_10_adyen_form_render(self):
|
|
cr, uid, context = self.cr, self.uid, {}
|
|
# be sure not to do stupid things
|
|
adyen = self.payment_acquirer.browse(self.cr, self.uid, self.adyen_id, None)
|
|
self.assertEqual(adyen.environment, 'test', 'test without test environment')
|
|
|
|
# ----------------------------------------
|
|
# Test: button direct rendering
|
|
# ----------------------------------------
|
|
|
|
form_values = {
|
|
'merchantAccount': 'OpenERPCOM',
|
|
'merchantReference': 'test_ref0',
|
|
'skinCode': 'cbqYWvVL',
|
|
'paymentAmount': '1',
|
|
'currencyCode': 'EUR',
|
|
'resURL': '%s' % urlparse.urljoin(self.base_url, AdyenController._return_url),
|
|
}
|
|
|
|
# render the button
|
|
res = self.payment_acquirer.render(
|
|
cr, uid, self.adyen_id,
|
|
'test_ref0', 0.01, self.currency_euro_id,
|
|
partner_id=None,
|
|
partner_values=self.buyer_values,
|
|
context=context)
|
|
|
|
# check form result
|
|
tree = objectify.fromstring(res)
|
|
self.assertEqual(tree.get('action'), 'https://test.adyen.com/hpp/pay.shtml', 'adyen: wrong form POST url')
|
|
for form_input in tree.input:
|
|
if form_input.get('name') in ['submit', 'shipBeforeDate', 'sessionValidity', 'shopperLocale', 'merchantSig']:
|
|
continue
|
|
self.assertEqual(
|
|
form_input.get('value'),
|
|
form_values[form_input.get('name')],
|
|
'adyen: wrong value for input %s: received %s instead of %s' % (form_input.get('name'), form_input.get('value'), form_values[form_input.get('name')])
|
|
)
|
|
|
|
# @mute_logger('openerp.addons.payment_adyen.models.adyen', 'ValidationError')
|
|
# def test_20_paypal_form_management(self):
|
|
# cr, uid, context = self.cr, self.uid, {}
|
|
# # be sure not to do stupid things
|
|
# adyen = self.payment_acquirer.browse(self.cr, self.uid, self.adyen_id, None)
|
|
# self.assertEqual(adyen.env, 'test', 'test without test env')
|
|
|
|
# {'authResult': u'AUTHORISED',
|
|
# 'merchantReference': u'SO014',
|
|
# 'merchantReturnData': u'return_url=/shop/payment/validate',
|
|
# 'merchantSig': u'GaLRO8aMHFaQX3gQ5BVP/YETzeA=',
|
|
# 'paymentMethod': u'visa',
|
|
# 'pspReference': u'8813859935907337',
|
|
# 'shopperLocale': u'en_US',
|
|
# 'skinCode': u'cbqYWvVL'} |