Ejemplo n.º 1
0
def test_us2_1(sys):

    #order21 = Order('preparing', 21)

    burger1 = Burger()
    muffinBun1 = Ingredient("Muffin Bun", sys.getStockBasePrice("Muffin Bun"), 2)
    beefPatty1 = Ingredient("Beef Patty", sys.getStockBasePrice('Beef Patty'), 1)
    burger1.addBuns(muffinBun1)
    burger1.addPatties(beefPatty1)

    burger2 = Burger()
    GBun2 = Ingredient("Gluten Free Bun", sys.getStockBasePrice("Gluten Free Bun"), 4)
    beefPatty2 = Ingredient("Beef Patty", sys.getStockBasePrice('Beef Patty'), 2)
    burger2.addBuns(GBun2)
    burger2.addPatties(beefPatty2)

    print("======= receipt ========")
    order5 = sys.makeOrder([burger1,burger2], [], 'preparing', 21)
    assert order5.totalPrice() == 50
    assert len(order5.mainFoods) == 2
    sys.reduceStock(muffinBun1)
    sys.reduceStock(beefPatty1)
    #sys.checkcheckSpecificInventory(muffinBun1)
    print("======= errors ========")
    error1 = sys.reduceStock(GBun2)
    sys.reduceStock(beefPatty2)

    print(error1)
    print('test us2_1 has finished')
    print('')
Ejemplo n.º 2
0
    def vegify(self):
        for i in range(len(self.ingredients)):
            found = None
            for kind, matches in meat_types.items():
                for match in matches:
                    if match in self.ingredients[i].name:
                        found = kind
                        break

            if found is None:
                continue

            old = self.ingredients[i].name
            new = random.choice(meat_to_veg[found])
            if self.ingredients[i].measure == 'item':
                self.ingredients[i].quantity /= 2.0
                self.ingredients[i].measure = 'cup'
            descs = ' '.join(self.ingredients[i].descriptors)
            descs = descs + ' ' + ' '.join(self.ingredients[i].preparations)
            descs.strip()
            new_ing = Ingredient('{} {} {} {}'.format(
                self.ingredients[i].quantity, self.ingredients[i].measure,
                descs, new))
            new_ing = Ingredient('{} {} {}'.format(
                self.ingredients[i].quantity, self.ingredients[i].measure,
                new))
            self.ingredients[i] = new_ing

            yield old, new
Ejemplo n.º 3
0
    def get(self):
        recname = "Fried Chicken"
        rec = Recipe(id=recname,
                     name=recname,
                     totalprice=8.50,
                     totaltime=0.5,
                     healthrating=2,
                     notes="Don't cook on high heat!")
        rec_key = rec.put()

        ingred = Ingredient(parent=rec.key,
                            id="Chicken",
                            name="Chicken",
                            price=2.50)
        ingred.put()

        ingred1 = Ingredient(parent=rec.key,
                             id="Flour",
                             name="Flour",
                             price=0.10)
        ingred1.put()

        ##key = ndb.Key("Recipe", "Fried Chicken")
        ##key.delete()

        self.response.write("Data filled!")
Ejemplo n.º 4
0
def get_ingredient_by_name(name):
    if name in ("Bun", "Sandwich"):
        return Ingredient(name, 2, 300, 1)
    elif name in ('Chicken Patty', 'Vegetarian Patty', 'Beef Patty'):
        return Ingredient(name, 5, 600, 1)
    else:
        return Ingredient(name, 0.5, 50, 1)
Ejemplo n.º 5
0
def test_MKOrder_alt3(sys):
    burger1 = Burger()
    whiteBun1 = Ingredient('White Bun', sys.getStockBasePrice('White Bun'), 4)
    beefPatty1 = Ingredient("Beef Patty", sys.getStockBasePrice('Beef Patty'), 2)
    lettuce1 = Ingredient("Lettuce", sys.getStockBasePrice("Lettuce"), 3)

    error1 = burger1.addBuns(whiteBun1)
    error2 = burger1.addPatties(beefPatty1)
    burger1.addIngredient(lettuce1)

    assert error1 == None
    assert error2 == None
    assert burger1.calculatePrice() == 31

    wrap1 = Wrap()
    wholemealWrap1 = Ingredient('Wholemeal Wrap', sys.getStockBasePrice('Wholemeal Wrap'), 1)
    chickenPatty2 = Ingredient("Chicken Patty", sys.getStockBasePrice('Chicken Patty'), 2)

    error3 = wrap1.addWrap(wholemealWrap1)
    error4 = wrap1.addPatties(chickenPatty2)

    assert error3 == None
    assert error4 == None
    assert wrap1.calculatePrice() == 11

    # order.addMain(burger1)
    # order.addMain(wrap1)
    print("======= receipt ========")
    order2 = sys.makeOrder([burger1, wrap1], [], "preparing", 4)
    print('========================')
    assert order2.totalPrice() == 42
    print("test 4 passed")
