import io from django.core.files.uploadedfile import SimpleUploadedFile from PIL import Image from recipes import parsing from recipes.models import Recipe def make_recipe(owner, title="Testrezept", visibility=Recipe.Visibility.PUBLIC, ingredients="200 g Mehl\n2 Eier", steps="Mischen.\n\nBacken.", tags=("kuchen",)): recipe = Recipe.objects.create(owner=owner, title=title, visibility=visibility, servings=4) recipe.set_ingredients(parsing.parse_ingredients(ingredients)) recipe.set_steps(parsing.parse_steps(steps)) recipe.set_tags(tags) return recipe def image_upload(name="foto.jpg", size=(1200, 900), fmt="JPEG", color=(200, 120, 40)): buffer = io.BytesIO() Image.new("RGB", size, color).save(buffer, fmt) content_type = {"JPEG": "image/jpeg", "PNG": "image/png", "WEBP": "image/webp"}[fmt] return SimpleUploadedFile(name, buffer.getvalue(), content_type=content_type) def form_data(**overrides): data = { "title": "Pfannkuchen", "description": "Einfach und schnell.", "servings": 4, "servings_label": "Portionen", "prep_minutes": 10, "cook_minutes": 15, "ingredients_text": "250 g Mehl\n500 ml Milch\n3 Eier\n1 Prise Salz", "steps_text": "Alles verrühren.\n\nIn der Pfanne ausbacken.", "tags_text": "Frühstück, Süß", "author_notes": "Mit Apfelmus servieren.", "source_url": "", "visibility": "private", } data.update(overrides) return data