Esempio n. 1
0
    def setUp(self):
        self.stuff = FoodStuff(name='some stuff 3')
        self.stuff.save()

        recipe = Recipe(name='some recipe 3')
        recipe.save()

        ingredient = RecipeIngredient(
            stuff  = self.stuff,
            recipe = recipe,
            count  = 1.5
        )
        ingredient.save()

        self.product = Product(
            name   = 'some product 3',
            recipe = recipe,
            markup = 1.5
        )
        self.product.save()

        provider = FoodProvider(name='some provider')
        provider.save()

        purchase = Purchase(
            provider   = provider,
            stuff      = self.stuff,
            cost       = 200,
            unit_count = 10,
            unit_size  = 1,
        )
        purchase.save()

        self.offer = SaleOffer(product=self.product)
        self.offer.save()
Esempio n. 2
0
    def setUp(self):
        stuff = FoodStuff(name='some stuff 2')
        stuff.save()

        recipe = Recipe(name='some recipe 2')
        recipe.save()

        ingredient = RecipeIngredient(stuff=stuff, recipe=recipe, count=1.5)
        ingredient.save()

        self.product = Product(name='some product 2', recipe=recipe)
        self.product.save()
Esempio n. 3
0
    def test_str(self):
        stuff = FoodStuff(name='some stuff')
        stuff.save()

        recipe = Recipe(name='some recipe')
        recipe.save()

        ingredient = RecipeIngredient(
            stuff  = stuff,
            recipe = recipe,
            count  = 1.5
        )
        ingredient.save()

        self.assertEqual('some stuff x 1.5', str(ingredient))
Esempio n. 4
0
 def post(self):
     data = json.loads(request.data)
     user = g.user
     recipe = Recipe()
     recipe.name = data["name"]
     for ingredient in data["ingredients"]:
         irec = RecipeIngredient()
         irec.name = ingredient
         recipe.ingredients.append(irec)
     recipe.instructions = data["instructions"]
     recipe.author = data["author"]
     user.recipes.append(recipe)
     #db.session.add(recipe)
     try:
         db.session.commit()
     except Exception,e:
         print "error adding new record"
         db.session.rollback()
Esempio n. 5
0
class CalculationTests(TestCase):
    def setUp(self):
        self.stuff = FoodStuff(name='some stuff 4')
        self.stuff.save()

        recipe = Recipe(name='some recipe 4')
        recipe.save()

        self.ingredient = RecipeIngredient(
            stuff  = self.stuff,
            recipe = recipe,
            count  = 1.5
        )
        self.ingredient.save()

        self.product = Product(name='some product 4', recipe=recipe)
        self.product.save()

        self.offer = SaleOffer(product=self.product)
        self.offer.save()

    def test_create_with_only_material_count(self):
        check = Calculation.create(self.offer, self.ingredient)
        self.assertEqual(1.5, check.material_count)
        self.assertFalse(check.feasible)
        self.assertEqual(0, check.monetary_count)

    def test_create(self):
        provider = FoodProvider(name='some provider')
        provider.save()

        purchase = Purchase(
            provider   = provider,
            stuff      = self.stuff,
            cost       = 200,
            unit_count = 10,
            unit_size  = 1,
        )
        purchase.save()

        check = Calculation.create(self.offer, self.ingredient)
        self.assertEqual(1.5, check.material_count)
        self.assertTrue(check.feasible)
        self.assertEqual(30, check.monetary_count)
Esempio n. 6
0
 def put(self, r_id):
     data = json.loads(request.data)
     recipe = db.session.query(Recipe).filter_by(id=r_id).first()
     recipe.name = data["name"]
     #recipe.ingredients = data["ingredients"]
     for rec in recipe.ingredients:
         db.session.delete(rec)
     for ingredient in data["ingredients"]:
         irec = RecipeIngredient()
         irec.name = ingredient
         recipe.ingredients.append(irec)
     recipe.instructions = data["instructions"]
     recipe.author = data["author"]
     #maybe don't do this
     db.session.add(recipe)
     try:
         db.session.commit()
     except Exception,e:
         print "error adding new record"
         db.session.rollback()
Esempio n. 7
0
    def setUp(self):
        self.stuff = FoodStuff(name='some stuff 4')
        self.stuff.save()

        recipe = Recipe(name='some recipe 4')
        recipe.save()

        self.ingredient = RecipeIngredient(
            stuff  = self.stuff,
            recipe = recipe,
            count  = 1.5
        )
        self.ingredient.save()

        self.product = Product(name='some product 4', recipe=recipe)
        self.product.save()

        self.offer = SaleOffer(product=self.product)
        self.offer.save()
