Commit b475ac36 by Diana Huang

Some pep8/pylint cleanup

parent 055ad535
class PaymentException(Exception):
pass
class PurchasedCallbackException(PaymentException):
pass
class InvalidCartItem(PaymentException):
pass
......@@ -7,6 +7,7 @@ module = __import__('shoppingcart.processors.' + processor_name,
'process_postpay_callback',
])
def render_purchase_form_html(*args, **kwargs):
"""
The top level call to this module to begin the purchase.
......@@ -16,6 +17,7 @@ def render_purchase_form_html(*args, **kwargs):
"""
return module.render_purchase_form_html(*args, **kwargs)
def process_postpay_callback(*args, **kwargs):
"""
The top level call to this module after the purchase.
......@@ -29,4 +31,3 @@ def process_postpay_callback(*args, **kwargs):
return a helpful-enough error message in error_html.
"""
return module.process_postpay_callback(*args, **kwargs)
from shoppingcart.exceptions import PaymentException
class CCProcessorException(PaymentException):
pass
class CCProcessorSignatureException(CCProcessorException):
pass
class CCProcessorDataException(CCProcessorException):
pass
class CCProcessorWrongAmountException(CCProcessorException):
pass
......@@ -13,15 +13,16 @@ from mock import patch, Mock
TEST_CC_PROCESSOR = {
'CyberSource' : {
'CyberSource': {
'SHARED_SECRET': 'secret',
'MERCHANT_ID' : 'edx_test',
'SERIAL_NUMBER' : '12345',
'MERCHANT_ID': 'edx_test',
'SERIAL_NUMBER': '12345',
'ORDERPAGE_VERSION': '7',
'PURCHASE_ENDPOINT': '',
}
}
@override_settings(CC_PROCESSOR=TEST_CC_PROCESSOR)
class CyberSourceTests(TestCase):
......@@ -36,8 +37,8 @@ class CyberSourceTests(TestCase):
"""
Tests the hash function. Basically just hardcodes the answer.
"""
self.assertEqual(hash('test'), 'GqNJWF7X7L07nEhqMAZ+OVyks1Y=')
self.assertEqual(hash('edx '), '/KowheysqM2PFYuxVKg0P8Flfk4=')
self.assertEqual(processor_hash('test'), 'GqNJWF7X7L07nEhqMAZ+OVyks1Y=')
self.assertEqual(processor_hash('edx '), '/KowheysqM2PFYuxVKg0P8Flfk4=')
def test_sign_then_verify(self):
"""
......@@ -76,7 +77,7 @@ class CyberSourceTests(TestCase):
"""
DECISION = 'REJECT'
for code, reason in REASONCODE_MAP.iteritems():
params={
params = {
'decision': DECISION,
'reasonCode': code,
}
......@@ -109,8 +110,8 @@ class CyberSourceTests(TestCase):
student1.save()
student2 = UserFactory()
student2.save()
params_cc = {'card_accountNumber':'1234', 'card_cardType':'001', 'billTo_firstName':student1.first_name}
params_nocc = {'card_accountNumber':'', 'card_cardType':'002', 'billTo_firstName':student2.first_name}
params_cc = {'card_accountNumber': '1234', 'card_cardType': '001', 'billTo_firstName': student1.first_name}
params_nocc = {'card_accountNumber': '', 'card_cardType': '002', 'billTo_firstName': student2.first_name}
order1 = Order.get_cart_for_user(student1)
order2 = Order.get_cart_for_user(student2)
record_purchase(params_cc, order1)
......@@ -173,7 +174,7 @@ class CyberSourceTests(TestCase):
# tests for an order number that doesn't match up
params_bad_ordernum = params.copy()
params_bad_ordernum['orderNumber'] = str(order1.id+10)
params_bad_ordernum['orderNumber'] = str(order1.id + 10)
with self.assertRaises(CCProcessorDataException):
payment_accepted(params_bad_ordernum)
......@@ -215,7 +216,7 @@ class CyberSourceTests(TestCase):
self.assertDictContainsSubset({'amount': '1.00',
'currency': 'usd',
'orderPage_transactionType': 'sale',
'orderNumber':str(order1.id)},
'orderNumber': str(order1.id)},
context['params'])
def test_process_postpay_exception(self):
......
......@@ -12,6 +12,7 @@ from .processors import process_postpay_callback, render_purchase_form_html
log = logging.getLogger("shoppingcart")
def test(request, course_id):
item1 = PaidCourseRegistration(course_id, 200)
item1.purchased_callback(request.user.id)
......@@ -41,6 +42,7 @@ def register_for_verified_cert(request, course_id):
CertificateItem.add_to_order(cart, course_id, 30, 'verified')
return HttpResponse("Added")
@login_required
def show_cart(request):
cart = Order.get_cart_for_user(request.user)
......@@ -54,12 +56,14 @@ def show_cart(request):
'form_html': form_html,
})
@login_required
def clear_cart(request):
cart = Order.get_cart_for_user(request.user)
cart.clear()
return HttpResponse('Cleared')
@login_required
def remove_item(request):
item_id = request.REQUEST.get('id', '-1')
......@@ -71,6 +75,7 @@ def remove_item(request):
log.exception('Cannot remove cart OrderItem id={0}. DoesNotExist or item is already purchased'.format(item_id))
return HttpResponse('OK')
@csrf_exempt
def postpay_callback(request):
"""
......@@ -87,9 +92,10 @@ def postpay_callback(request):
if result['success']:
return HttpResponseRedirect(reverse('shoppingcart.views.show_receipt', args=[result['order'].id]))
else:
return render_to_response('shoppingcart/error.html', {'order':result['order'],
return render_to_response('shoppingcart/error.html', {'order': result['order'],
'error_html': result['error_html']})
@login_required
def show_receipt(request, ordernum):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment