def setUp(self): recipe_data = get_recipe_data('lekker') self.lekker = Recipe.recipes.create(**recipe_data) self.pas_mal = Recipe.objects.create( name='Pas mal', servings=2, instructions='Servir sur un lit de choucroute')
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_data_serializer(self): recipe_data = get_recipe_data('frozen_pizza') ingredient_amount = recipe_data['ingredients'] serializer = IngredientAmountSerializer(data=ingredient_amount, many=True) self.assertTrue(serializer.is_valid()) for i, ingredient in enumerate(recipe_data['ingredients']): self.compare_values(serializer.validated_data[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(self): recipe_data = get_recipe_data('lekker') recipe = Recipe.objects.get(pk=self.lekker.pk) serializer = RecipeModelSerializer(recipe) self.assertEqual(serializer.data['id'], recipe.pk) self.compare_values(serializer.data, recipe_data['recipe']) created = datetime.strptime(serializer.data['created'], '%Y-%m-%dT%H:%M:%S.%fZ') self.assertEqual(created.date(), recipe.created.date()) self.assertEqual(created.time(), recipe.created.time())
def test_serializer(self): recipe_data = get_recipe_data('lekker') recipe, ingredient_amounts = Recipe.recipes.get(pk=self.lekker.pk) serializer = RecipeSerializer( dict(recipe=recipe, ingredients=ingredient_amounts)) self.assertEqual(serializer.data['id'], self.lekker.pk) self.compare_values(get_recipe_no_ingredients(serializer.data), recipe_data['recipe']) for i, ingredient in enumerate(recipe_data['ingredients']): self.compare_values(serializer.data['ingredients'][i], ingredient) self.assertEqual( serializer.data['ingredients'][i]['ingredient']['id'], ingredient_amounts[i].ingredient.id) self.assertEqual( serializer.data['ingredients'][i]['amount']['unit']['id'], ingredient_amounts[i].amount.unit.id)
def test_db_fields(self): recipe_data = get_recipe_data('lekker') self.compare_object_values(self.lekker, recipe_data['recipe']) self.assertIsInstance(self.lekker.created, datetime)
def test_recipe_get(self): recipe_data = get_recipe_data('lekker') recipe, ingredients = Recipe.recipes.get(pk=self.lekker.pk) self.compare_object_values(recipe, recipe_data['recipe']) for i, ingredient in enumerate(recipe_data['ingredients']): self.compare_object_values(ingredients[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)
def setUp(self): recipe_data = get_recipe_data('lekker') self.lekker = Recipe.recipes.create(**recipe_data)