Esempio n. 8
0
def generator():
    # Clear up database first
    User.query.delete()
    Setting.query.delete()
    Category.query.delete()
    Tag.query.delete()
    Recipe.query.delete()
    Ingredient.query.delete()
    RecipeIngredient.query.delete()
    Meal.query.delete()

    jurian = User(name='jurian', email='*****@*****.**', password=generate_password_hash('password'))

    grocery_day             = Setting('grocery_day', 'sat')
    default_servings        = Setting('default_servings', '2')
    allow_user_registration = Setting('allow_user_registration', 'true')
    default_language        = Setting('default_language', 'nl')

    starter   = Category('Starter')
    main      = Category('Main')
    side_dish = Category('Side dish')
    desert    = Category('Desert')
    breakfast = Category('Breakfast')
    lunch     = Category('Lunch')

    vegetarian = Tag('Vegetarian')
    indian     = Tag('Indian')
    italian    = Tag('Italian')
    moroccan   = Tag('Moroccan')
    lactose    = Tag('Lactose free')

    recipe1 = Recipe(
        name='Fish curry', servings=4, prep_time=15, cook_time=30,
        category=main, intro='A delicious but simple curry',
        description="""Wash and cook the rice.\n\nStart with oil and fry the
            paste for 5 minutes. Add the fish and coconut milk. Poach fish until
            tender. Finalize with coriander.""")

    rice = Ingredient('Rice', 'g')
    paste = Ingredient('Curry paste', 'ts')
    fish = Ingredient('White fish', 'g')
    coconut = Ingredient('Coconut milk', 'ml')
    coriander = Ingredient('Coriander', 'g')

    recipe1.ingredients.append(RecipeIngredient(rice, 320))
    recipe1.ingredients.append(RecipeIngredient(paste, 3, 0.75))
    recipe1.ingredients.append(RecipeIngredient(fish, 400))
    recipe1.ingredients.append(RecipeIngredient(coconut, 150))
    recipe1.ingredients.append(RecipeIngredient(coriander, 20))

    recipe2 = Recipe(name='Pasta something', servings=4, prep_time=20, cook_time=15, category=main,
        intro='Quick pasta for a working day meal',
        description="Start with bla bla and then\nDo some more steps\n\nEnjoy!")

    recipe3 = Recipe(name='Weekend tajine', servings=4, prep_time=30, cook_time=60, category=main,
        intro='Something truly the waiting for during a weekend',
        description="Start with bla bla and then\nDo some more steps\n\nEnjoy!")

    recipe4 = Recipe(name='Fish curry', servings=4, prep_time=15, cook_time=30, category=main,
        intro='A delicious but simple curry',
        description="Start with bla bla and then\nDo some more steps\n\nEnjoy!")

    recipe5 = Recipe(name='Pasta something', servings=4, prep_time=20, cook_time=15, category=main,
        intro='Quick pasta for a working day meal',
        description="Start with bla bla and then\nDo some more steps\n\nEnjoy!")

    recipe6 = Recipe(name='Weekend tajine', servings=4, prep_time=30, cook_time=60, category=main,
        intro='Something truly the waiting for during a weekend',
        description="Start with bla bla and then\nDo some more steps\n\nEnjoy!")

    recipe7 = Recipe(name='Fish curry', servings=4, prep_time=15, cook_time=30, category=main,
        intro='A delicious but simple curry',
        description="Start with bla bla and then\nDo some more steps\n\nEnjoy!")

    recipe8 = Recipe(name='Pasta something', servings=4, prep_time=20, cook_time=15, category=main,
        intro='Quick pasta for a working day meal',
        description="Start with bla bla and then\nDo some more steps\n\nEnjoy!")

    recipe9 = Recipe(name='Weekend tajine', servings=4, prep_time=30, cook_time=60, category=main,
        intro='Something truly the waiting for during a weekend',
        description="Start with bla bla and then\nDo some more steps\n\nEnjoy!")

    recipe10 = Recipe(name='Fish curry', servings=4, prep_time=15, cook_time=30, category=main,
        intro='A delicious but simple curry',
        description="Start with bla bla and then\nDo some more steps\n\nEnjoy!")

    recipe11 = Recipe(name='Zaalouk', servings=4, prep_time=15, cook_time=0, category=side_dish,
        intro='Moroccan Vegetable side dish',
        description="Cut the eggplants to cubes, if you like you can peel the eggplant not completely you leave some skin on them for the dark look.\n\nCut the tomato to fine slices")

    recipe12 = Recipe(name='A very long title with multiple words', servings=4, prep_time=30, cook_time=60, category=main,
        intro='Something truly the waiting for during a weekend',
        description="Start with bla bla and then\nDo some more steps\n\nEnjoy!")

    session = db.session
    session.add(jurian)
    session.add(grocery_day)
    session.add(default_servings)
    session.add(allow_user_registration)
    session.add(default_language)
    session.add(starter)
    session.add(main)
    session.add(side_dish)
    session.add(desert)
    session.add(breakfast)
    session.add(lunch)
    session.add(vegetarian)
    session.add(indian)
    session.add(italian)
    session.add(moroccan)
    session.add(lactose)
    session.add(recipe1)
    session.add(recipe2)
    session.add(recipe3)
    session.add(recipe4)
    session.add(recipe5)
    session.add(recipe6)
    session.add(recipe7)
    session.add(recipe8)
    session.add(recipe9)
    session.add(recipe10)
    session.add(recipe11)
    session.add(recipe12)

    session.commit()

    recipe1.tags.append(indian)
    recipe1.tags.append(lactose)

    recipe11.tags.append(moroccan)

    session.commit()

    today = Meal(date.today(), recipe1)
    tomorrow = Meal(date.today() + timedelta(days=1), recipe2)
    tomorrow1 = Meal(date.today() + timedelta(days=1), name='Green salad', note='Use rocket salad from yesterday')
    tomorrow2 = Meal(date.today() + timedelta(days=2),
                     name='Rösti with lamb and red cabbage',
                     note='Rösti from freezer, check lamb first!')
    tomorrow3 = Meal(date.today() + timedelta(days=3), recipe3, servings=4)
    tomorrow4 = Meal(date.today() + timedelta(days=4), name='Chicken biryani')
    tomorrow5 = Meal(date.today() + timedelta(days=5), recipe9)
    tomorrow6 = Meal(date.today() + timedelta(days=5), recipe11)

    session.add(today)
    session.add(tomorrow)
    session.add(tomorrow1)
    session.add(tomorrow2)
    session.add(tomorrow3)
    session.add(tomorrow4)
    session.add(tomorrow5)
    session.add(tomorrow6)

    session.commit()

    return redirect(url_for('home'))