Example #1
0
    def test_get_enterprise_customer_from_enterprise_offer(self, discount_value):
        """
        Verify that "get_enterprise_customer_from_enterprise_offer" returns `None` if expected conditions are not met.
        """
        course = CourseFactory(name='EnterpriseConsentErrorTest', partner=PartnerFactory())
        product = course.create_or_update_seat('verified', False, 50)

        benefit = EnterprisePercentageDiscountBenefitFactory(value=discount_value)
        offer = EnterpriseOfferFactory(benefit=benefit)
        # set wrong priority to invalidate the condition in util
        offer.priority = 111

        self.mock_enterprise_learner_api(
            learner_id=self.learner.id,
            enterprise_customer_uuid=str(offer.condition.enterprise_customer_uuid),
            course_run_id=course.id,
        )

        self.mock_catalog_contains_course_runs(
            [course.id],
            str(offer.condition.enterprise_customer_uuid),
            enterprise_customer_catalog_uuid=str(offer.condition.enterprise_customer_catalog_uuid),
            contains_content=True,
        )

        basket = BasketFactory(site=self.site, owner=self.create_user())
        basket.add_product(product)
        basket.strategy = DefaultStrategy()
        Applicator().apply_offers(basket, [offer])

        self.assertIsNone(get_enterprise_customer_from_enterprise_offer(basket))
Example #2
0
 def _redirect_for_enterprise_data_sharing_consent(self, basket):
     """
     Redirect to LMS to get data sharing consent from learner.
     """
     # check if basket contains only a single product of type seat
     if basket.lines.count() == 1 and basket.lines.first(
     ).product.is_seat_product:
         enterprise_custmer_uuid = get_enterprise_customer_from_enterprise_offer(
             basket)
         product = basket.lines.first().product
         course = product.course
         if enterprise_custmer_uuid is not None and enterprise_customer_user_needs_consent(
                 self.request.site,
                 enterprise_custmer_uuid,
                 course.id,
                 self.request.user.username,
         ):
             redirect_url = construct_enterprise_course_consent_url(
                 self.request, product.course.id, enterprise_custmer_uuid)
             raise RedirectException(
                 response=HttpResponseRedirect(redirect_url))