Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)