Commit 6538e989 by Diana Huang

Fix some of the shopping cart tests.

parent af2424da
......@@ -20,10 +20,14 @@ from course_modes.models import CourseMode
from shoppingcart.exceptions import PurchasedCallbackException
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class OrderTest(TestCase):
def setUp(self):
self.user = UserFactory.create()
self.course_id = "test/course"
self.course_id = "org/test/Test_Course"
CourseFactory.create(org='org', number='test', display_name='Test Course 1')
for i in xrange(1, 5):
CourseFactory.create(org='org', number='test', display_name='Test Course {0}'.format(i))
self.cost = 40
def test_get_cart_for_user(self):
......@@ -38,7 +42,7 @@ class OrderTest(TestCase):
def test_cart_clear(self):
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, self.course_id, self.cost, 'honor')
CertificateItem.add_to_order(cart, 'test/course1', self.cost, 'honor')
CertificateItem.add_to_order(cart, 'org/test/Test_Course_1', self.cost, 'honor')
self.assertEquals(cart.orderitem_set.count(), 2)
cart.clear()
self.assertEquals(cart.orderitem_set.count(), 0)
......@@ -58,10 +62,10 @@ class OrderTest(TestCase):
def test_total_cost(self):
cart = Order.get_cart_for_user(user=self.user)
# add items to the order
course_costs = [('test/course1', 30),
('test/course2', 40),
('test/course3', 10),
('test/course4', 20)]
course_costs = [('org/test/Test_Course_1', 30),
('org/test/Test_Course_2', 40),
('org/test/Test_Course_3', 10),
('org/test/Test_Course_4', 20)]
for course, cost in course_costs:
CertificateItem.add_to_order(cart, course, cost, 'honor')
self.assertEquals(cart.orderitem_set.count(), len(course_costs))
......@@ -225,13 +229,14 @@ class PaidCourseRegistrationTest(ModuleStoreTestCase):
self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course_id))
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class CertificateItemTest(TestCase):
"""
Tests for verifying specific CertificateItem functionality
"""
def setUp(self):
self.user = UserFactory.create()
self.course_id = "test/course"
self.course_id = "org/test/Test_Course"
self.cost = 40
course_mode = CourseMode(course_id=self.course_id,
mode_slug="honor",
......@@ -243,6 +248,7 @@ class CertificateItemTest(TestCase):
mode_display_name="verified cert",
min_price=self.cost)
course_mode.save()
CourseFactory.create(org='org', number='test', run='course', display_name='Test Course')
def test_existing_enrollment(self):
CourseEnrollment.enroll(self.user, self.course_id)
......
......@@ -50,6 +50,8 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
mode_display_name="honor cert",
min_price=self.cost)
self.course_mode.save()
self.verified_course_id = 'org/test/Test_Course'
CourseFactory.create(org='org', number='test', run='course1', display_name='Test Course')
self.cart = Order.get_cart_for_user(self.user)
def login_user(self):
......@@ -91,7 +93,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
def test_show_cart(self):
self.login_user()
reg_item = PaidCourseRegistration.add_to_order(self.cart, self.course_id)
cert_item = CertificateItem.add_to_order(self.cart, 'test/course1', self.cost, 'honor')
cert_item = CertificateItem.add_to_order(self.cart, self.verified_course_id, self.cost, 'honor')
resp = self.client.get(reverse('shoppingcart.views.show_cart', args=[]))
self.assertEqual(resp.status_code, 200)
......@@ -110,7 +112,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
def test_clear_cart(self):
self.login_user()
PaidCourseRegistration.add_to_order(self.cart, self.course_id)
CertificateItem.add_to_order(self.cart, 'test/course1', self.cost, 'honor')
CertificateItem.add_to_order(self.cart, self.verified_course_id, self.cost, 'honor')
self.assertEquals(self.cart.orderitem_set.count(), 2)
resp = self.client.post(reverse('shoppingcart.views.clear_cart', args=[]))
self.assertEqual(resp.status_code, 200)
......@@ -120,7 +122,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
def test_remove_item(self, exception_log):
self.login_user()
reg_item = PaidCourseRegistration.add_to_order(self.cart, self.course_id)
cert_item = CertificateItem.add_to_order(self.cart, 'test/course1', self.cost, 'honor')
cert_item = CertificateItem.add_to_order(self.cart, self.verified_course_id, self.cost, 'honor')
self.assertEquals(self.cart.orderitem_set.count(), 2)
resp = self.client.post(reverse('shoppingcart.views.remove_item', args=[]),
{'id': reg_item.id})
......@@ -166,7 +168,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
def test_show_receipt_404s(self):
PaidCourseRegistration.add_to_order(self.cart, self.course_id)
CertificateItem.add_to_order(self.cart, 'test/course1', self.cost, 'honor')
CertificateItem.add_to_order(self.cart, self.verified_course_id, self.cost, 'honor')
self.cart.purchase()
user2 = UserFactory.create()
......@@ -184,7 +186,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
@patch('shoppingcart.views.render_to_response', render_mock)
def test_show_receipt_success(self):
reg_item = PaidCourseRegistration.add_to_order(self.cart, self.course_id)
cert_item = CertificateItem.add_to_order(self.cart, 'test/course1', self.cost, 'honor')
cert_item = CertificateItem.add_to_order(self.cart, self.verified_course_id, self.cost, 'honor')
self.cart.purchase(first='FirstNameTesting123', street1='StreetTesting123')
self.login_user()
......@@ -203,7 +205,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
@patch('shoppingcart.views.render_to_response', render_mock)
def test_show_receipt_success_refund(self):
reg_item = PaidCourseRegistration.add_to_order(self.cart, self.course_id)
cert_item = CertificateItem.add_to_order(self.cart, 'test/course1', self.cost, 'honor')
cert_item = CertificateItem.add_to_order(self.cart, self.verified_course_id, self.cost, 'honor')
self.cart.purchase(first='FirstNameTesting123', street1='StreetTesting123')
cert_item.status = "refunded"
cert_item.save()
......
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