Ejemplo n.º 1
0
    def test_shippingquery(self):
        # Shipping method
        s1 = self.make_test_shippingmethod(order_cost=Decimal('2.00'))
        s1.save()

        valid = ShippingMethod.get_valid_methods(order_methods=True)
        method = valid[0]
        self.assertEqual(method, s1)

        self.assertEqual(method.get_cost(), Decimal('2.00'))
Ejemplo n.º 2
0
 def make_test_shippingmethod(self, order_cost=Decimal('10.00')):
     """ Make a shipping method for testing. """
     s = ShippingMethod()
     s.order_cost = order_cost
     return s
Ejemplo n.º 3
0
    def test_countryquery(self):
        country1 = Country.objects.all()[0]
        country2 = Country.objects.all()[1]

        # Shipping method with country1
        s1 = self.make_test_shippingmethod(order_cost=Decimal('2.00'))
        s1.name = 'cheapest'
        s1.save()

        s1.countries.add(country1)

        # Shipping method with country1 and country2
        s2 = self.make_test_shippingmethod(order_cost=Decimal('3.00'))
        s2.name = 'less cheap'
        s2.save()

        s2.countries.add(country1)
        s2.countries.add(country2)

        # Shipping method without country
        s3 = self.make_test_shippingmethod(order_cost=Decimal('4.00'))
        s3.name = 'expensive'
        s3.save()

        # Check country1-s1
        valid = ShippingMethod.get_valid_methods(order_methods=True,
                                                 country=country1)
        valid = list(valid)
        self.assertEquals(len(valid), 3)
        self.assertIn(s1, valid)
        self.assertIn(s2, valid)
        self.assertIn(s3, valid)

        # Check the cheapest
        cheapest = ShippingMethod.get_cheapest(order_methods=True,
                                               country=country1)
        self.assertEqual(s1, cheapest)
        self.assertEqual(cheapest.get_cost(), Decimal('2.00'))

        # Check country2-s2
        valid = ShippingMethod.get_valid_methods(order_methods=True,
                                                 country=country2)
        valid = list(valid)
        self.assertEquals(len(valid), 2)
        self.assertIn(s2, valid)
        self.assertIn(s3, valid)

        # Check the cheapest
        cheapest = ShippingMethod.get_cheapest(order_methods=True,
                                               country=country2)
        self.assertEqual(s2, cheapest)
        self.assertEqual(cheapest.get_cost(), Decimal('3.00'))

        # Check s3, no country
        valid = ShippingMethod.get_valid_methods(order_methods=True)

        method = valid[0]
        self.assertEqual(method, s3)

        cheapest = ShippingMethod.get_cheapest(order_methods=True)
        self.assertEqual(s3, cheapest)
        self.assertEqual(cheapest.get_cost(), Decimal('4.00'))