Beispiel #1
0
    def test_basket_attribute_update(self, mock_update_course_enrollment):
        """ Verify the Sailthru campaign ID is saved as a basket attribute. """

        seat, order = self._create_order(99)
        process_basket_addition(None, request=self.request, user=self.user, product=seat, basket=order.basket)
        self.assertTrue(mock_update_course_enrollment.called)
        mock_update_course_enrollment.assert_called_with(
            TEST_EMAIL,
            self.course_url,
            True,
            seat.attr.certificate_type,
            course_id=self.course_id,
            currency=order.currency,
            message_id=CAMPAIGN_COOKIE,
            site_code=self.partner.short_code,
            unit_cost=order.total_excl_tax
        )

        # now call checkout_complete with the same basket to see if campaign id saved and restored
        process_checkout_complete(None, order=order, request=None)
        self.assertTrue(mock_update_course_enrollment.called)
        mock_update_course_enrollment.assert_called_with(
            TEST_EMAIL,
            self.course_url,
            False,
            seat.attr.certificate_type,
            course_id=self.course_id,
            currency=order.currency,
            message_id=CAMPAIGN_COOKIE,
            site_code=self.partner.short_code,
            unit_cost=order.total_excl_tax
        )
Beispiel #2
0
    def test_basket_attribute_update(self, mock_update_course_enrollment):
        """ Verify the Sailthru campaign ID is saved as a basket attribute. """

        seat, order = self._create_order(99)
        process_basket_addition(None, request=self.request,
                                user=self.user,
                                product=seat, basket=order.basket)
        self.assertTrue(mock_update_course_enrollment.called)
        mock_update_course_enrollment.assert_called_with(TEST_EMAIL,
                                                         self.course_url,
                                                         True,
                                                         seat.attr.certificate_type,
                                                         course_id=self.course_id,
                                                         currency=order.currency,
                                                         message_id=CAMPAIGN_COOKIE,
                                                         site_code='edX',
                                                         unit_cost=order.total_excl_tax)

        # now call checkout_complete with the same basket to see if campaign id saved and restored
        process_checkout_complete(None, order=order, request=None)
        self.assertTrue(mock_update_course_enrollment.called)
        mock_update_course_enrollment.assert_called_with(TEST_EMAIL,
                                                         self.course_url,
                                                         False,
                                                         seat.attr.certificate_type,
                                                         course_id=self.course_id,
                                                         currency=order.currency,
                                                         message_id=CAMPAIGN_COOKIE,
                                                         site_code='edX',
                                                         unit_cost=order.total_excl_tax)
Beispiel #3
0
    def test_basket_attribute_update_with_existing_attribute(self):
        """ Verify existing BasketAttribute values are updated if a user is modifying an existing basket. """
        campaign_id = 'attempt-1'
        seat, order = self._create_order(99)
        basket = order.basket
        self.request.COOKIES['sailthru_bid'] = campaign_id
        process_basket_addition(None,
                                request=self.request,
                                user=self.user,
                                product=seat,
                                basket=basket)
        self.assertEqual(
            basket.basketattribute_set.get(
                attribute_type=self.basket_attribute_type).value_text,
            campaign_id)

        # Call again to trigger another attempt to create an attribute
        campaign_id = 'attempt-2'
        self.request.COOKIES['sailthru_bid'] = campaign_id
        process_basket_addition(None,
                                request=self.request,
                                user=self.user,
                                product=seat,
                                basket=basket)
        self.assertEqual(
            basket.basketattribute_set.get(
                attribute_type=self.basket_attribute_type).value_text,
            campaign_id)
    def test_stop_sailthru_update_on_multi_product_baskets(
            self, mock_log_error, mock_update_course_enrollment):
        """ Verify Sailthru is not contacted for multi-product baskets. """
        # Create multi-product basket
        seat = self.course.create_or_update_seat('verified', False, 100, None)
        other_course = CourseFactory(partner=self.partner)
        other_seat = other_course.create_or_update_seat(
            'verified', False, 100, None)
        basket = BasketFactory(owner=self.user, site=self.site)
        basket.add_product(seat)
        basket.add_product(other_seat)
        multi_product_order = create_order(number=2,
                                           basket=basket,
                                           user=self.user,
                                           site=self.site)

        # This method takes an argument to determine whether that product is part of a multi-product basket
        process_basket_addition(None,
                                request=self.request,
                                user=self.user,
                                product=seat,
                                is_multi_product_basket=True)
        self.assertFalse(mock_update_course_enrollment.called)
        self.assertFalse(mock_log_error.called)

        # This method looks at the number of lines in the order to determine if the basket has multiple products
        process_checkout_complete(None,
                                  order=multi_product_order,
                                  request=None)
        self.assertFalse(mock_update_course_enrollment.called)
        self.assertFalse(mock_log_error.called)
