Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
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")
Exemplo n.º 3
0
 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())
Exemplo n.º 4
0
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"])
Exemplo n.º 5
0
 def prepareNonVegMeal(self):
     meal = Meal()
     meal.addItem(ChickenBurger())
     meal.addItem(Pepsi())
     return meal
Exemplo n.º 6
0
 def test_meal_add_ingredient_is_ingredient_no_error(self):
     meal = Meal()
     meal.add_ingredient(Ingredient("Rice",2))        
Exemplo n.º 7
0
 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())
Exemplo n.º 8
0
 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)) 
Exemplo n.º 9
0
def parseMeals(resp):
    data = json.loads(resp.text)
    return [Meal(meal) for meal in data["recipes"]]
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
 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))              
Exemplo n.º 12
0
def meal_index():
  session = request.environ["beaker.session"]
  meals = Meal.all(session["user"])
  return {"meals":meals}
Exemplo n.º 13
0
 def __init__(self):
     self._meal = Meal()
Exemplo n.º 14
0
 def prepareVegMeal(self):
     meal = Meal()
     meal.addItem(VegBurger())
     meal.addItem(Coke())
     return meal
Exemplo n.º 15
0
 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))
Exemplo n.º 16
0
#!/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 = {
Exemplo n.º 17
0
    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