Exemplo n.º 1
0
 def test_zero_tax_with_postage_and_discount(self):
     """test tax with postage and discount"""
     settings.CCCHECKOUT_TAX = Decimal('0.00')
     # make the postage
     line = Line()
     line.name='test postage'
     line.save()
     tier = LineTier()
     tier.price = Decimal('2.50')
     tier.minimum = 0
     tier.maximum = 100
     tier.line = line
     tier.save()
     # add the postages to the checkout
     self.checkout.postage = line
     self.checkout.postage_tier = tier
     self.checkout.save()
     # add a discount to the checkout
     d = DiscountCode()
     d.type = d.PERCENTAGE
     d.discount = Decimal('50.00')
     d.title = 'test discount'
     d.save()
     self.checkout.discount = d
     self.checkout.save()
     # now the tax should be 5,24
     self.assertEqual(Decimal('0.00'), self.checkout.total_tax())
Exemplo n.º 2
0
 def test_no_postage_with_discount(self):
     """test tax without postage and with discount"""
     # add a discount to the checkout
     d = DiscountCode()
     d.type = d.PERCENTAGE
     d.discount = Decimal('50.00')
     d.title = 'test discount'
     d.save()
     self.checkout.discount = d
     self.checkout.save()
     # now we should have half the tax - because of a 50% discount
     self.assertEqual(Decimal('2.20'), self.checkout.total_tax())
 def test_discount_code_form(self):
     """ensure the discoint form works as expected"""
     # make a discount code
     d = DiscountCode()
     d.type = DiscountCode.PERCENTAGE
     d.discount = Decimal('50.00')
     d.title = 'test discount'
     d.code = 'test'
     d.save()
     # make the form and get the discount
     form = DiscountCodeForm({'code': 'test'})
     form.is_valid()
     discount = form.save()
     self.assertEqual(discount.pk, d.pk)
 def test_monetary_based_discount(self):
     """monetary based discounts behave correctly"""
     d = DiscountCode()
     d.title = 'test discount code'
     d.code = 'TEST'
     d.type = DiscountCode.MONETARY
     d.discount = Decimal('2.00')
     d.save()
     # make the request
     #settings.CCCHECKOUT_ADAPTER = 'cccheckout.tests.mock.testcase_adapter'
     post_request = self.rf.post('/yeah', {'code': 'TEST'})
     self.request = post_request
     self.request.session['cccheckout'] = self.checkout
     self.request.session.save()
     # get start page ad checkout total is now 9.00
     response = customer(self.request)
     self.assertEqual(self.request.session['cccheckout'].total_price(),
                     Decimal('8.00'))
    def test_percentage_based_discount(self):
        """percentage based discounts behave correctly"""
        d = DiscountCode()
        d.title = 'test discount code'
        d.code = 'TEST'
        d.type = DiscountCode.PERCENTAGE
        d.discount = 10
        d.save()
        # make the request

        post_request = self.rf.post('/yeah', {'code': 'TEST'})
        self.request = post_request
        self.request.session['cccheckout'] = self.checkout
        self.request.session.save()
        # get start page abd checkout total is now 9.00
        response = customer(self.request)
        self.assertEqual(self.request.session['cccheckout'].total_price(),
                        Decimal('9.00'))
 def test_setcheckout_with_discount(self):
     """test the set checkout with discounts"""
     # add a discount
     d = DiscountCode()
     d.type = DiscountCode.PERCENTAGE
     d.discount = Decimal('50.00')
     d.code = 'TEST'
     d.save()
     self.checkout.discount = d
     self.checkout.save()
     # get the api
     api = PaypalExpressCheckout(checkout=self.checkout)
     # make the setExpressCheckout call
     api.setExpressCheckout()
     # we now have a token
     self.assertTrue(api.token)
     # remove the discount
     self.checkout.discount = None
     self.checkout.save()