def test_add_multiple_products_and_use_voucher(self, usage): """ Verify the basket accepts multiple products and a single use voucher. """ products = ProductFactory.create_batch( 3, stockrecords__partner=self.partner) voucher = factories.VoucherFactory(usage=usage) product_range = factories.RangeFactory(products=products) voucher.offers.add( factories.ConditionalOfferFactory( benefit=factories.BenefitFactory(range=product_range), condition=factories.ConditionFactory(range=product_range))) qs = urllib.urlencode( { 'sku': [ product.stockrecords.first().partner_sku for product in products ], 'code': voucher.code }, True) url = '{root}?{qs}'.format(root=self.path, qs=qs) response = self.client.get(url) self.assertEqual(response.status_code, 303) basket = response.wsgi_request.basket self.assertEqual(basket.status, Basket.OPEN) self.assertTrue(basket.contains_voucher(voucher.code))
def test_coupon_applied_on_site_offer(self): """Coupon offer supersedes site offer.""" product_price = 100 site_offer_discount = 20 voucher_discount = 10 voucher, product = prepare_voucher(benefit_value=voucher_discount) stockrecord = product.stockrecords.first() stockrecord.price_excl_tax = product_price stockrecord.save() _range = factories.RangeFactory(includes_all_products=True) site_offer = factories.ConditionalOfferFactory( offer_type=ConditionalOffer.SITE, benefit=factories.BenefitFactory(range=_range, value=site_offer_discount), condition=factories.ConditionFactory(type=Condition.COVERAGE, value=1, range=_range)) self.basket.add_product(product) # Only site offer is applied to the basket. self.assert_basket_discounts([site_offer]) # Only the voucher offer is applied to the basket. self.client.post(reverse('basket:vouchers-add'), data={'code': voucher.code}) self.assert_basket_discounts( expected_voucher_discounts=[voucher.offers.first()]) # Site offer discount is still present after removing voucher. self.client.post( reverse('basket:vouchers-remove', kwargs={'pk': voucher.id})) self.assert_basket_discounts([site_offer])