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')
 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")
 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)
Esempio n. 4
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, "")
 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, "")
Esempio n. 6
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, "")
Esempio n. 7
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)
Esempio n. 8
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,"")
    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, "")
 def testInitFromCSV(self):
     ingrStorInstance = IngredientsStore.init_from_filepath('../../data/ingredients.csv')
     self.assertIngredients(ingrStorInstance)
Esempio n. 11
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')
 def testInitFromCSV(self):
     ingrStorInstance = IngredientsStore.init_from_filepath("../../data/ingredients.csv")
     self.assertIngredients(ingrStorInstance)