コード例 #1
0
def test_discount_apply_correctly_discounts():
    grocery = GroceryFactory(name='Apples',
                             price_per_unit=Decimal('2'),
                             quantity=Decimal('3'))
    basket = BasketFactory(groceries=[grocery])
    discount = DiscountFactory(rule=buy_two_apples_get_one_free)
    discount.apply(basket)
    assert discount.reduction == Decimal('-2')
コード例 #2
0
def test_discount_apply_correctly_discounts_multiple_groceries():
    grocery1 = GroceryFactory(name='Apples',
                              price_per_unit=Decimal('2'),
                              quantity=Decimal('3'))
    grocery2 = GroceryFactory(name='Milk',
                              price_per_unit=Decimal('2'),
                              quantity=Decimal('3'))
    grocery3 = GroceryFactory(name='Red Wine',
                              price_per_unit=Decimal('5'),
                              quantity=Decimal('1'))
    basket = BasketFactory(groceries=[grocery1, grocery2, grocery3])
    discount = DiscountFactory(rule=buy_two_apples_get_one_free)
    discount.apply(basket)
    assert discount.reduction == Decimal('-2')
コード例 #3
0
 def test_5_apples(self):
     basket = BasketFactory(groceries=[
         GroceryFactory(name='Oranges',
                        price_per_unit=Decimal('2'),
                        quantity=Decimal('3')),
         GroceryFactory(name='Cakes',
                        price_per_unit=Decimal('10'),
                        quantity=Decimal('2')),
         GroceryFactory(name='Apples',
                        price_per_unit=Decimal('2.22'),
                        quantity=Decimal('5'))
     ])
     self.discount.apply(basket)
     assert self.discount.reduction == Decimal('-2.22')
コード例 #4
0
 def test_different_unit_type(self):
     basket = BasketFactory(groceries=[
         GroceryFactory(name='Oranges',
                        price_per_unit=Decimal('2'),
                        quantity=Decimal('3')),
         GroceryFactory(name='Cakes',
                        price_per_unit=Decimal('10'),
                        quantity=Decimal('2')),
         GroceryFactory(name='Apples',
                        price_per_unit=Decimal('2.22'),
                        quantity=Decimal('3'),
                        unit_type=UnitType.KILOGRAM)
     ])
     self.discount.apply(basket)
     assert self.discount.reduction == Decimal('0')
コード例 #5
0
 def test_below_hundred(self):
     basket = BasketFactory(groceries=[
         GroceryFactory(name='Oranges',
                        price_per_unit=Decimal('2'),
                        quantity=Decimal('3')),
         GroceryFactory(name='Cakes',
                        price_per_unit=Decimal('5'),
                        quantity=Decimal('3')),
         GroceryFactory(name='Apples',
                        price_per_unit=Decimal('2.22'),
                        quantity=Decimal('5'))
     ])
     assert basket.total_price <= Decimal('100')
     self.discount.apply(basket)
     assert self.discount.reduction == Decimal('0')