コード例 #1
0
    def test_basket_calculate_by_staff_user_invalid_username(self, mocked_logger):
        """Verify that a staff user passing an invalid username gets a response about themselves
            and an error is logged about a non existant user """
        self.site_configuration.enable_partial_program = True
        self.site_configuration.save()
        offer = ProgramOfferFactory(
            site=self.site,
            benefit=PercentageDiscountBenefitWithoutRangeFactory(value=100),
            condition=ProgramCourseRunSeatsConditionFactory()
        )
        program_uuid = offer.condition.program_uuid
        program = self.mock_program_detail_endpoint(program_uuid, self.site_configuration.discovery_api_url)
        differentuser = self.create_user(username='******', is_staff=False)

        products = self._get_program_verified_seats(program)
        url = self._generate_sku_username_url(products, 'invalidusername')
        enrollment = [{'mode': 'verified', 'course_details': {'course_id': program['courses'][0]['key']}}]
        self.mock_user_data(differentuser.username, enrollment)

        expected = {
            'total_incl_tax_excl_discounts': sum(product.stockrecords.first().price_excl_tax
                                                 for product in products[1:]),
            'total_incl_tax': Decimal('300.00'),
            'currency': 'USD'
        }

        with self.assertRaises(Exception):
            response = self.client.get(url)
            self.assertEqual(response.status_code, 200)
            self.assertTrue(mocked_logger.called)
            self.assertEqual(response.data, expected)
コード例 #2
0
    def test_basket_calculate_by_staff_user_invalid_username(self, mock_get_lms_resource_for_user, mock_logger):
        """Verify that a staff user passing an invalid username gets a response the anonymous
            basket and an error is logged about a non existent user """
        self.site_configuration.enable_partial_program = True
        self.site_configuration.save()
        offer = ProgramOfferFactory(
            site=self.site,
            benefit=PercentageDiscountBenefitWithoutRangeFactory(value=100),
            condition=ProgramCourseRunSeatsConditionFactory()
        )
        program_uuid = offer.condition.program_uuid
        program = self.mock_program_detail_endpoint(program_uuid, self.site_configuration.discovery_api_url)

        products = self._get_program_verified_seats(program)
        url = self._generate_sku_url(products, username='******')

        expected = {
            'total_incl_tax_excl_discounts': sum(product.stockrecords.first().price_excl_tax
                                                 for product in products[1:]),
            'total_incl_tax': Decimal('300.00'),
            'currency': 'USD'
        }

        with self.assertRaises(Exception):
            response = self.client.get(url)

            self.assertFalse(
                mock_get_lms_resource_for_user.called, msg='LMS calls should be skipped for anonymous case.'
            )

            self.assertEqual(response.status_code, 200)
            self.assertTrue(mock_logger.called)
            self.assertEqual(response.data, expected)
コード例 #3
0
    def setup_other_user_basket_calculate(self):
        """
        Sets up basket calculate for another user.

        Returns:
            products, url: The product list and the url for the anonymous basket
                calculate.
        """
        self.site_configuration.enable_partial_program = True
        self.site_configuration.save()
        offer = ProgramOfferFactory(
            partner=self.partner,
            benefit=PercentageDiscountBenefitWithoutRangeFactory(value=100),
            condition=ProgramCourseRunSeatsConditionFactory())
        program_uuid = offer.condition.program_uuid
        program = self.mock_program_detail_endpoint(
            program_uuid, self.site_configuration.discovery_api_url)
        different_user = self.create_user(username='******',
                                          is_staff=False)

        products = self._get_program_verified_seats(program)
        url = self._generate_sku_url(
            products, username=different_user.username) + '&bundle={}'.format(
                program_uuid)
        enrollment = [{
            'mode': 'verified',
            'course_details': {
                'course_id': program['courses'][0]['key']
            }
        }]
        self.mock_user_data(different_user.username, owned_products=enrollment)

        return products, url
コード例 #4
0
    def _setup_anonymous_basket_calculate(self):
        """
        Sets up anonymous basket calculate.

        Returns:
            products, url: The product list and the url for the anonymous basket
                calculate.
        """
        self.site_configuration.enable_partial_program = True
        self.site_configuration.save()
        offer = ProgramOfferFactory(
            site=self.site,
            benefit=PercentageDiscountBenefitWithoutRangeFactory(value=100),
            condition=ProgramCourseRunSeatsConditionFactory())
        program_uuid = offer.condition.program_uuid
        program = self.mock_program_detail_endpoint(
            program_uuid, self.site_configuration.discovery_api_url)
        products = self._get_program_verified_seats(program)
        url = self._generate_sku_url(products, username=None)
        return products, url