def testInitFromList(self):
     ingredients_list = [
         ('tomatoes', Decimal('0.15')),
         ('chicken', Decimal('3.49')),
         ('onions', Decimal('2.00')),
         ('rice', Decimal('0.70')),
     ]
     ingrStorInstance = IngredientsStore(ingredients_list)
     self.assertIngredients(ingrStorInstance)
 def testGetIngredientPrice(self):
     ingredients_list = [
         ('tomatoes', Decimal('0.15')),
         ('chicken', Decimal('3.49')),
         ('onions', Decimal('2.00')),
         ('rice', Decimal('0.70')),
     ]
     ingrStorInstance = IngredientsStore(ingredients_list)
     self.assertEqual(Decimal('0.15').compare(ingrStorInstance.get_ingredient_price('tomatoes')), 0, "")
     self.assertRaises(Exception, ingrStorInstance.get_ingredient_price,'tomatoess')
Ejemplo n.º 3
0
 def testCartAddQty(self):
     ingredients_list = [
         ('tomatoes', Decimal('0.15')),
         ('chicken', Decimal('3.49')),
         ('onions', Decimal('2.00')),
         ('rice', Decimal('0.70')),
     ]
     ingrStoreInst = IngredientsStore(ingredients_list)
     cart = Cart(ingrStoreInst)
     cart.add('tomatoes', 2)
     cart.add('tomatoes', 5)
     self.assertEqual(cart.getQty('tomatoes'), 7, "")
Ejemplo n.º 4
0
 def testNoDiscountCalcLine(self):
     ingredients = [
         ('tomatoes', Decimal('0.15')),
         ('chicken', Decimal('3.49')),
         ('onions', Decimal('2.00')),
         ('rice', Decimal('0.70')),
     ]
     ingrStoreInst = IngredientsStore(ingredients)
     cart = Cart(ingrStoreInst)
     no_discount = NoDiscount('tomatoes')
     dval = no_discount.calc_line_total(cart)
     self.assertEqual(dval, 0, "")
Ejemplo n.º 5
0
 def testGetTotalNoDiscount(self):
     ingredients_list = [
         ('tomatoes', Decimal('0.15')),
         ('chicken', Decimal('3.49')),
         ('onions', Decimal('2.00')),
         ('rice', Decimal('0.70')),
     ]
     ingrStoreInst = IngredientsStore(ingredients_list)
     cart = Cart(ingrStoreInst)
     cart.add('tomatoes', 2)
     cart.add('onions', 4)
     cart.add('chicken',2)
     cart.add('rice',3)
     self.assertEqual(Decimal('17.38').compare(cart.get_total()), 0, "")
Ejemplo n.º 6
0
 def testCartAddInValidIngrOrQty(self):
     ingredients_list = [
         ('tomatoes', Decimal('0.15')),
         ('chicken', Decimal('3.49')),
         ('onions', Decimal('2.00')),
         ('rice', Decimal('0.70')),
     ]
     ingrStoreInst = IngredientsStore(ingredients_list)
     cart = Cart(ingrStoreInst)
     self.assertRaises(ValueError, Cart,ingredients_list)
     self.assertRaises(ValueError, cart.add,'tomatoes', '1')
     self.assertRaises(ValueError, cart.add,'tomatoes', 0)
     self.assertRaises(ValueError, cart.add,'tomatoes', -1)
     self.assertRaises(ValueError, cart.add,'tomatoess', 4)
Ejemplo n.º 7
0
 def testGetTotalWithDiscounts(self):
     ingredients_list = [
         ('tomatoes', Decimal('0.15')),
         ('chicken', Decimal('3.49')),
         ('onions', Decimal('2.00')),
         ('rice', Decimal('0.70')),
     ]
     ingrStoreInst = IngredientsStore(ingredients_list)
     
     cart = Cart(ingrStoreInst)
     cart.add('tomatoes', 7)
     cart.add('onions', 4)
     cart.add('chicken',2)
     cart.add('rice',3)
     
     d1 = BulkDiscount('tomatoes',2,1)
     d2 = BulkDiscount ('onions',1,1)
     d3 = NoDiscount('rice')
     
     self.assertEqual(Decimal('13.83').compare(cart.get_total([d1,d2])),0,"")
Ejemplo n.º 8
0
    def testBulkDiscount(self):
        ingredients = [
            ('tomatoes', Decimal('0.15')),
            ('chicken', Decimal('3.49')),
            ('onions', Decimal('2.00')),
            ('rice', Decimal('0.70')),
        ]
        ingrStoreInst = IngredientsStore(ingredients)
        cart = Cart(ingrStoreInst)
        d1 = BulkDiscount('tomatoes', 2, 1)
        d2 = BulkDiscount('onions', 1, 1)
        d3 = BulkDiscount('rice', 1, 1)
        cart.add('tomatoes', 6)
        cart.add('onions', 8)
        cart.add('chicken', 3)

        d1_val = d1.calc_line_total(cart)
        d2_val = d2.calc_line_total(cart)
        d3_val = d3.calc_line_total(cart)

        self.assertEquals(Decimal('0.30').compare(d1_val), 0, "")
        self.assertEquals(Decimal('8.00').compare(d2_val), 0, "")
        self.assertEqual(Decimal('0.00').compare(d3_val), 0, "")
Ejemplo n.º 9
0
from ingredients.IngredientsStore import IngredientsStore
from decimal import Decimal
import csv
from pickle import INST
from carts.Cart import Cart
from Discount.BulkDiscount import BulkDiscount
from Discount.NoDiscount import NoDiscount

ingredients = [
    ('tomatoes', Decimal('0.15')),
    ('chicken', Decimal('3.49')),
    ('onions', Decimal('2.00')),
    ('rice', Decimal('0.70')),
]

i = IngredientsStore(ingredients)
# v = i.ingredients['tomatoes']
#
# i2 = IngredientsStore.init_from_filepath('../../data/ingredients.csv')
# print i2.ingredients['tomatoes']

#
# try:
#     v2 = i.get_ingredient_price('tomatos')
#     print v2
# except Exception as inst:
#     print type(inst)
#     print inst.args

c = Cart(i)
q = c.getQty('tomatoes')