From 63cfcd3de4fd6d1448b26aa5e7d61fdd64fc6e54 Mon Sep 17 00:00:00 2001 From: Jason Bau Date: Thu, 28 Aug 2014 10:08:00 -0700 Subject: [PATCH] change PaidCourseRegistration.contained_in_order now handles cases where the order has both a PaidCourseRegistration and a CertificateItem --- lms/djangoapps/shoppingcart/models.py | 7 +++++-- lms/djangoapps/shoppingcart/tests/test_models.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/shoppingcart/models.py b/lms/djangoapps/shoppingcart/models.py index 47d5d327f1..ac9704b258 100644 --- a/lms/djangoapps/shoppingcart/models.py +++ b/lms/djangoapps/shoppingcart/models.py @@ -478,8 +478,11 @@ class PaidCourseRegistration(OrderItem): """ Is the course defined by course_id contained in the order? """ - return course_id in [item.paidcourseregistration.course_id - for item in order.orderitem_set.all().select_subclasses("paidcourseregistration")] + return course_id in [ + item.course_id + for item in order.orderitem_set.all().select_subclasses("paidcourseregistration") + if isinstance(item, cls) + ] @classmethod def get_total_amount_of_purchased_item(cls, course_key): diff --git a/lms/djangoapps/shoppingcart/tests/test_models.py b/lms/djangoapps/shoppingcart/tests/test_models.py index cdaeda1826..2e340a87d8 100644 --- a/lms/djangoapps/shoppingcart/tests/test_models.py +++ b/lms/djangoapps/shoppingcart/tests/test_models.py @@ -337,6 +337,16 @@ class PaidCourseRegistrationTest(ModuleStoreTestCase): reg1.purchased_callback() self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course_key)) + def test_user_cart_has_both_items(self): + """ + This test exists b/c having both CertificateItem and PaidCourseRegistration in an order used to break + PaidCourseRegistration.contained_in_order + """ + cart = Order.get_cart_for_user(self.user) + CertificateItem.add_to_order(cart, self.course_key, self.cost, 'honor') + PaidCourseRegistration.add_to_order(self.cart, self.course_key) + self.assertTrue(PaidCourseRegistration.contained_in_order(cart, self.course_key)) + @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) class CertificateItemTest(ModuleStoreTestCase):