Files
Meal-Planner/backend/tests/test_recipe_schema.py
T
admin 2695ba0232
CI / backend (pytest + alembic) (push) Canceled after 0s
CI / frontend (build) (push) Canceled after 0s
feat(meals): enforce three lower-calorie dinners with media
2026-09-01 10:11:36 -07:00

64 lines
1.9 KiB
Python

from uuid import uuid4
import pytest
from pydantic import ValidationError
from app.schemas.recipe import RecipeCreate, RecipeIngredientRef, RecipeRead, ResolveIngredientRequest
def test_recipe_create_requires_canonical_ingredient_ids() -> None:
iid = uuid4()
payload = RecipeCreate(
name="Sheet-Pan Chicken Thighs",
servings=4,
prep_time_minutes=10,
cook_time_minutes=30,
cuisine_tags=["american"],
protein_type="chicken",
ingredients=[RecipeIngredientRef(ingredient_id=iid, qty=2.0, unit="lb")],
instructions=["Preheat oven", "Roast"],
)
assert payload.ingredients[0].ingredient_id == iid
assert payload.servings == 4
def test_recipe_create_rejects_empty_ingredients() -> None:
with pytest.raises(ValidationError):
RecipeCreate(
name="Empty",
servings=4,
prep_time_minutes=5,
cook_time_minutes=5,
cuisine_tags=[],
protein_type="vegetarian",
ingredients=[],
instructions=["nope"],
)
def test_recipe_read_allows_nullable_discovered_recipe_fields() -> None:
iid = uuid4()
payload = RecipeRead(
id=uuid4(),
name="Imported Recipe With Sparse Metadata",
servings=4,
prep_time_minutes=None,
cook_time_minutes=None,
cuisine_tags=[],
dietary_tags=[],
protein_type=None,
ingredients=[RecipeIngredientRef(ingredient_id=iid, qty=1.0, unit="ea")],
instructions=["Cook until done"],
side_dishes=None,
)
assert payload.prep_time_minutes is None
assert payload.cook_time_minutes is None
assert payload.protein_type is None
def test_resolve_ingredient_request_round_trip() -> None:
req = ResolveIngredientRequest(text="1 lb chicken thighs")
assert req.text == "1 lb chicken thighs"