예제 #1
0
 def test_coupon_allowed_program(self):
     """
     Assert that the price is not adjusted if the coupon is for a different program
     """
     course_run, _ = create_purchasable_course_run()
     price = Decimal('0.3')
     coupon = CouponFactory.create()
     assert coupon.content_object != course_run
     assert calculate_coupon_price(coupon, price, course_run.edx_course_key) == price
예제 #2
0
 def test_coupon_allowed_program(self):
     """
     Assert that the price is not adjusted if the coupon is for a different program
     """
     course_run, _ = create_purchasable_course_run()
     price = Decimal('0.3')
     coupon = CouponFactory.create()
     assert coupon.content_object != course_run
     assert calculate_coupon_price(coupon, price, course_run.edx_course_key) == price
예제 #3
0
 def test_capped_coupon_price_above_full(self):
     """
     Assert that the adjusted price cannot go above the full price
     """
     course_run, _ = create_purchasable_course_run()
     price = course_run.course.program.price
     coupon = CouponFactory.create(
         content_object=course_run.course, amount_type=Coupon.FIXED_DISCOUNT, amount=-(price + 50),
     )
     assert calculate_coupon_price(coupon, price, course_run.edx_course_key) == price
예제 #4
0
 def test_fixed_discount(self):
     """
     Assert the price with a fixed discount
     """
     course_run, _ = create_purchasable_course_run()
     price = Decimal(5)
     coupon = CouponFactory.create(
         content_object=course_run.course, amount_type=Coupon.FIXED_DISCOUNT, amount=Decimal("1.5")
     )
     assert calculate_coupon_price(coupon, price, course_run.edx_course_key) == price - coupon.amount
예제 #5
0
 def test_capped_coupon_price_above_full(self):
     """
     Assert that the adjusted price cannot go above the full price
     """
     course_run, _ = create_purchasable_course_run()
     price = course_run.course.program.price
     coupon = CouponFactory.create(
         content_object=course_run.course, amount_type=Coupon.FIXED_DISCOUNT, amount=-(price + 50),
     )
     assert calculate_coupon_price(coupon, price, course_run.edx_course_key) == price
예제 #6
0
 def test_fixed_discount(self):
     """
     Assert the price with a fixed discount
     """
     course_run, _ = create_purchasable_course_run()
     price = Decimal(5)
     coupon = CouponFactory.create(
         content_object=course_run.course, amount_type=Coupon.FIXED_DISCOUNT, amount=Decimal("1.5")
     )
     assert calculate_coupon_price(coupon, price, course_run.edx_course_key) == price - coupon.amount
예제 #7
0
 def test_calculate_coupon_price(self):
     """
     Assert that the price is not adjusted if the amount type is unknown
     """
     course_run, _ = create_purchasable_course_run()
     price = Decimal('0.3')
     coupon = CouponFactory.create(content_object=course_run.course)
     # Use manager to skip validation, which usually prevents setting content_object to an arbitrary object
     Coupon.objects.filter(id=coupon.id).update(amount_type='xyz')
     coupon.refresh_from_db()
     assert calculate_coupon_price(coupon, price, course_run.edx_course_key) == price
예제 #8
0
 def test_fixed_price(self):
     """
     Assert a fixed price coupon
     """
     course_run, _ = create_purchasable_course_run()
     price = Decimal(5)
     amount = Decimal("1.5")
     coupon = CouponFactory.create(
         content_object=course_run.course, amount_type=Coupon.FIXED_PRICE, amount=amount
     )
     assert calculate_coupon_price(coupon, price, course_run.edx_course_key) == amount
예제 #9
0
 def test_calculate_coupon_price(self):
     """
     Assert that the price is not adjusted if the amount type is unknown
     """
     course_run, _ = create_purchasable_course_run()
     price = Decimal('0.3')
     coupon = CouponFactory.create(content_object=course_run.course)
     # Use manager to skip validation, which usually prevents setting content_object to an arbitrary object
     Coupon.objects.filter(id=coupon.id).update(amount_type='xyz')
     coupon.refresh_from_db()
     assert calculate_coupon_price(coupon, price, course_run.edx_course_key) == price
예제 #10
0
 def test_fixed_price(self):
     """
     Assert a fixed price coupon
     """
     course_run, _ = create_purchasable_course_run()
     price = Decimal(5)
     amount = Decimal("1.5")
     coupon = CouponFactory.create(
         content_object=course_run.course, amount_type=Coupon.FIXED_PRICE, amount=amount
     )
     assert calculate_coupon_price(coupon, price, course_run.edx_course_key) == amount
예제 #11
0
 def test_percent_discount(self):
     """
     Assert the price with a percent discount
     """
     course_run, _ = create_purchasable_course_run()
     price = Decimal(5)
     coupon = CouponFactory.create(
         content_object=course_run.course,
         amount_type=Coupon.PERCENT_DISCOUNT,
         amount=Decimal("0.3"),
     )
     assert calculate_coupon_price(coupon, price, course_run.edx_course_key) == price * (1 - coupon.amount)
예제 #12
0
 def test_percent_discount(self):
     """
     Assert the price with a percent discount
     """
     course_run, _ = create_purchasable_course_run()
     price = Decimal(5)
     coupon = CouponFactory.create(
         content_object=course_run.course,
         amount_type=Coupon.PERCENT_DISCOUNT,
         amount=Decimal("0.3"),
     )
     assert calculate_coupon_price(coupon, price, course_run.edx_course_key) == price * (1 - coupon.amount)