def test_recipe_create(self): recipe_data = get_recipe_data('lekker') recipe = Recipe.recipes.create(**recipe_data) self.compare_object_values(recipe, recipe_data['recipe']) ingredient_amounts = get_ingredient_amounts(recipe) for i, ingredient in enumerate(recipe_data['ingredients']): self.compare_object_values(ingredient_amounts[i], ingredient)
def test_recipe_amounts_update(self): recipe_data = get_recipe_data('lekker') recipe_data['ingredients'][0]['amount']['quantity'] = 3 recipe = Recipe.recipes.update(self.lekker, **recipe_data) self.compare_object_values(recipe, recipe_data['recipe']) ingredient_amounts = get_ingredient_amounts(recipe) for i, ingredient in enumerate(recipe_data['ingredients']): self.compare_object_values(ingredient_amounts[i], ingredient)
def test_recipe_update(self): recipe_data = get_recipe_data('lekker') recipe_data['recipe']['instructions'] = "Stir well for 20 minutes" recipe = Recipe.recipes.update(self.lekker, **recipe_data) self.compare_object_values(recipe, recipe_data['recipe']) ingredient_amounts = get_ingredient_amounts(recipe) for i, ingredient in enumerate(recipe_data['ingredients']): self.compare_object_values(ingredient_amounts[i], ingredient)
def test_recipe_ingredients_update(self): recipe_data = get_recipe_data('lekker') recipe_data['ingredients'][1]['ingredient']['name'] = "onion" recipe_data['ingredients'][1]['ingredient']['plural'] = "onions" recipe = Recipe.recipes.update(self.lekker, **recipe_data) self.compare_object_values(recipe, recipe_data['recipe']) ingredient_amounts = get_ingredient_amounts(recipe) for i, ingredient in enumerate(recipe_data['ingredients']): self.compare_object_values(ingredient_amounts[i], ingredient)
def test_serializer_create(self): recipe_data, expected_recipe = get_recipe_data_flat('frozen_pizza') serializer = RecipeSerializer(data=recipe_data) self.assertTrue(serializer.is_valid()) recipe = serializer.save() ingredient_amounts = get_ingredient_amounts(recipe) self.compare_object_values(recipe, expected_recipe) for i, ingredient in enumerate(recipe_data['ingredients']): self.compare_object_values(ingredient_amounts[i], ingredient)
def test_serializer_update_recipe_ingredients(self): recipe_data, expected_recipe = get_recipe_data_flat('lekker') recipe_data['ingredients'][1]['ingredient']['name'] = "onion" recipe_data['ingredients'][1]['ingredient']['plural'] = "onions" recipe, _ = Recipe.recipes.get(pk=self.lekker.pk) serializer = RecipeSerializer(recipe, data=recipe_data) self.assertTrue(serializer.is_valid()) recipe = serializer.save() ingredient_amounts = get_ingredient_amounts(recipe) self.compare_object_values(recipe, expected_recipe) for i, ingredient in enumerate(recipe_data['ingredients']): self.compare_object_values(ingredient_amounts[i], ingredient)
def test_db_fields(self): recipe_data = get_recipe_data('lekker') ingredient_amounts = get_ingredient_amounts(self.lekker) for i, ingredient in enumerate(recipe_data['ingredients']): self.compare_object_values(ingredient_amounts[i], ingredient)
def test_single_serializer(self): recipe_data = get_recipe_data('lekker') ingredient_amounts = get_ingredient_amounts(self.lekker) for i, ingredient in enumerate(recipe_data['ingredients']): serializer = IngredientAmountSerializer(ingredient_amounts[i]) self.compare_values(serializer.data, ingredient)
def test_multiple_serializer(self): recipe_data = get_recipe_data('lekker') ingredient_amounts = get_ingredient_amounts(self.lekker) serializer = IngredientAmountSerializer(ingredient_amounts, many=True) for i, ingredient in enumerate(recipe_data['ingredients']): self.compare_values(serializer.data[i], ingredient)