summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2016-07-05 14:21:26 +0200
committerThibault Delavallée <tde@openerp.com>2016-07-06 15:10:49 +0200
commit415eee1ca7c3b7db71c493f288f274f19b662f2f (patch)
treed8d11f4cdff46e59223b895c05759a48d63d1ada
parent86a51d28d02a0a0f819e218ece00cfd9d2dd85c2 (diff)
[CLN] payment_stripe: cleaning and guidelines
As this module is already in new API only small linting is performed.
-rw-r--r--addons/payment_stripe/models/payment.py10
-rw-r--r--addons/payment_stripe/tests/test_stripe.py27
2 files changed, 14 insertions, 23 deletions
diff --git a/addons/payment_stripe/models/payment.py b/addons/payment_stripe/models/payment.py
index e1d1d8e1aa8..59f9b1a8c82 100644
--- a/addons/payment_stripe/models/payment.py
+++ b/addons/payment_stripe/models/payment.py
@@ -19,19 +19,15 @@ STRIPE_HEADERS = {'Stripe-Version': '2016-03-07'}
class PaymentAcquirerStripe(models.Model):
_inherit = 'payment.acquirer'
+ provider = fields.Selection(selection_add=[('stripe', 'Stripe')])
stripe_secret_key = fields.Char(required_if_provider='stripe')
stripe_publishable_key = fields.Char(required_if_provider='stripe')
- stripe_image_url = fields.Char("Checkout Image URL",
+ stripe_image_url = fields.Char(
+ "Checkout Image URL",
help="A relative or absolute URL pointing to a square image of your "
"brand or product. As defined in your Stripe profile. See: "
"https://stripe.com/docs/checkout")
- @api.model
- def _get_providers(self):
- providers = super(PaymentAcquirerStripe, self)._get_providers()
- providers.append(['stripe', 'Stripe'])
- return providers
-
@api.multi
def stripe_form_generate_values(self, tx_values):
self.ensure_one()
diff --git a/addons/payment_stripe/tests/test_stripe.py b/addons/payment_stripe/tests/test_stripe.py
index 496ede5c8fd..ef2f6627cd8 100644
--- a/addons/payment_stripe/tests/test_stripe.py
+++ b/addons/payment_stripe/tests/test_stripe.py
@@ -12,9 +12,7 @@ class StripeCommon(PaymentAcquirerCommon):
def setUp(self):
super(StripeCommon, self).setUp()
- self.currency_euro = self.env['res.currency'].search([('name', '=', 'EUR')], limit=1)
- # get the stripe account
- self.stripe_id = self.env.ref('payment.payment_acquirer_stripe').id
+ self.stripe = self.env.ref('payment.payment_acquirer_stripe')
@odoo.tests.common.at_install(True)
@@ -22,18 +20,17 @@ class StripeCommon(PaymentAcquirerCommon):
class StripeTest(StripeCommon):
def test_10_stripe_s2s(self):
- stripe = self.env['payment.acquirer'].browse(self.stripe_id)
- self.assertEqual(stripe.environment, 'test', 'test without test environment')
+ self.assertEqual(self.stripe.environment, 'test', 'test without test environment')
# Add Stripe credentials
- stripe.write({
+ self.stripe.write({
'stripe_secret_key': 'sk_test_bldAlqh1U24L5HtRF9mBFpK7',
'stripe_publishable_key': 'pk_test_0TKSyYSZS9AcS4keZ2cxQQCW',
})
# Create payment meethod for Stripe
payment_token = self.env['payment.token'].create({
- 'acquirer_id': self.stripe_id,
+ 'acquirer_id': self.stripe.id,
'partner_id': self.buyer_id,
'cc_number': '4242424242424242',
'cc_expiry': '02 / 26',
@@ -46,7 +43,7 @@ class StripeTest(StripeCommon):
tx = self.env['payment.transaction'].create({
'reference': 'test_ref_%s' % fields.date.today(),
'currency_id': self.currency_euro.id,
- 'acquirer_id': self.stripe_id,
+ 'acquirer_id': self.stripe.id,
'partner_id': self.buyer_id,
'payment_token_id': payment_token.id,
'type': 'server2server',
@@ -58,8 +55,7 @@ class StripeTest(StripeCommon):
self.assertEqual(tx.state, 'done', 'Stripe: Transcation has been discarded.')
def test_20_stripe_form_render(self):
- stripe = self.env['payment.acquirer'].browse(self.stripe_id)
- self.assertEqual(stripe.environment, 'test', 'test without test environment')
+ self.assertEqual(self.stripe.environment, 'test', 'test without test environment')
# ----------------------------------------
# Test: button direct rendering
@@ -77,7 +73,7 @@ class StripeTest(StripeCommon):
}
# render the button
- res = stripe.render('SO404', 320.0, self.currency_euro.id, values=self.buyer_values)
+ res = self.stripe.render('SO404', 320.0, self.currency_euro.id, values=self.buyer_values)
post_url = "https://checkout.stripe.com/checkout.js"
email = "norbert.buyer@example.com"
# check form result
@@ -91,8 +87,7 @@ class StripeTest(StripeCommon):
)
def test_30_stripe_form_management(self):
- stripe = self.env['payment.acquirer'].browse(self.stripe_id)
- self.assertEqual(stripe.environment, 'test', 'test without test environment')
+ self.assertEqual(self.stripe.environment, 'test', 'test without test environment')
# typical data posted by Stripe after client has successfully paid
stripe_post_data = {
@@ -153,11 +148,11 @@ class StripeTest(StripeCommon):
tx = self.env['payment.transaction'].create({
'amount': 4700,
- 'acquirer_id': self.stripe_id,
+ 'acquirer_id': self.stripe.id,
'currency_id': self.currency_euro.id,
'reference': 'SO100',
'partner_name': 'Norbert Buyer',
- 'partner_country_id': self.country_france_id})
+ 'partner_country_id': self.country_france.id})
# validate it
tx.form_feedback(stripe_post_data, 'stripe')
@@ -168,7 +163,7 @@ class StripeTest(StripeCommon):
# simulate an error
stripe_post_data['status'] = 'error'
stripe_post_data.update({u'error': {u'message': u"Your card's expiration year is invalid.", u'code': u'invalid_expiry_year', u'type': u'card_error', u'param': u'exp_year'}})
- with mute_logger('openerp.addons.payment_stripe.models.payment_transaction'):
+ with mute_logger('openerp.addons.payment_stripe.models.payment'):
tx.form_feedback(stripe_post_data, 'stripe')
# check state
self.assertEqual(tx.state, 'error', 'Stipe: erroneous validation did not put tx into error state')