Pep8 fixes
This commit is contained in:
@@ -3,8 +3,10 @@ Tests for the Shopping Cart Models
|
||||
"""
|
||||
|
||||
from factory import DjangoModelFactory
|
||||
from mock import patch
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.db import DatabaseError
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
|
||||
@@ -12,7 +14,7 @@ from shoppingcart.models import Order, OrderItem, CertificateItem, InvalidCartIt
|
||||
from student.tests.factories import UserFactory
|
||||
from student.models import CourseEnrollment
|
||||
from course_modes.models import CourseMode
|
||||
from ..exceptions import PurchasedCallbackException
|
||||
from shoppingcart.exceptions import PurchasedCallbackException
|
||||
|
||||
|
||||
class OrderTest(TestCase):
|
||||
@@ -74,6 +76,17 @@ class OrderTest(TestCase):
|
||||
cart.purchase()
|
||||
self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_id))
|
||||
|
||||
def test_purchase_item_failure(self):
|
||||
# once again, we're testing against the specific implementation of
|
||||
# CertificateItem
|
||||
cart = Order.get_cart_for_user(user=self.user)
|
||||
CertificateItem.add_to_order(cart, self.course_id, self.cost, 'verified')
|
||||
with patch('shoppingcart.models.CertificateItem.save', side_effect=DatabaseError):
|
||||
with self.assertRaises(DatabaseError):
|
||||
cart.purchase()
|
||||
# verify that we rolled back the entire transaction
|
||||
self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course_id))
|
||||
|
||||
|
||||
class OrderItemTest(TestCase):
|
||||
def setUp(self):
|
||||
|
||||
@@ -22,6 +22,7 @@ from mitxmako.shortcuts import render_to_response
|
||||
from shoppingcart.processors import render_purchase_form_html, process_postpay_callback
|
||||
from mock import patch, Mock
|
||||
|
||||
|
||||
def mock_render_purchase_form_html(*args, **kwargs):
|
||||
return render_purchase_form_html(*args, **kwargs)
|
||||
|
||||
@@ -34,6 +35,7 @@ render_mock = Mock(side_effect=mock_render_to_response)
|
||||
|
||||
postpay_mock = Mock()
|
||||
|
||||
|
||||
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
|
||||
class ShoppingCartViewsTests(ModuleStoreTestCase):
|
||||
def setUp(self):
|
||||
@@ -53,7 +55,6 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
|
||||
def login_user(self):
|
||||
self.client.login(username=self.user.username, password="password")
|
||||
|
||||
|
||||
def test_add_course_to_cart_anon(self):
|
||||
resp = self.client.post(reverse('shoppingcart.views.add_course_to_cart', args=[self.course_id]))
|
||||
self.assertEqual(resp.status_code, 403)
|
||||
@@ -141,7 +142,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
|
||||
'Cannot remove cart OrderItem id={0}. DoesNotExist or item is already purchased'.format(cert_item.id))
|
||||
|
||||
resp3 = self.client.post(reverse('shoppingcart.views.remove_item', args=[]),
|
||||
{'id': -1})
|
||||
{'id': -1})
|
||||
self.assertEqual(resp3.status_code, 200)
|
||||
exception_log.assert_called_with(
|
||||
'Cannot remove cart OrderItem id={0}. DoesNotExist or item is already purchased'.format(-1))
|
||||
@@ -158,7 +159,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
|
||||
@patch('shoppingcart.views.process_postpay_callback', postpay_mock)
|
||||
@patch('shoppingcart.views.render_to_response', render_mock)
|
||||
def test_postpay_callback_failure(self):
|
||||
postpay_mock.return_value = {'success': False, 'order': self.cart, 'error_html':'ERROR_TEST!!!'}
|
||||
postpay_mock.return_value = {'success': False, 'order': self.cart, 'error_html': 'ERROR_TEST!!!'}
|
||||
self.login_user()
|
||||
resp = self.client.post(reverse('shoppingcart.views.postpay_callback', args=[]))
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
@@ -224,4 +225,4 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
|
||||
self.assertEqual(context['order'], self.cart)
|
||||
self.assertIn(reg_item.orderitem_ptr, context['order_items'])
|
||||
self.assertIn(cert_item.orderitem_ptr, context['order_items'])
|
||||
self.assertTrue(context['any_refunds'])
|
||||
self.assertTrue(context['any_refunds'])
|
||||
|
||||
@@ -26,7 +26,7 @@ def add_course_to_cart(request, course_id):
|
||||
PaidCourseRegistration.add_to_order(cart, course_id)
|
||||
except ItemNotFoundError:
|
||||
return HttpResponseNotFound(_('The course you requested does not exist.'))
|
||||
if request.method == 'GET': ### This is temporary for testing purposes and will go away before we pull
|
||||
if request.method == 'GET': # This is temporary for testing purposes and will go away before we pull
|
||||
return HttpResponseRedirect(reverse('shoppingcart.views.show_cart'))
|
||||
return HttpResponse(_("Course added to cart."))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user