mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-10 07:55:23 +02:00
feat: Remove "Is Food" and "Disable Amounts" Flags (#5684)
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
parent
efc0d31724
commit
245ca5fe3b
49 changed files with 173 additions and 364 deletions
|
@ -49,7 +49,6 @@ def test_admin_update_household(api_client: TestClient, admin_user: TestUser, un
|
|||
"recipeShowAssets": random_bool(),
|
||||
"recipeLandscapeView": random_bool(),
|
||||
"recipeDisableComments": random_bool(),
|
||||
"recipeDisableAmount": random_bool(),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -377,7 +377,6 @@ def test_get_suggested_recipes(
|
|||
SaveIngredientFood(id=uuid4(), name=random_string(), group_id=unique_user.group_id)
|
||||
)
|
||||
random_recipe.recipe_ingredient = [RecipeIngredient(food_id=known_food.id, food=known_food)]
|
||||
random_recipe.settings.disable_amount = False
|
||||
database.recipes.update(random_recipe.slug, random_recipe)
|
||||
|
||||
## Try to find suggested recipes
|
||||
|
|
|
@ -145,6 +145,11 @@ from mealie.schema.recipe.recipe_ingredient import (
|
|||
@pytest.mark.parametrize(
|
||||
["food", "expected_food_singular_string", "expected_food_plural_string"],
|
||||
[
|
||||
[
|
||||
None,
|
||||
"",
|
||||
"",
|
||||
],
|
||||
[
|
||||
IngredientFood(id=uuid4(), name="chopped onion", plural_name=None),
|
||||
"chopped onion",
|
||||
|
@ -157,16 +162,14 @@ from mealie.schema.recipe.recipe_ingredient import (
|
|||
],
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("note", ["very thin", ""])
|
||||
@pytest.mark.parametrize("use_food", [True, False])
|
||||
@pytest.mark.parametrize("note", ["very thin", "", None])
|
||||
def test_ingredient_display(
|
||||
quantity: float | None,
|
||||
quantity_display_decimal: str,
|
||||
quantity_display_fraction: str,
|
||||
unit: IngredientUnit | None,
|
||||
food: IngredientFood,
|
||||
note: str,
|
||||
use_food: bool,
|
||||
food: IngredientFood | None,
|
||||
note: str | None,
|
||||
expect_display_fraction: bool,
|
||||
expect_plural_unit: bool,
|
||||
expect_plural_food: bool,
|
||||
|
@ -176,36 +179,25 @@ def test_ingredient_display(
|
|||
expected_food_plural_string: str,
|
||||
):
|
||||
expected_components = []
|
||||
if use_food:
|
||||
if expect_display_fraction:
|
||||
expected_components.append(quantity_display_fraction)
|
||||
if expect_display_fraction:
|
||||
expected_components.append(quantity_display_fraction)
|
||||
else:
|
||||
expected_components.append(quantity_display_decimal)
|
||||
|
||||
if quantity:
|
||||
if expect_plural_unit:
|
||||
expected_components.append(expected_unit_plural_string)
|
||||
else:
|
||||
expected_components.append(quantity_display_decimal)
|
||||
|
||||
if quantity:
|
||||
if expect_plural_unit:
|
||||
expected_components.append(expected_unit_plural_string)
|
||||
else:
|
||||
expected_components.append(expected_unit_singular_string)
|
||||
expected_components.append(expected_unit_singular_string)
|
||||
|
||||
if food:
|
||||
if expect_plural_food:
|
||||
expected_components.append(expected_food_plural_string)
|
||||
else:
|
||||
expected_components.append(expected_food_singular_string)
|
||||
|
||||
expected_components.append(note)
|
||||
|
||||
else:
|
||||
if quantity != 0 and quantity != 1:
|
||||
if expect_display_fraction:
|
||||
expected_components.append(quantity_display_fraction)
|
||||
else:
|
||||
expected_components.append(quantity_display_decimal)
|
||||
|
||||
expected_components.append(note)
|
||||
expected_components.append(note or "")
|
||||
|
||||
expected_display_value = " ".join(c for c in expected_components if c)
|
||||
ingredient = RecipeIngredient(
|
||||
quantity=quantity, unit=unit, food=food, note=note, use_food=use_food, disable_amount=not use_food
|
||||
)
|
||||
ingredient = RecipeIngredient(quantity=quantity, unit=unit, food=food, note=note)
|
||||
assert ingredient.display == expected_display_value
|
||||
|
|
|
@ -48,7 +48,6 @@ def create_recipe(
|
|||
*,
|
||||
foods: list[IngredientFood] | None = None,
|
||||
tools: list[RecipeToolOut] | None = None,
|
||||
disable_amount: bool = False,
|
||||
**kwargs,
|
||||
):
|
||||
if foods:
|
||||
|
@ -63,7 +62,7 @@ def create_recipe(
|
|||
name=kwargs.pop("name", random_string()),
|
||||
recipe_ingredient=ingredients,
|
||||
tools=tools or [],
|
||||
settings=RecipeSettings(disable_amount=disable_amount),
|
||||
settings=RecipeSettings(),
|
||||
**kwargs,
|
||||
)
|
||||
)
|
||||
|
@ -338,60 +337,6 @@ def test_include_recipes_with_no_tools(api_client: TestClient, unique_user: Test
|
|||
unique_user.repos.recipes.delete(recipe.slug)
|
||||
|
||||
|
||||
def test_ignore_recipes_with_ingredient_amounts_disabled_with_foods(api_client: TestClient, unique_user: TestUser):
|
||||
known_food = create_food(unique_user)
|
||||
recipe_with_amounts = create_recipe(unique_user, foods=[known_food])
|
||||
recipe_without_amounts = create_recipe(unique_user, foods=[known_food], disable_amount=True)
|
||||
|
||||
try:
|
||||
response = api_client.get(
|
||||
api_routes.recipes_suggestions,
|
||||
params={"maxMissingFoods": 0, "maxMissingTools": 0, "foods": [str(known_food.id)]},
|
||||
headers=unique_user.token,
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
||||
data = response.json()
|
||||
assert {item["recipe"]["id"] for item in data["items"]} == {str(recipe_with_amounts.id)}
|
||||
for item in data["items"]:
|
||||
assert item["missingFoods"] == []
|
||||
|
||||
finally:
|
||||
for recipe in [recipe_with_amounts, recipe_without_amounts]:
|
||||
unique_user.repos.recipes.delete(recipe.slug)
|
||||
|
||||
|
||||
def test_include_recipes_with_ingredient_amounts_disabled_without_foods(api_client: TestClient, unique_user: TestUser):
|
||||
known_tool = create_tool(unique_user)
|
||||
recipe_with_amounts = create_recipe(unique_user, tools=[known_tool])
|
||||
recipe_without_amounts = create_recipe(unique_user, tools=[known_tool], disable_amount=True)
|
||||
|
||||
try:
|
||||
response = api_client.get(
|
||||
api_routes.recipes_suggestions,
|
||||
params={
|
||||
"maxMissingFoods": 0,
|
||||
"maxMissingTools": 0,
|
||||
"includeFoodsOnHand": False,
|
||||
"tools": [str(known_tool.id)],
|
||||
},
|
||||
headers=unique_user.token,
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
||||
data = response.json()
|
||||
assert {item["recipe"]["id"] for item in data["items"]} == {
|
||||
str(recipe_with_amounts.id),
|
||||
str(recipe_without_amounts.id),
|
||||
}
|
||||
for item in data["items"]:
|
||||
assert item["missingFoods"] == []
|
||||
|
||||
finally:
|
||||
for recipe in [recipe_with_amounts, recipe_without_amounts]:
|
||||
unique_user.repos.recipes.delete(recipe.slug)
|
||||
|
||||
|
||||
def test_exclude_recipes_with_no_user_foods(api_client: TestClient, unique_user: TestUser):
|
||||
known_food = create_food(unique_user)
|
||||
food_on_hand = create_food(unique_user, on_hand=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue