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_payment_200(self):
     """If a basket is not empty then the checkout reponds with 200"""
     request = self.rf.get(reverse('cccheckout:payment'))
     request.session['cccheckout'] = self.checkout
     # add a customer
     self.checkout.customer = Customer()
     self.checkout.customer.save()
     # add postage
     postage = Line(name='test')
     postage.save()
     tier = LineTier(minimum=1,
             maximum=2,
             price=Decimal('2.00'),
             line=postage)
     tier.save()
     country = LineCountry(country='GB', line=postage)
     country.save()
     self.checkout.postage = postage
     self.checkout.postage_tier = tier
     request.session.save()
     response = payment(request)
     self.assertEqual(200, response.status_code)
 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