Ejemplo n.º 6
0
 def test_dish_expired(self):
     dish = Dish('dummy')
     now = datetime.datetime.now()
     ingredient1 = Ingredient('dummy', now, now)
     ingredient2 = Ingredient('dummy2', now, now)
     dish.add_ingredient(ingredient1)
     dish.add_ingredient(ingredient2)
     time.sleep(10)
     can_prepare = dish.can_prepare(datetime.datetime.now())
     self.assertFalse(can_prepare)
Ejemplo n.º 7
0
    def meatify(self):
        num_items_replaced = 0
        max_items_replaced = round((3 + (len(self.ingredients) * 0.2)) / 2)

        for i in range(len(self.ingredients)):
            if num_items_replaced > max_items_replaced:
                break

            found = None
            for kind, matches in veg_types.items():
                for match in matches:
                    if match in self.ingredients[i].name:
                        found = kind
                        break

            if found is None:
                continue

            old = self.ingredients[i].name
            new = random.choice(veg_to_meat[found])
            if self.ingredients[i].measure == 'item':
                self.ingredients[i].quantity /= 2.0
                self.ingredients[i].measure = 'cup'
            descs = ' '.join(self.ingredients[i].descriptors)
            descs = descs + ' ' + ' '.join(self.ingredients[i].preparations)
            descs.strip()
            new_ing = Ingredient('{} {} {} {}'.format(
                self.ingredients[i].quantity, self.ingredients[i].measure,
                descs, new))
            self.ingredients[i] = new_ing

            num_items_replaced += 1
            yield old, new

        if num_items_replaced == 0:
            # try to guess new meat
            ing_str, prep_str, comb_str = random.choice(meat_additions)

            # add ingredient
            new_ingredient = Ingredient(ing_str)
            self.ingredients.append(new_ingredient)

            # add step to cook ingredient
            cook_step = Step(prep_str, self.ingredients)
            self.steps.insert(0, cook_step)

            # add step to combine ingredient
            combine_step = Step(comb_str, self.ingredients)
            self.steps.append(combine_step)

            yield None, new_ingredient
Ejemplo n.º 8
0
def test_MKOrder_alt1(sys):
    order = Order('parparing',2)
    wrap = Wrap()
    wholemealWrap1 = Ingredient('Wholemeal Wrap',sys.getStockBasePrice('Wholemeal Wrap'),3)
    beefPatty1 = Ingredient("Beef Patty", sys.getStockBasePrice('Beef Patty'), 1)

    error = wrap.addWrap(wholemealWrap1)
    wrap.addPatties(beefPatty1)
    order.addMain(wrap)
    #assert len(sys.orders) == 1
    print("=======error=======")
    print(error)
    print("====================")
    print('test 2 passed')
Ejemplo n.º 9
0
 def setUp(self):
     self.ingredient_1 = Ingredient('green pepper',
                                    IngredientType.VEGETABLE)
     self.ingredient_2 = Ingredient('green apple', IngredientType.FRUIT)
     self.ingredient_3 = Ingredient('peanuts', IngredientType.NUTS)
     self.ingredient_4 = Ingredient('bread', IngredientType.GRAIN)
     self.ingredient_5 = Ingredient('pinto beans', IngredientType.BEANS)
     self.ingredient_6 = Ingredient('steak', IngredientType.MEAT)
     self.ingredient_7 = Ingredient('salmon', IngredientType.FISH)
     self.ingredient_8 = Ingredient('milk', IngredientType.DAIRY)
     self.ingredient_9 = Ingredient('oregano', IngredientType.SEASONING)
Ejemplo n.º 10
0
def test_us2_1_3(sys):

    frenchFriess213 = Ingredient("French Fries", sys.getStockBasePrice("Small French Fries"), 2)
    fanta213 = Ingredient("Fanta", sys.getStockBasePrice("Fanta"), 1)
    chickenNuggets213 = Ingredient("Small Chicken Nuggets", sys.getStockBasePrice("Small Chicken Nuggets"), 1)


    side213 = Extra()
    side213.addExtra(frenchFriess213)
    side213.addExtra(fanta213)
    side213.addExtra(chickenNuggets213)

    assert len(side213.ingredient) == 3
    order213 = sys.makeOrder([], [side213], 'preparing', 213)
    print("test us2_1_3 has finished \n")
Ejemplo n.º 11
0
    def hydrate(self, options):
        self.name = options['name']

        if 'ingredients' in options.keys():
            for ingredient_data in options['ingredients']:
                ingredient = Ingredient(ingredient_data)
                self.ingredients.append(ingredient)
Ejemplo n.º 12
0
 def make_ingredient_no_modifier():
     ingred = "All-Purpose Flour"
     cups = 1
     ounces = 4.25
     grams = 120
     return Ingredient(ingred, cups,
                       ounces, grams)
Ejemplo n.º 13
0
	def add_ingredient(self, name, price, calories, decrement_quantity=1, stock_quantity=0):
		if self.search_ingredient(name) != None:
			return None
		ingredient = Ingredient(name, price, calories, decrement_quantity)
		self._ingredients.append(ingredient)
		self._inventory.stock.update({ingredient : stock_quantity})
		return ingredient
Ejemplo n.º 14
0
def test_MKOrder_alt2(sys):
    order = Order('parparing',3)
    burger1 = Burger()
    whiteBun1 = Ingredient('White Bun',sys.getStockBasePrice('White Bun'),5)
    beefPatty1 = Ingredient("Beef Patty", sys.getStockBasePrice('Beef Patty'), 8)
    lettuce1 = Ingredient("Lettuce", sys.getStockBasePrice('Lettuce'),3)

    error1 = burger1.addBuns(whiteBun1)
    error2 = burger1.addPatties(beefPatty1)
    burger1.addIngredient(lettuce1)

    print("=======error=======")
    print(error1)
    print(error2)
    print('===================')
    print('test 3 passed')
Ejemplo n.º 15
0
    def load_conf(self):
        """
        parses json files and populate self.dishes
        :return:
        """
        recipes_json, ingredients_json = {}, {}
        # dict of title  of ingredient and its object
        dict_ingredients = {}

        with open(self.recipes_file) as frecipes:
            recipes_json = json.load(frecipes)
        with open(self.ingredients_file) as fingredients:
            ingredients_json = json.load(fingredients)

        for x in ingredients_json["ingredients"]:
            title = x["title"]
            # parse use by
            use_by = x["use-by"]
            fields = [int(d) for d in use_by.split("-")]
            assert len(fields) == 3
            use_by_date = datetime.datetime(year=fields[0], month=fields[1], day=fields[2])
            # parse best before now
            best_before = x["best-before"]
            fields = [int(d) for d in best_before.split("-")]
            assert len(fields) == 3
            best_before_date = datetime.datetime(year=fields[0], month=fields[1], day=fields[2])
            dict_ingredients[title] = Ingredient(title, best_before_date, use_by_date)

        for recipe in recipes_json["recipes"]:
            title = recipe["title"]
            dish = Dish(title)
            for ingre in recipe["ingredients"]:
                dish.add_ingredient(dict_ingredients[ingre])

            self.dishes.append(dish)
Ejemplo n.º 16
0
def get_ingredient(path=None, name=None):

    if path is None and name is None:
        raise ValueError('The arguments are invalid')

    if name is None:
        try:
            name = path.split('/')[2]
        except:
            raise Exception('Path is not good for ingredient: ', path)

    ingredient = Ingredient(name=name)
    if not does_ingredient_exist(ingredient):
        return None

    filename_features = 'features'
    filename_quantity_names = 'quantity_names'
    filename_complements = 'complements'

    f = open(os.path.join(path, filename_features), 'r')
    ingredient.name = [l.replace('\n', '') for l in f][0]
    f.close()

    f = open(os.path.join(path, filename_quantity_names), 'r')
    ingredient.quantity_names = [l.replace('\n', '') for l in f]
    f.close()

    f = open(os.path.join(path, filename_complements), 'r')
    ingredient.complements = [l.replace('\n', '') for l in f]
    f.close()

    return ingredient
Ejemplo n.º 17
0
 def add_ingredient(self, name, calories, carbs, proteins, fats):
     new_ingredient = Ingredient(name.get(), calories.get(), carbs.get(),
                                 proteins.get(), fats.get())
     self.ingredient_list.add_ingredient(new_ingredient)
     # Refresh the frame
     self.frames["ings"] = self.ingredients_win(self.window)
     self.goto_page("ings")
