Release Drafter / auto_label (push) Skipped
Release Drafter / draft_release (push) Canceled after 0s
CodeQL / Analyze (javascript-typescript) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
Backend Lint and Test / tests (sqlite) (push) Canceled after 0s
Backend Lint and Test / tests (postgres) (push) Canceled after 0s
Docker Nightly Production / Backend Server Tests (push) Canceled after 0s
Frontend Lint and Test / lint (push) Canceled after 0s
Docker Nightly Production / Frontend Tests (push) Canceled after 0s
Build Package / Build frontend and wheel (push) Canceled after 0s
Docker Nightly Production / Build Package (push) Canceled after 0s
Docker Nightly Production / Build E2E Image Cache (push) Canceled after 0s
Docker Nightly Production / Build Tagged Release (push) Canceled after 0s
Docker Nightly Production / Notify Discord (push) Canceled after 0s
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from mealie.schema.recipe.recipe_step import IngredientReferences, RecipeStep, StepCooking
|
|
|
|
|
|
def test_legacy_step_and_explicit_zero():
|
|
step = RecipeStep(text="Mix", ingredient_references=[IngredientReferences(quantity=0)])
|
|
assert step.cooking is None
|
|
assert step.ingredient_references[0].quantity == 0
|
|
assert IngredientReferences().quantity is None
|
|
|
|
|
|
@pytest.mark.parametrize("speed", [1, 0.5, "spoon"])
|
|
def test_cooking_speeds(speed):
|
|
assert StepCooking(speed=speed).speed == speed
|
|
|
|
|
|
@pytest.mark.parametrize("quantity", [-1, float("inf"), float("nan")])
|
|
def test_invalid_quantity(quantity):
|
|
with pytest.raises(ValidationError):
|
|
IngredientReferences(quantity=quantity)
|
|
|
|
|
|
def test_nonfinite_speed_rejected():
|
|
with pytest.raises(ValidationError):
|
|
StepCooking(speed=float("inf"))
|
|
|
|
|
|
def test_unknown_cooking_settings_are_not_silently_discarded():
|
|
with pytest.raises(ValidationError):
|
|
StepCooking.model_validate({"speed": 2, "unknownSetting": True})
|
|
assert "reverse" in StepCooking.model_json_schema(by_alias=True)["properties"]
|
|
|
|
|
|
@pytest.mark.parametrize("reverse", [True, False, None])
|
|
def test_rotation_direction_round_trip(reverse):
|
|
step = RecipeStep.model_validate({"text": "Mix", "cooking": {"speed": "spoon", "reverse": reverse}})
|
|
saved = RecipeStep.model_validate_json(step.model_dump_json(by_alias=True))
|
|
assert saved.cooking.reverse is reverse
|
|
assert StepCooking().reverse is None
|
|
|
|
|
|
@pytest.mark.parametrize("reverse", ["false", "true", 0, 1, "inversa"])
|
|
def test_invalid_rotation_direction_rejected(reverse):
|
|
with pytest.raises(ValidationError):
|
|
StepCooking(reverse=reverse)
|