Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lms/djangoapps/shoppingcart/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,11 @@ def contained_in_order(cls, order, course_id):
"""
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to use isinstance after all, because this is a function within the PaidCourseRegistration class

]

@classmethod
def get_total_amount_of_purchased_item(cls, course_key):
Expand Down
10 changes: 10 additions & 0 deletions lms/djangoapps/shoppingcart/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,16 @@ def test_purchased_callback_exception(self):
reg1.purchased_callback()
self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course_key))

def test_user_cart_has_both_items(self):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test passes with new implementation and fails with the old.

"""
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):
Expand Down