added a first pass for payment.tests.TransactionTest.test_paymentmanager_charge to illustrate use of PaymentManager.charge() -> hardwired for stripelib right now....

pull/1/head
Raymond Yee 2013-06-28 16:05:19 -07:00
parent 172ed2f557
commit ccbc78a10c
2 changed files with 44 additions and 3 deletions

View File

@ -31,6 +31,7 @@ from regluit.payment.parameters import (
TRANSACTION_STATUS_COMPLETE,
TRANSACTION_STATUS_ERROR,
PAYMENT_TYPE_AUTHORIZATION,
PAYMENT_TYPE_INSTANT,
TRANSACTION_STATUS_CANCELED
)
from regluit.payment.signals import transaction_charged, transaction_failed
@ -680,13 +681,10 @@ class Processor(baseprocessor.Processor):
if p.success() and not p.error():
transaction.pay_key = p.key()
transaction.save()
return True
else:
transaction.error = p.error_string()
transaction.save()
logger.info("execute_transaction Error: " + p.error_string())
return False
def amount( self ):
return self.transaction.amount

View File

@ -297,6 +297,49 @@ class TransactionTest(TestCase):
self.assertEqual(results[0].amount, D('12.34'))
self.assertEqual(c.left,c.target-D('12.34'))
self.assertEqual(c.supporters_count, 1)
def test_paymentmanager_charge(self):
"""
test regluit.payment.manager.PaymentManager.charge
trying to simulate the conditions of having a bare transaction setup before we try to do
an instant charge.
"""
user = User.objects.create_user('pm_charge', 'support2@example.org', 'payment_test')
# need to create an Account to associate with user
from regluit.payment.stripelib import StripeClient, card, Processor
sc = StripeClient()
# valid card and Account
card0 = card()
stripe_processor = Processor()
account = stripe_processor.make_account(user,token=card0)
w = Work()
w.save()
c = Campaign(target=D('1000.00'),deadline=now() + timedelta(days=180),work=w)
c.save()
t = Transaction(host='stripelib')
t.max_amount = D('12.34')
t.type = PAYMENT_TYPE_NONE
t.status = TRANSACTION_STATUS_NONE
t.campaign = c
t.approved = False
t.user = user
t.save()
pm = PaymentManager()
response = pm.charge(t)
self.assertEqual(t.status, TRANSACTION_STATUS_COMPLETE)
self.assertEqual(t.type, EXECUTE_TYPE_CHAINED_INSTANT)
self.assertEqual(t.amount, D('12.34'))
class BasicGuiTest(TestCase):
def setUp(self):