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())
def setUp(self): """set up the environment for the tests""" reload(c_settings) session_key = '11111111111111111111111111111111' settings.CCCHECKOUT_ADAPTER = 'cccheckout.tests.mock.testcase_adapter' engine = import_module(settings.SESSION_ENGINE) # make mock basket lines p1 = MockBasketLine('10.00', 2, 'test thing') p2 = MockBasketLine('2.00', 1, 'anotjer') # make a customer customer = Customer(delivery_country='GB') customer.save() # make a checkout on the session c = Checkout() c.session_id = session_key c.customer = customer c.items = [p1, p2] c.item_total = Decimal('10.00') c.lines = 3 c.save() self.checkout = c # make request & add checkout self.rf = MockRequest() # add the postages line1 = Line(name='Test case line based postage') line1.save() country1 = LineCountry( country='GB', line = line1) country1.save() # add the tiers tier1 = LineTier( minimum=1, maximum=22, price=Decimal('1.00'), line=line1) tier1.save() # tier 2 tier2 = LineTier( minimum=23, maximum=50, price=Decimal('2.00'), line=line1) tier2.save() # now the content types line_ct = ContentType.objects.get_for_model(line1) tier_ct = ContentType.objects.get_for_model(tier1) # set up the selfs self.line1 = line1 self.country1 = country1 self.tier1 = tier1 self.tier2 = tier2 self.line_ct = line_ct self.tier_ct = tier_ct
def test_with_postage_no_discount(self): """test tax with postage and without discount""" # 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() self.assertEqual(Decimal('4.90'), self.checkout.total_tax())
def test_payment_responds_with_postage(self): """If there is postage then payment responds 200""" p = Line() p.name = 'test' p.save() p_tier = LineTier() p_tier.line = p p_tier.minimum = Decimal('0.00') p_tier.maximum = Decimal('0.00') p_tier.price = Decimal('2.00') p_tier.save() p_country = LineCountry() p_country.line = p p_country.country = 'GB' p_country.save() checkout = deepcopy(self.checkout) checkout.postage = p checkout.postage_tier = p_tier checkout.save() # process and all is fine request = self.rf.get(reverse('cccheckout:payment')) request.session['cccheckout'] = checkout r = payment(request) self.assertEqual(200, r.status_code)
def setUp(self): """Ensure postage form returns something""" # # LINE 1 # line1 = Line(name='Test case line based postage') line1.save() country1 = LineCountry( country='GB', line = line1) country1.save() # add the tiers tier1 = LineTier( minimum=1, maximum=4, price=Decimal('1.00'), line=line1 ) tier1.save() # tier 2 tier2 = LineTier( minimum=5, maximum=8, price=Decimal('2.00'), line=line1 ) tier2.save() # tier 3 tier3 = LineTier( minimum=9, maximum=20, price=Decimal('3.00'), line=line1 ) tier3.save() # # # LINE 2 line2 = Line(name='Swanky case line based postage') line2.save() country2 = LineCountry( country='GB', line=line2) country2.save() # add the tiers tier4 = LineTier( minimum=1, maximum=8, price=Decimal('5.00'), line=line2 ) tier4.save() # tier 2 tier5 = LineTier( minimum=9, maximum=20, price=Decimal('10.00'), line=line2 ) tier5.save() # # # the checkout customer = Customer(delivery_country='GB') customer.save() checkout = Checkout( session_id='test', customer=customer) checkout.save() # now the content types line_ct = ContentType.objects.get_for_model(line1) tier_ct = ContentType.objects.get_for_model(tier1) # set up the selfs self.checkout = checkout self.line1 = line1 self.line2 = line2 self.country1 = country1 self.country2 = country2 self.tier1 = tier1 self.tier2 = tier2 self.tier3 = tier3 self.tier4 = tier4 self.tier5 = tier5 self.line_ct = line_ct self.tier_ct = tier_ct