Ejemplo n.º 18
0
def fileToObject(route):
    try:
        lista = open(route).readlines()
    except UnicodeDecodeError:
        return None
    pedidos = [x.replace('\n', '') for x in lista]
    print(pedidos)
    i = 0
    listaOrdenes = []
    while(i < len(pedidos)):
        if pedidos[i] == 'COMIENZO_PEDIDO':
            
            j = i+2
            # A dos líneas del comienzo se encuentran las pizzas
            listaPizzas = []
            while(pedidos[j] != 'FIN_PEDIDO'):
                orden = pedidos[j].split(";")
                # Separa la pizza y extras en una lista
                pizza = Pizza([10, 15, 20], orden[0])
                orden.remove(orden[0])
                for extra in orden:
                    # Agrega cada ingrediente a la pizza
                    ingrediente = Ingredient([1.5, 1.75, 2], extra)
                    pizza = Decorator(pizza, ingrediente)
                listaPizzas.append(pizza)
                j = j+1
            order = Order(pedidos[i+1].split(";")[1], listaPizzas)
            listaOrdenes.append(order)
            i = j+1
        else:
            return None
    return listaOrdenes
Ejemplo n.º 19
0
 def addIngredients(self):
     print("Add each ingredient to the pantry by typing the name and pressing enter.\n"
           "If finished type in '---' and enter")
     ingredName = ""
     while ingredName != "---":
         ingredName = input()
         if ingredName != "---":
             self.ingredients[ingredName] = Ingredient(ingredName)
Ejemplo n.º 20
0
def test_us2_2(sys):


    burger3 = Burger()
    whiteBun1 = Ingredient("White Bun", sys.getStockBasePrice("White Bun"), 2)
    beefPatty3 = Ingredient("Beef Patty", sys.getStockBasePrice('Beef Patty'), 1)
    sys.reduceStock(whiteBun1)
    sys.reduceStock(beefPatty3)

    burger3.addBuns(whiteBun1)
    burger3.addPatties(beefPatty3)
    print("========= receipt ===========")
    sys.makeOrder([burger3], [], 'preparing', 2)
    print('==============================')
    #assert order22.extraFoods == None

    print('test us2_2 has finished')
Ejemplo n.º 21
0
 def make_ingredient_one_modifier():
     ingred = "Salt"
     cups = 0.06
     ounces = ''
     grams = 16
     modifiers = ["Morton's Kosher"]
     return Ingredient(ingred, cups,
                       ounces, grams, modifiers)
Ejemplo n.º 22
0
 def make_ingredient_two_modifiers():
     ingred = "Apples"
     cups = "1.00"
     ounces = "3.00"
     grams = 85
     modifiers = ["dried", "diced"]
     return Ingredient(ingred, cups,
                       ounces, grams, modifiers)
Ejemplo n.º 23
0
 def addIngredient(self,name,quantity):
     ''' Used to add an ingredient into the coffee_machine.
         Parameters:
             name of type str
             quantity of type int
     '''
     i = Ingredient(name,quantity)
     self.ingredients[name]=i
     return True
Ejemplo n.º 24
0
def ingredients_from_file(filename):
    ingredients = []
    with open(filename) as file:
        for line in file:
            divided_line = line.split(" ", 2)
            ounces = float(divided_line[0])
            name = divided_line[2]
            ingredients.append(Ingredient(ounces, name))

    return ingredients
Ejemplo n.º 25
0
def test_view_menu(gourmet_fixture):
    print("Test viewing menu options")

    assert len(gourmet_fixture.inventory.find_in_stock()) == 31
    gourmet_fixture.inventory.update_stock(Ingredient('Onion', 2, 300, 1), 0)
    assert len(gourmet_fixture.inventory.find_in_stock()) == 31

    in_stock = gourmet_fixture.inventory.find_in_stock()
    for item in in_stock:
        assert item.name != None and item.price != None and item.calories != None