Beispiel #5
0
    def test_basket_addition_with_free_product(self, mock_update_course_enrollment):
        """ Verify Sailthru is not contacted when free items are added to the basket. """

        seat = self._create_order(0)[0]
        process_basket_addition(None, request=self.request,
                                user=self.user,
                                product=seat)
        self.assertFalse(mock_update_course_enrollment.called)
Beispiel #6
0
    def test_signals_disabled(self, mock_log_error):
        """ Verify Sailthru is not contacted if the signals are disabled. """
        toggle_switch('sailthru_enable', False)
        process_checkout_complete(None)
        self.assertFalse(mock_log_error.called)

        process_basket_addition(None)
        self.assertFalse(mock_log_error.called)
Beispiel #7
0
    def test_signals_disabled(self, mock_log_error):
        """ Verify Sailthru is not contacted if the signals are disabled. """
        toggle_switch('sailthru_enable', False)
        process_checkout_complete(None)
        self.assertFalse(mock_log_error.called)

        process_basket_addition(None)
        self.assertFalse(mock_log_error.called)
    def test_price_zero(self, mock_update_course_enrollment):
        """
        Test that a price of zero skips update_course_enrollment in process basket
        """

        seat = self._create_order(0)[0]
        process_basket_addition(None, request=self.request,
                                user=self.user,
                                product=seat)
        self.assertFalse(mock_update_course_enrollment.called)
Beispiel #9
0
    def test_just_return_signals(self, mock_log_error):
        """
        Ensure that disabling Sailthru just returns
        """
        toggle_switch('sailthru_enable', False)
        process_checkout_complete(None)
        self.assertFalse(mock_log_error.called)

        process_basket_addition(None)
        self.assertFalse(mock_log_error.called)
Beispiel #10
0
    def test_basket_addition_with_free_product(self,
                                               mock_update_course_enrollment):
        """ Verify Sailthru is not contacted when free items are added to the basket. """

        seat = self._create_order(0)[0]
        process_basket_addition(None,
                                request=self.request,
                                user=self.user,
                                product=seat)
        self.assertFalse(mock_update_course_enrollment.called)
    def test_just_return_signals(self, mock_log_error):
        """
        Ensure that disabling Sailthru just returns
        """
        toggle_switch('sailthru_enable', False)
        process_checkout_complete(None)
        self.assertFalse(mock_log_error.called)

        process_basket_addition(None)
        self.assertFalse(mock_log_error.called)
Beispiel #12
0
    def test_price_zero(self, mock_update_course_enrollment):
        """
        Test that a price of zero skips update_course_enrollment in process basket
        """

        seat = self._create_order(0)[0]
        process_basket_addition(None,
                                request=self.request,
                                user=self.user,
                                product=seat)
        self.assertFalse(mock_update_course_enrollment.called)
Beispiel #13
0
    def test_unsupported_product_class(self, mock_log_error, mock_update_course_enrollment):
        """ Verify Sailthru is not contacted for non-seat products. """
        coupon = self.create_coupon()
        basket = BasketFactory()
        basket.add_product(coupon, 1)
        process_basket_addition(None, request=self.request, user=self.user, product=coupon, basket=basket)
        self.assertFalse(mock_update_course_enrollment.called)
        self.assertFalse(mock_log_error.called)

        order = create_order(number=1, basket=basket, user=self.user)
        process_checkout_complete(None, order=order, request=None)
        self.assertFalse(mock_update_course_enrollment.called)
        self.assertFalse(mock_log_error.called)
Beispiel #14
0
    def test_partner_not_supported(self, mock_log_error, mock_update_course_enrollment):
        """ Verify Sailthru is not contacted if the feature is disabled for the site. """
        self.site_configuration.enable_sailthru = False
        self.site_configuration.save()

        process_basket_addition(None, request=self.request)
        self.assertFalse(mock_update_course_enrollment.called)
        self.assertFalse(mock_log_error.called)

        __, order = self._create_order(99)
        process_checkout_complete(None, order=order)
        self.assertFalse(mock_update_course_enrollment.called)
        self.assertFalse(mock_log_error.called)
Beispiel #15
0
    def test_partner_not_supported(self, mock_log_error, mock_update_course_enrollment):
        """ Verify Sailthru is not contacted if the Partner does not support Sailthru. """
        site_configuration = SiteConfigurationFactory(partner__name='TestX')
        site_configuration.partner.enable_sailthru = False
        self.request.site.siteconfiguration = site_configuration
        process_basket_addition(None, request=self.request)
        self.assertFalse(mock_update_course_enrollment.called)
        self.assertFalse(mock_log_error.called)

        __, order = self._create_order(99)
        order.site.siteconfiguration = site_configuration
        process_checkout_complete(None, order=order)
        self.assertFalse(mock_update_course_enrollment.called)
        self.assertFalse(mock_log_error.called)
