1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-03 04:25:24 +02:00

Fix/multiple bug fixes (#1015)

* test-case for #1011

* revert regressions for #1011

* update cache key on new image

* lint

* fix #1012

* typing

* random_recipe fixture

* remove delete button when no listeners are present

* spacing

* update copy to match settings value
This commit is contained in:
Hayden 2022-02-27 12:48:21 -09:00 committed by GitHub
parent 6a5fd8e4f8
commit 568a1a0015
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 112 additions and 18 deletions

View file

@ -5,6 +5,7 @@ from mealie.repos.repository_factory import AllRepositories
from mealie.schema.recipe.recipe import Recipe, RecipeCategory
from mealie.schema.recipe.recipe_category import CategorySave
from mealie.schema.recipe.recipe_ingredient import RecipeIngredient
from mealie.schema.recipe.recipe_step import RecipeStep
from tests.utils.factories import random_string
from tests.utils.fixture_schemas import TestUser
from tests.utils.recipe_data import get_raw_no_image, get_raw_recipe, get_recipe_test_cases
@ -70,3 +71,31 @@ def recipe_categories(database: AllRepositories, unique_user: TestUser) -> list[
database.categories.delete(model.id)
except sqlalchemy.exc.NoResultFound:
pass
@fixture(scope="function")
def random_recipe(database: AllRepositories, unique_user: TestUser) -> Recipe:
recipe = Recipe(
user_id=unique_user.user_id,
group_id=unique_user.group_id,
name=random_string(10),
recipe_ingredient=[
RecipeIngredient(note="Ingredient 1"),
RecipeIngredient(note="Ingredient 2"),
RecipeIngredient(note="Ingredient 3"),
],
recipe_instructions=[
RecipeStep(text="Step 1"),
RecipeStep(text="Step 2"),
RecipeStep(text="Step 3"),
],
)
model = database.recipes.create(recipe)
yield model
try:
database.recipes.delete(model.slug)
except sqlalchemy.exc.NoResultFound:
pass

View file

@ -0,0 +1,49 @@
import json
import random
from fastapi.testclient import TestClient
from mealie.schema.recipe.recipe import Recipe
from mealie.schema.recipe.recipe_step import IngredientReferences
from tests.utils import jsonify, routes
from tests.utils.fixture_schemas import TestUser
def test_associate_ingredient_with_step(api_client: TestClient, unique_user: TestUser, random_recipe: Recipe):
recipe: Recipe = random_recipe
# Associate an ingredient with a step
steps = {} # key=step_id, value=ingredient_id
for idx, step in enumerate(recipe.recipe_instructions):
ingredients = random.choices(recipe.recipe_ingredient, k=2)
step.ingredient_references = [
IngredientReferences(reference_id=ingredient.reference_id) for ingredient in ingredients
]
steps[idx] = [str(ingredient.reference_id) for ingredient in ingredients]
response = api_client.put(
routes.RoutesRecipe.item(recipe.slug),
json=jsonify(recipe.dict()),
headers=unique_user.token,
)
assert response.status_code == 200
# Get Recipe and check that the ingredient is associated with the step
response = api_client.get(routes.RoutesRecipe.item(recipe.slug), headers=unique_user.token)
assert response.status_code == 200
recipe = json.loads(response.text)
for idx, step in enumerate(recipe.get("recipeInstructions")):
all_refs = [ref["referenceId"] for ref in step.get("ingredientReferences")]
assert len(all_refs) == 2
assert all(ref in steps[idx] for ref in all_refs)