示例#1
0
 def test_no_program_enrollment(self):
     """
     If a user is not enrolled a 404 should be raised when getting the price
     """
     course_run, user = create_purchasable_course_run()
     ProgramEnrollment.objects.filter(program=course_run.course.program, user=user).delete()
     with self.assertRaises(Http404):
         calculate_run_price(course_run, user)
示例#2
0
 def test_no_program_enrollment(self):
     """
     If a user is not enrolled a 404 should be raised when getting the price
     """
     course_run, user = create_purchasable_course_run()
     ProgramEnrollment.objects.filter(program=course_run.course.program, user=user).delete()
     with self.assertRaises(Http404):
         calculate_run_price(course_run, user)
示例#3
0
 def test_calculate_run_price_coupon(self):
     """
     If there is a coupon calculate_run_price should use calculate_coupon_price to get the discounted price
     """
     course_run, user = create_purchasable_course_run()
     coupon = CouponFactory.create(content_object=course_run.course)
     UserCoupon.objects.create(coupon=coupon, user=user)
     discounted_price = 5
     with patch('ecommerce.api.calculate_coupon_price', autospec=True) as _calculate_coupon_price:
         _calculate_coupon_price.return_value = discounted_price
         assert calculate_run_price(course_run, user) == (discounted_price, coupon)
     program_enrollment = course_run.course.program.programenrollment_set.first()
     fa_price = get_formatted_course_price(program_enrollment)['price']
     _calculate_coupon_price.assert_called_with(coupon, fa_price, course_run.edx_course_key)
示例#4
0
 def test_calculate_run_price_coupon(self):
     """
     If there is a coupon calculate_run_price should use calculate_coupon_price to get the discounted price
     """
     course_run, user = create_purchasable_course_run()
     coupon = CouponFactory.create(content_object=course_run.course)
     UserCoupon.objects.create(coupon=coupon, user=user)
     discounted_price = 5
     with patch('ecommerce.api.calculate_coupon_price', autospec=True) as _calculate_coupon_price:
         _calculate_coupon_price.return_value = discounted_price
         assert calculate_run_price(course_run, user) == (discounted_price, coupon)
     program_enrollment = course_run.course.program.programenrollment_set.first()
     fa_price = get_formatted_course_price(program_enrollment)['price']
     _calculate_coupon_price.assert_called_with(coupon, fa_price, course_run.edx_course_key)
示例#5
0
 def test_calculate_run_price_other_run(self):
     """
     If the coupon is for another course in this program it should not be returned here
     """
     course_run, user = create_purchasable_course_run()
     other_course = CourseRunFactory.create(course__program=course_run.course.program).course
     coupon = CouponFactory.create(content_object=other_course)
     UserCoupon.objects.create(coupon=coupon, user=user)
     discounted_price = 5
     program_enrollment = course_run.course.program.programenrollment_set.first()
     fa_price = get_formatted_course_price(program_enrollment)['price']
     with patch('ecommerce.api.calculate_coupon_price', autospec=True) as _calculate_coupon_price:
         _calculate_coupon_price.return_value = discounted_price
         assert calculate_run_price(course_run, user) == (fa_price, None)
     assert _calculate_coupon_price.called is False
示例#6
0
 def test_calculate_run_price_no_coupons(self):
     """
     If there are no coupons for this program the price should be what get_formatted_course_price returned
     """
     course_run, user = create_purchasable_course_run()
     # This coupon is for a different program
     coupon = CouponFactory.create()
     UserCoupon.objects.create(coupon=coupon, user=user)
     discounted_price = 5
     program_enrollment = course_run.course.program.programenrollment_set.first()
     fa_price = get_formatted_course_price(program_enrollment)['price']
     with patch('ecommerce.api.calculate_coupon_price', autospec=True) as _calculate_coupon_price:
         _calculate_coupon_price.return_value = discounted_price
         assert calculate_run_price(course_run, user) == (fa_price, None)
     assert _calculate_coupon_price.called is False
示例#7
0
 def test_calculate_run_price_other_run(self):
     """
     If the coupon is for another course in this program it should not be returned here
     """
     course_run, user = create_purchasable_course_run()
     other_course = CourseRunFactory.create(course__program=course_run.course.program).course
     coupon = CouponFactory.create(content_object=other_course)
     UserCoupon.objects.create(coupon=coupon, user=user)
     discounted_price = 5
     program_enrollment = course_run.course.program.programenrollment_set.first()
     fa_price = get_formatted_course_price(program_enrollment)['price']
     with patch('ecommerce.api.calculate_coupon_price', autospec=True) as _calculate_coupon_price:
         _calculate_coupon_price.return_value = discounted_price
         assert calculate_run_price(course_run, user) == (fa_price, None)
     assert _calculate_coupon_price.called is False
示例#8
0
 def test_calculate_run_price_no_coupons(self):
     """
     If there are no coupons for this program the price should be what get_formatted_course_price returned
     """
     course_run, user = create_purchasable_course_run()
     # This coupon is for a different program
     coupon = CouponFactory.create()
     UserCoupon.objects.create(coupon=coupon, user=user)
     discounted_price = 5
     program_enrollment = course_run.course.program.programenrollment_set.first()
     fa_price = get_formatted_course_price(program_enrollment)['price']
     with patch('ecommerce.api.calculate_coupon_price', autospec=True) as _calculate_coupon_price:
         _calculate_coupon_price.return_value = discounted_price
         assert calculate_run_price(course_run, user) == (fa_price, None)
     assert _calculate_coupon_price.called is False