Exemplo n.º 1
0
    def test_apply(self, discount_param, jwt_decode_handler, request):  # pylint: disable=unused-argument
        request_type = discount_param[0]
        discount_percent = discount_param[1]
        discount_jwt = {
            'discount_applicable': True,
            'discount_percent': discount_percent
        }
        mock_kwargs = {
            'method': request_type,
            request_type: {
                'discount_jwt': discount_jwt
            }
        }
        request.return_value = Mock(**mock_kwargs)
        basket = BasketFactory(site=self.site, owner=self.create_user())

        product = ProductFactory(categories=[],
                                 stockrecords__price_currency='USD')
        basket.add_product(product)
        Applicator().apply(basket)

        if discount_percent is not None:
            # Our discount should be applied
            self.assertEqual(len(basket.offer_applications), 1)
            benefit = basket.offer_discounts[0].get('offer').benefit
            self.assertEqual(
                basket.total_discount,
                benefit.round(discount_jwt['discount_percent'] /
                              Decimal('100') *
                              basket.total_incl_tax_excl_discounts))
        else:
            self.assertEqual(len(basket.offer_applications), 0)
Exemplo n.º 2
0
 def apply_voucher(self, user, site, voucher):
     """ Apply the voucher to a basket. """
     basket = factories.BasketFactory(owner=user, site=site)
     product = voucher.offers.first().benefit.range.all_products()[0]
     basket.add_product(product)
     basket.vouchers.add(voucher)
     Applicator().apply(basket, self.user)
     return basket