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
108 lines
3.7 KiB
Python
108 lines
3.7 KiB
Python
from uuid import uuid4
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from mealie.schema.recipe.recipe import RecipeDraft
|
|
from mealie.schema.recipe.recipe_step import IngredientReferences, RecipeStep, StepCooking, StepParameter
|
|
|
|
|
|
@pytest.mark.parametrize("kind", ["remaining", "unknown", "prepared", "asNeeded", "referenceOnly"])
|
|
def test_non_numeric_allocations_never_expose_legacy_full_quantity(kind):
|
|
ref = IngredientReferences(quantity_kind=kind)
|
|
assert ref.quantity == 0
|
|
assert IngredientReferences.model_validate_json(ref.model_dump_json()).quantity_kind == kind
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"payload",
|
|
[
|
|
{"quantityKind": "partial"},
|
|
{"quantityKind": "full", "quantity": 1},
|
|
{"quantityKind": "unknown", "quantity": 1},
|
|
{"quantityKind": "prepared", "weighing": "weigh"},
|
|
{"quantityMinimum": 10, "quantityMaximum": 2},
|
|
{"containerCount": 0},
|
|
],
|
|
)
|
|
def test_invalid_allocations_are_not_coerced(payload):
|
|
with pytest.raises(ValidationError):
|
|
IngredientReferences.model_validate(payload)
|
|
|
|
|
|
def test_optional_legacy_allocations_and_appliance_data():
|
|
step = RecipeStep(text="Hand mix", ingredient_references=[IngredientReferences()])
|
|
assert step.cooking is None
|
|
assert step.ingredient_references[0].quantity is None
|
|
assert step.ingredient_references[0].weighing is None
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"payload",
|
|
[
|
|
{"durationRangeSeconds": {"minimum": 5, "maximum": 2}},
|
|
{"durationRangeSeconds": {"minimum": 0}},
|
|
{"durationRangeSeconds": {"minimum": 0.0001}},
|
|
{"speedRange": {"minimum": float("inf")}},
|
|
{"speedProgression": [1, float("nan")]},
|
|
{"repetitions": 1.5},
|
|
{"repetitions": True},
|
|
{"repetitionRange": {"minimum": 1.5}},
|
|
{"optional": "true"},
|
|
{"accessories": [{"name": "basket", "state": "guessed"}]},
|
|
],
|
|
)
|
|
def test_invalid_operation_settings_are_rejected(payload):
|
|
with pytest.raises(ValidationError):
|
|
StepCooking.model_validate(payload)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"payload",
|
|
[
|
|
{"kind": "number", "value": "2"},
|
|
{"kind": "number", "value": True},
|
|
{"kind": "boolean", "value": "false"},
|
|
{"kind": "text", "value": 2},
|
|
{"kind": "range", "value": 2},
|
|
{"kind": "range", "minimum": 5, "maximum": 2},
|
|
{"kind": "text", "minimum": 1},
|
|
],
|
|
)
|
|
def test_parameter_discriminator_is_validated(payload):
|
|
with pytest.raises(ValidationError):
|
|
StepParameter(name="setting", **payload)
|
|
|
|
|
|
def test_dependencies_are_declarative_and_cannot_form_cycles():
|
|
first, second = uuid4(), uuid4()
|
|
with pytest.raises(ValidationError, match="cycle"):
|
|
RecipeDraft(
|
|
recipe_instructions=[
|
|
RecipeStep(id=first, text="First", cooking=StepCooking(depends_on_step_ids=[second])),
|
|
RecipeStep(id=second, text="Second", cooking=StepCooking(depends_on_step_ids=[first])),
|
|
]
|
|
)
|
|
with pytest.raises(ValidationError, match="reference an instruction"):
|
|
RecipeDraft(recipe_instructions=[RecipeStep(text="Wait", cooking=StepCooking(depends_on_step_ids=[uuid4()]))])
|
|
|
|
|
|
def test_cooking_json_is_serializable_without_custom_database_encoders():
|
|
import json
|
|
from datetime import UTC, datetime
|
|
|
|
from mealie.schema.recipe.recipe_step import StepReview, StepReviewEvent
|
|
|
|
cooking = StepCooking(
|
|
depends_on_step_ids=[uuid4()],
|
|
reviews=[
|
|
StepReview(
|
|
category="operation",
|
|
history=[
|
|
StepReviewEvent(at=datetime.now(UTC), status="unresolved", content="Original content"),
|
|
],
|
|
),
|
|
],
|
|
)
|
|
assert StepCooking.model_validate(json.loads(json.dumps(cooking.model_dump()))) == cooking
|