Beispiel #16
0
    def test_partner_not_supported(self, mock_log_error,
                                   mock_update_course_enrollment):
        """ Verify Sailthru is not contacted if the Partner does not support Sailthru. """
        site_configuration = SiteConfigurationFactory(partner__name='TestX')
        site_configuration.partner.enable_sailthru = False
        self.request.site.siteconfiguration = site_configuration
        process_basket_addition(None, request=self.request)
        self.assertFalse(mock_update_course_enrollment.called)
        self.assertFalse(mock_log_error.called)

        __, order = self._create_order(99)
        order.site.siteconfiguration = site_configuration
        process_checkout_complete(None, order=order)
        self.assertFalse(mock_update_course_enrollment.called)
        self.assertFalse(mock_log_error.called)
Beispiel #17
0
    def test_unsupported_product_class(self, mock_log_error, mock_update_course_enrollment):
        """ Verify Sailthru is not contacted for non-seat products. """
        coupon = self.create_coupon()
        basket = BasketFactory()
        basket.add_product(coupon, 1)
        process_basket_addition(None, request=self.request,
                                user=self.user,
                                product=coupon, basket=basket)
        self.assertFalse(mock_update_course_enrollment.called)
        self.assertFalse(mock_log_error.called)

        order = create_order(number=1, basket=basket, user=self.user)
        process_checkout_complete(None, order=order, request=None)
        self.assertFalse(mock_update_course_enrollment.called)
        self.assertFalse(mock_log_error.called)
Beispiel #18
0
    def test_basket_attribute_update_with_existing_attribute(self):
        """ Verify existing BasketAttribute values are updated if a user is modifying an existing basket. """
        campaign_id = 'attempt-1'
        seat, order = self._create_order(99)
        basket = order.basket
        self.request.COOKIES['sailthru_bid'] = campaign_id
        process_basket_addition(None, request=self.request, user=self.user, product=seat, basket=basket)
        self.assertEqual(basket.basketattribute_set.get(attribute_type=self.basket_attribute_type).value_text,
                         campaign_id)

        # Call again to trigger another attempt to create an attribute
        campaign_id = 'attempt-2'
        self.request.COOKIES['sailthru_bid'] = campaign_id
        process_basket_addition(None, request=self.request, user=self.user, product=seat, basket=basket)
        self.assertEqual(basket.basketattribute_set.get(attribute_type=self.basket_attribute_type).value_text,
                         campaign_id)
Beispiel #19
0
    def test_basket_addition(self, mock_update_course_enrollment):
        """ Verify the basket_addition receiver is called, and contacts Sailthru. """

        seat, order = self._create_order(99)
        process_basket_addition(None, request=self.request,
                                user=self.user,
                                product=seat)
        self.assertTrue(mock_update_course_enrollment.called)
        mock_update_course_enrollment.assert_called_with(TEST_EMAIL,
                                                         self.course_url,
                                                         True,
                                                         seat.attr.certificate_type,
                                                         course_id=self.course_id,
                                                         currency=order.currency,
                                                         message_id=CAMPAIGN_COOKIE,
                                                         site_code='edX',
                                                         unit_cost=order.total_excl_tax)
Beispiel #20
0
    def test_basket_addition(self, mock_update_course_enrollment):
        """ Verify the basket_addition receiver is called, and contacts Sailthru. """

        seat, order = self._create_order(99)
        process_basket_addition(None, request=self.request, user=self.user, product=seat)
        self.assertTrue(mock_update_course_enrollment.called)
        mock_update_course_enrollment.assert_called_with(
            TEST_EMAIL,
            self.course_url,
            True,
            seat.attr.certificate_type,
            course_id=self.course_id,
            currency=order.currency,
            message_id=CAMPAIGN_COOKIE,
            site_code=self.partner.short_code,
            unit_cost=order.total_excl_tax
        )
    def test_process_basket_addition(self, mock_update_course_enrollment):
        """
        Test that the process_basket_addition signal handler properly calls the task routine
        """

        seat, order = self._create_order(99)
        process_basket_addition(None, request=self.request,
                                user=self.user,
                                product=seat)
        self.assertTrue(mock_update_course_enrollment.called)
        mock_update_course_enrollment.assert_called_with(TEST_EMAIL,
                                                         self.course_url,
                                                         True,
                                                         seat.attr.certificate_type,
                                                         course_id=self.course_id,
                                                         currency=order.currency,
                                                         message_id='cookie_bid',
                                                         site_code='edX',
                                                         unit_cost=order.total_excl_tax)
Beispiel #22
0
    def test_process_basket_addition(self, mock_update_course_enrollment):
        """
        Test that the process_basket_addition signal handler properly calls the task routine
        """

        seat, order = self._create_order(99)
        process_basket_addition(None,
                                request=self.request,
                                user=self.user,
                                product=seat)
        self.assertTrue(mock_update_course_enrollment.called)
        mock_update_course_enrollment.assert_called_with(
            TEST_EMAIL,
            self.course_url,
            True,
            seat.attr.certificate_type,
            course_id=self.course_id,
            currency=order.currency,
            message_id='cookie_bid',
            site_code='edX',
            unit_cost=order.total_excl_tax)