def test_offer_availability_with_max_user_discount(self, discount_type, num_prev_orders, is_satisfied): """ Verify that enterprise offer with discount type percentage and absolute, condition returns correct result based on user limits in the offer. """ benefits = { Benefit.PERCENTAGE: factories.EnterprisePercentageDiscountBenefitFactory(value=50), Benefit.FIXED: factories.EnterpriseAbsoluteDiscountBenefitFactory(value=50), } offer = factories.EnterpriseOfferFactory( partner=self.partner, benefit=benefits[discount_type], max_user_discount=100) for _ in range(num_prev_orders): order = OrderFactory(user=self.user, status=ORDER.COMPLETE) OrderDiscountFactory(order=order, offer_id=offer.id, amount=10) basket = BasketFactory(site=self.site, owner=self.user) basket.add_product(self.course_run.seat_products[0]) self.mock_catalog_contains_course_runs( [self.course_run.id], self.condition.enterprise_customer_uuid, self.site.siteconfiguration.enterprise_api_url, enterprise_customer_catalog_uuid=self.condition. enterprise_customer_catalog_uuid, ) self.assertEqual(self.condition.is_satisfied(offer, basket), is_satisfied)
def test_offer_availability_with_max_discount(self, discount_type, total_discount, is_satisfied): """ Verify that enterprise offer with discount type percentage and absolute, condition returns correct result based on total_discount(consumed discount so far) and discount on course price covered by the offer. """ benefits = { Benefit.PERCENTAGE: factories.EnterprisePercentageDiscountBenefitFactory(value=50), Benefit.FIXED: factories.EnterpriseAbsoluteDiscountBenefitFactory(value=70), } offer = factories.EnterpriseOfferFactory( partner=self.partner, benefit=benefits[discount_type], max_discount=Decimal(5000), total_discount=total_discount) basket = BasketFactory(site=self.site, owner=self.user) basket.add_product(self.course_run.seat_products[0]) self.mock_catalog_contains_course_runs( [self.course_run.id], self.condition.enterprise_customer_uuid, self.site.siteconfiguration.enterprise_api_url, enterprise_customer_catalog_uuid=self.condition. enterprise_customer_catalog_uuid, ) self.assertEqual(self.condition.is_satisfied(offer, basket), is_satisfied)
def test_absolute_benefit_offer_availability(self): """ Verify that enterprise offer condition returns correct result for an absolute benefit with discount value greater than course price. """ offer = factories.EnterpriseOfferFactory( partner=self.partner, benefit=factories.EnterpriseAbsoluteDiscountBenefitFactory(value=150), max_discount=Decimal(300), total_discount=Decimal(200) ) basket = BasketFactory(site=self.site, owner=self.user) basket.add_product(self.course_run.seat_products[0]) self.mock_catalog_contains_course_runs( [self.course_run.id], self.condition.enterprise_customer_uuid, enterprise_customer_catalog_uuid=self.condition.enterprise_customer_catalog_uuid, ) self.assertTrue(self.condition.is_satisfied(offer, basket))
def test_offer_availability_with_max_user_discount_including_refunds( self, discount_type, num_prev_orders, benefit_value, refund_count, is_satisfied): """ Verify that enterprise offer with discount type percentage and absolute, condition returns correct result based on user limits in the offer, even when user has refund history. """ current_refund_count = 0 benefits = { Benefit.PERCENTAGE: factories.EnterprisePercentageDiscountBenefitFactory( value=benefit_value), Benefit.FIXED: factories.EnterpriseAbsoluteDiscountBenefitFactory( value=benefit_value), } offer = factories.EnterpriseOfferFactory( partner=self.partner, benefit=benefits[discount_type], max_user_discount=150) for _ in range(num_prev_orders): order = OrderFactory(user=self.user, status=ORDER.COMPLETE) OrderDiscountFactory(order=order, offer_id=offer.id, amount=10) if current_refund_count < refund_count: RefundFactory(order=order, user=self.user, status=REFUND.COMPLETE) current_refund_count += 1 basket = BasketFactory(site=self.site, owner=self.user) basket.add_product(self.course_run.seat_products[0]) basket.add_product(self.entitlement) self.mock_course_detail_endpoint( discovery_api_url=self.site_configuration.discovery_api_url, course=self.entitlement) self.mock_catalog_contains_course_runs( [self.course_run.id], self.condition.enterprise_customer_uuid, enterprise_customer_catalog_uuid=self.condition. enterprise_customer_catalog_uuid, ) self.assertEqual(self.condition.is_satisfied(offer, basket), is_satisfied)
def test_absolute_benefit_offer_availability_with_max_user_discount(self): """ Verify that enterprise offer condition returns correct result for an absolute benefit with discount value greater than course price. """ offer = factories.EnterpriseOfferFactory( partner=self.partner, benefit=factories.EnterpriseAbsoluteDiscountBenefitFactory(value=150), max_user_discount=150 ) for _ in range(5): order = OrderFactory(user=self.user, status=ORDER.COMPLETE) OrderDiscountFactory(order=order, offer_id=offer.id, amount=10) basket = BasketFactory(site=self.site, owner=self.user) basket.add_product(self.course_run.seat_products[0]) self.mock_catalog_contains_course_runs( [self.course_run.id], self.condition.enterprise_customer_uuid, enterprise_customer_catalog_uuid=self.condition.enterprise_customer_catalog_uuid, ) self.assertTrue(self.condition.is_satisfied(offer, basket))