def test_delete_recipe(self): recipe = Recipe.from_json(RecipeTest.RECIPE) recipe.recipe_id = self.recipe_store.add_recipe(recipe) self.assertListEqual([recipe], self.recipe_store.list_recipes()) removed_recipe = self.recipe_store.remove_recipe(recipe.recipe_id) self.assertListEqual([], self.recipe_store.list_recipes())
def test_json_to_recipe(self): recipe = Recipe.from_json(RecipeTest.RECIPE) self.assertEquals(recipe.author, "Author") self.assertEquals(recipe.description, "Description") self.assertEquals(recipe.time, 30) self.assertEquals(recipe.default_portions, 4) self.assertEquals(recipe.ingredients, []) self.assertEquals(recipe.steps, []) self.assertEquals(recipe.tags, [])
def test_add_multiple_recipes(self): recipe1 = Recipe("description1") recipe2 = Recipe("description2") recipe3 = Recipe("description3") recipe1.recipe_id = self.recipe_store.add_recipe(recipe1) recipe2.recipe_id = self.recipe_store.add_recipe(recipe2) recipe3.recipe_id = self.recipe_store.add_recipe(recipe3) return_list = self.recipe_store.list_recipes() return_list.sort(key=lambda r: r.description) self.assertListEqual([recipe1, recipe2, recipe3], return_list)
def add_recipe(): json_data = request.data.decode('utf-8') return current_app.recipe_store.add_recipe(Recipe.from_json(json_data))
def test_recipe_to_json_to_recipe(self): recipe = Recipe.from_json(RecipeTest.RECIPE) json_recipe = recipe.to_json() self.assertEquals(json_recipe, RecipeTest.RECIPE)
def test_recipe_to_json(self): recipe = Recipe(author="Author", description="Description", time=30) json_recipe = recipe.to_json() self.assertEquals(json_recipe, RecipeTest.RECIPE)
def test_fetch_recipe_by_id(self): recipe_id = self.recipe_store.add_recipe(Recipe.from_json(RecipeTest.RECIPE)) recipe = self.recipe_store.get_recipe(recipe_id) self.assertEquals(recipe_id, recipe.recipe_id)