Esempio n. 1
0
    def test_decimals(self):
        basket = factories.create_basket(empty=True)
        product = factories.create_product(attributes={'weight': '0.3'},
                                           price=D('5.00'))
        basket.add(product)

        scale = Scale(attribute_code='weight')
        self.assertEqual(D('0.3'), scale.weigh_basket(basket))

        basket.add(product)
        self.assertEqual(D('0.6'), scale.weigh_basket(basket))

        basket.add(product)
        self.assertEqual(D('0.9'), scale.weigh_basket(basket))
Esempio n. 2
0
    def test_decimals(self):
        basket = factories.create_basket(empty=True)
        product = factories.create_product(attributes={'weight': '0.3'},
                                           price=D('5.00'))
        basket.add(product)

        scale = Scale(attribute_code='weight')
        self.assertEqual(D('0.3'), scale.weigh_basket(basket))

        basket.add(product)
        self.assertEqual(D('0.6'), scale.weigh_basket(basket))

        basket.add(product)
        self.assertEqual(D('0.9'), scale.weigh_basket(basket))
Esempio n. 3
0
 def calculate(self, basket):
     myround = lambda x: float(int(x)) if int(x) == x else float(int(x) + 1)
     s = Scale()
     weight = s.weigh_basket(basket) / 1000
     total = D(myround(weight)) * self.charge_per_item
     return prices.Price(
         currency=basket.currency,
         excl_tax=total,
         incl_tax=total)
    def test_returns_correct_weight_for_nonempty_basket_with_line_quantities(self):
        basket = factories.create_basket(empty=True)
        products = [
            (factories.create_product(attributes={"weight": "1"}, price=D("5.00")), 3),
            (factories.create_product(attributes={"weight": "2"}, price=D("5.00")), 4),
        ]
        for product, quantity in products:
            basket.add(product, quantity=quantity)

        scale = Scale(attribute_code="weight")
        self.assertEqual(1 * 3 + 2 * 4, scale.weigh_basket(basket))
    def test_returns_correct_weight_for_nonempty_basket(self):
        basket = factories.create_basket(empty=True)
        products = [
            factories.create_product(attributes={"weight": "1"}, price=D("5.00")),
            factories.create_product(attributes={"weight": "2"}, price=D("5.00")),
        ]
        for product in products:
            basket.add(product)

        scale = Scale(attribute_code="weight")
        self.assertEqual(1 + 2, scale.weigh_basket(basket))
Esempio n. 6
0
    def test_returns_correct_weight_for_nonempty_basket(self):
        basket = factories.create_basket(empty=True)
        products = [
            factories.create_product(attributes={'weight': '1'},
                                     price=D('5.00')),
            factories.create_product(attributes={'weight': '2'},
                                     price=D('5.00'))]
        for product in products:
            basket.add(product)

        scale = Scale(attribute_code='weight')
        self.assertEqual(1 + 2, scale.weigh_basket(basket))
Esempio n. 7
0
    def test_returns_correct_weight_for_nonempty_basket_with_line_quantities(
            self):
        basket = factories.create_basket(empty=True)
        products = [(factories.create_product(attributes={'weight': '1'},
                                              price=D('5.00')), 3),
                    (factories.create_product(attributes={'weight': '2'},
                                              price=D('5.00')), 4)]
        for product, quantity in products:
            basket.add(product, quantity=quantity)

        scale = Scale(attribute_code='weight')
        self.assertEqual(1 * 3 + 2 * 4, scale.weigh_basket(basket))
Esempio n. 8
0
    def test_returns_correct_weight_for_nonempty_basket(self):
        basket = factories.create_basket(empty=True)
        products = [
            factories.create_product(attributes={'weight': '1'},
                                     price=D('5.00')),
            factories.create_product(attributes={'weight': '2'},
                                     price=D('5.00'))]
        for product in products:
            basket.add(product)

        scale = Scale(attribute_code='weight')
        self.assertEqual(1 + 2, scale.weigh_basket(basket))
Esempio n. 9
0
    def test_returns_zero_for_empty_basket(self):
        basket = Basket()

        scale = Scale(attribute_code='weight')
        self.assertEqual(0, scale.weigh_basket(basket))
Esempio n. 10
0
    def test_returns_zero_for_empty_basket(self):
        basket = Basket()

        scale = Scale(attribute_code='weight')
        self.assertEqual(0, scale.weigh_basket(basket))