Commit b475ac36 by Diana Huang

Some pep8/pylint cleanup

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