Ejemplo n.º 26
0
    def test_add_food(self):
        old_size = len(self.list.food)
        banana_split = Food(
            "banana_split"
        )  # So that the food that we compare have at least two ingredients
        banana_ing = Ingredient("banana", 75, 60, 0, 5)
        banana_split.add_ingredient(banana_ing, 100, 100)
        cream_ing = Ingredient("cream", 190, 100, 10, 50)
        banana_split.add_ingredient(cream_ing, 25, 45, True)
        sandwich = Food("sandwich")
        bread_ing = Ingredient("bread", 100, 80, 0, 20)
        ham_ing = Ingredient("ham", 60, 5, 30, 10)
        sandwich.add_ingredient(bread_ing, 100, 100)
        sandwich.add_ingredient(ham_ing, 100, 100)

        self.list.add_food(banana_split)  # We add the food to the list
        self.list.add_food(sandwich)  # We add the food to the list
        self.assertEqual(old_size + 2, len(
            self.list.food))  # We check if the list is bigger by one element
Ejemplo n.º 27
0
def test_us2_3(sys):

    frenchFriess1 = Ingredient("French Fries", sys.getStockBasePrice("Small French Fries"), 2)
    frenchFriesl1 = Ingredient("French Fries", sys.getStockBasePrice("Large French Fries"), 2)

    cokel = Ingredient("Coca Cola", sys.getStockBasePrice("Bottle Coca Cola"), 2)
    cokes = Ingredient("Coca Cola", sys.getStockBasePrice("Can Coca Cola"), 3)

    side23 = Extra()
    side23.addExtra(frenchFriess1)
    side23.addExtra(frenchFriesl1)
    side23.addExtra(cokel)
    side23.addExtra(cokes)
    assert len(side23.ingredient) == 4
    print("========= receipt ===========")
    order23 = sys.makeOrder([], [side23], 'preparing', 23)
    print("=============================")
    print('')
    print("test us2_3 finishes \n")
Ejemplo n.º 28
0
    def less_healthy(self):
        num_items_replaced = 0
        for i in range(len(self.ingredients)):
            found = None
            for kind, matches in less_healthy_conversions.items():
                for match in matches:
                    if match in self.ingredients[i].name:
                        found = kind
                        break

            if found is None:
                continue

            old = self.ingredients[i].name
            if self.ingredients[i].measure == 'item':
                self.ingredients[i].quantity /= 2.0
                self.ingredients[i].measure = 'cup'
            descs = ' '.join(self.ingredients[i].descriptors)
            descs = descs + ' ' + ' '.join(self.ingredients[i].preparations)
            descs.strip()
            new_ing = Ingredient('{} {} {} {}'.format(
                self.ingredients[i].quantity, self.ingredients[i].measure,
                descs, found))
            self.ingredients[i] = new_ing

            new = self.ingredients[i].name

            num_items_replaced += 1
            yield old, new

        if num_items_replaced == 0:
            # guess new ingredient
            ing_str, stp_str = random.choice(less_healthy_conversions)

            # add new ingredient
            new_ing = Ingredient(ing_str)
            self.ingredients.append(new_ing)

            # add new step
            new_stp = Step(stp_str, self.ingredients)
            self.steps.append(new_stp)

            yield None, new_ing.name
Ejemplo n.º 29
0
 def __init__(self, ingredient: Union[Ingredient, str], quantity: complex,
              measurement: Optional[str]=None,
              condition: Optional[str]=None):
     self.ingredient: Ingredient
     if isinstance(ingredient, Ingredient):
         self.ingredient = ingredient
     else:
         self.ingredient = Ingredient(ingredient)
     self.quantity: complex = quantity
     self.measurement: Optional[str] = measurement
     self.condition: Optional[str] = condition
Ejemplo n.º 30
0
def test_us2_1_2(sys):

    burger12 = Burger()
    sweetbun12 = Ingredient("Sweet Bun", sys.getStockBasePrice("Sweet Bun"), 2)
    chickpatty12 = Ingredient("Chicken Patty", sys.getStockBasePrice('Chicken Patty'), 1)
    error12 = burger12.addBuns(sweetbun1)
    error12 = burger12.addPatties(chickpatty1)

    burger12 = Burger()
    sweetbun12 = Ingredient("Sweet Bun", sys.getStockBasePrice("Sweet Bun"), 2)
    chickpatty12 = Ingredient("Chicken Patty", sys.getStockBasePrice('Chicken Patty'), 1)
    error13 = burger12.addBuns(sweetbun12)
    error14 = burger12.addPatties(chickpatty12)

    error1 =  sys.reduceStock()
    assert error13 == None
    assert error12 == None
    assert error1 == 'Sorry it is out stock'
    assert error14 == None

    print('test us2_1_2 has finished')