def test_meal_remove_ingredient_duplicate_ingredient_decrements_quantity(self): meal = Meal("Chicken Dinner") ingredient = Ingredient("Gravy", 2.5) meal.add_ingredient(ingredient) meal.add_ingredient(ingredient) meal.remove_ingredient(ingredient) self.assertEqual(1, meal.Ingredients[0].quantity)
def meals_delete(id): session = request.environ["beaker.session"] meal = Meal(id) if meal.meal["user_id"] != session["user"]: if not "flash" in session: session["flash"] = {} session["flash"]["error"]="You do not have permission to access that resource" redirect("/") else: if not "flash" in session: session["flash"] = {} session["flash"]["success"]="Meal deleted successfully" meal.delete() redirect("/meals")
def test_meal_cost_returns_sum_of_unique_ingredients(self): meal = Meal() rice = Ingredient("Rice",5) chicken = Ingredient("Chicken",5) meal.add_ingredient(rice) meal.add_ingredient(chicken) self.assertEqual(10, meal.cost())
def create_meal(): session = request.environ["beaker.session"] ingredients = [] cost = 0 name = request.forms.get("name") for i in range(10): name = request.forms.get("ingredient[%d][name]" % i) unit = request.forms.get("ingredient[%d][unit]" % i) quantity = request.forms.get("ingredient[%d][quantity]" % i) if quantity != "": ingredient = Ingredient(name,unit) cost += ingredient.price * float(quantity) ingredients.append({ "name":name, "unit":unit, "quantity":quantity, "price":ingredient.price, "cost":ingredient.price * float(quantity) }) if not "flash" in session: session["flash"] = {} session["flash"]["success"]="Meal created successfully" meal = Meal.new(session["user"],ingredients,name) redirect("/meals/"+meal.meal["_id"])
def prepareNonVegMeal(self): meal = Meal() meal.addItem(ChickenBurger()) meal.addItem(Pepsi()) return meal
def test_meal_add_ingredient_is_ingredient_no_error(self): meal = Meal() meal.add_ingredient(Ingredient("Rice",2))
def test_meal_cost_returns_sum_of_duplicate_ingredients(self): meal = Meal() rice = Ingredient("Rice",3) meal.add_ingredient(rice) meal.add_ingredient(rice) self.assertEqual(6, meal.cost())
def test_meal_remove_ingredient_removes_ingredient(self): removeMeal = Meal("Chicken Dinner") ingredient = Ingredient("Gravy", 2.5) removeMeal.add_ingredient(ingredient) removeMeal.remove_ingredient(ingredient) self.assertEqual(0, len(removeMeal.Ingredients))
def parseMeals(resp): data = json.loads(resp.text) return [Meal(meal) for meal in data["recipes"]]
def test_meal_adding_duplicate_ingredient_increments_quantity(self): meal = Meal() ingredient = Ingredient("Gravy", 2.5) meal.add_ingredient(ingredient) meal.add_ingredient(ingredient) self.assertEqual(2, meal.Ingredients[0].quantity)
def test_meal_add_ingredient_adds_ingredient_to_meal(self): addMeal = Meal("Curry") ingredient = Ingredient("Rice", 2.5) addMeal.add_ingredient(ingredient) self.assertEqual(1, len(addMeal.Ingredients))
def meal_index(): session = request.environ["beaker.session"] meals = Meal.all(session["user"]) return {"meals":meals}
def __init__(self): self._meal = Meal()
def prepareVegMeal(self): meal = Meal() meal.addItem(VegBurger()) meal.addItem(Coke()) return meal
def test_meal_adding_duplicate_ingredients_does_not_increase_list_size(self): meal = Meal() ingredient = Ingredient("Gravy", 2.5) meal.add_ingredient(ingredient) meal.add_ingredient(ingredient) self.assertEqual(1, len(meal.Ingredients))
#!/usr/bin/env python import webapp2 from google.appengine.ext import db from google.appengine.api import users from Database.Votes import Votes from datetime import datetime, timedelta from Meal import Meal from Template_Handler import Handler bfast = { "Monday": Meal("Breakfast", "Monday", "aloo parantha, pickle, milk/tea, bread butter"), "Tuesday": Meal("Breakfast", "Tuesday", "suji pancake/besan chilla, milk/tea, bread butter"), "Wednesday": Meal("Breakfast", "Wednesday", "omelette/boiled egg, veg cutlet, mil/tea"), "Thursday": Meal("Breakfast", "Thursday", "methi/palak/onion paratha, pickle, milk/tea, bread butter"), "Friday": Meal("Breakfast", "Friday", "vada/idli, sambhar, milk/tea, bread butter"), "Saturday": Meal("Breakfast", "Saturday", "poori aloo, milk/tea, bread butter"), "Sunday": Meal("Breakfast", "Sunday", "pav bhaji/poha, milk/tea, bread butter"), } eve = {
def loadMeals(self): # read file with open('demo-data.json', 'r') as demoDataFile: demoData = demoDataFile.read() # parse file demoDataJsonObject = json.loads(demoData) print("length: " + str(len(demoDataJsonObject))) meals = [] for mealData in demoDataJsonObject: ingredientsObject = mealData['ingredients'] ingredients = [] for ingredientData in ingredientsObject: newIngredient = Ingredient(ingredientData['name'], ingredientData['quantity'], ingredientData['units'], ingredientData['size']) ingredients.append(newIngredient) methodStepsObject = mealData['method'] methodSteps = [] for methodStepData in methodStepsObject: newMethodStep = MethodStep(methodStepData['stepNumber'], methodStepData['stepDescription']) methodSteps.append(newMethodStep) equipmentObject = mealData['equipment'] equipment = [] for equipmentData in equipmentObject: newEquipment = Equipment(equipmentData['name'], equipmentData['quantityRequired']) equipment.append(newEquipment) dietaryNotesObject = mealData['dietaryNotes'] dietaryNotes = [] for dietaryNotesData in dietaryNotesObject: newdietaryNote = DietaryNote(dietaryNotesData['note']) dietaryNotes.append(newdietaryNote) prepTimeObject = mealData['prepTime'] prepTime = timedelta(hours=prepTimeObject['hours'], minutes=prepTimeObject['minutes'], seconds=prepTimeObject['seconds']) print("prepTime: " + str(prepTime)) cookingTimeObject = mealData['cookingTime'] cookingTime = timedelta(hours=cookingTimeObject['hours'], minutes=cookingTimeObject['minutes'], seconds=cookingTimeObject['seconds']) print("cookingTime: " + str(cookingTime)) newMeal = Meal(mealData['name'], mealData['description'], ingredients, methodSteps, mealData['difficultyRating'], equipment, mealData['priceRating'], dietaryNotes, prepTime, cookingTime) meals.append(newMeal) return meals