mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-09 03:04:54 -04:00
Fix/issue#2003 - Unable to remove all instructions/ingredients from a recipe (#2008)
* Fix issue where recipes could not have all their ingredients/instructions removed * Add test for removing all instructions and ingredients from a recipe
This commit is contained in:
parent
a72f038247
commit
0cd892059b
@ -146,10 +146,10 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
|||||||
) -> None:
|
) -> None:
|
||||||
self.nutrition = Nutrition(**nutrition) if nutrition else Nutrition()
|
self.nutrition = Nutrition(**nutrition) if nutrition else Nutrition()
|
||||||
|
|
||||||
if recipe_instructions:
|
if recipe_instructions is not None:
|
||||||
self.recipe_instructions = [RecipeInstruction(**step, session=session) for step in recipe_instructions]
|
self.recipe_instructions = [RecipeInstruction(**step, session=session) for step in recipe_instructions]
|
||||||
|
|
||||||
if recipe_ingredient:
|
if recipe_ingredient is not None:
|
||||||
self.recipe_ingredient = [RecipeIngredient(**ingr, session=session) for ingr in recipe_ingredient]
|
self.recipe_ingredient = [RecipeIngredient(**ingr, session=session) for ingr in recipe_ingredient]
|
||||||
|
|
||||||
if assets:
|
if assets:
|
||||||
|
@ -273,6 +273,36 @@ def test_duplicate(api_client: TestClient, recipe_data: RecipeSiteTestCase, uniq
|
|||||||
assert copy_info(original_ingredients[i]) == copy_info(edited_ingredients[i])
|
assert copy_info(original_ingredients[i]) == copy_info(edited_ingredients[i])
|
||||||
|
|
||||||
|
|
||||||
|
# This needs to happen after test_duplicate,
|
||||||
|
# otherwise that one will run into problems with comparing the instruction/ingredient lists
|
||||||
|
@pytest.mark.parametrize("recipe_data", recipe_test_data)
|
||||||
|
def test_update_with_empty_relationship(
|
||||||
|
api_client: TestClient,
|
||||||
|
recipe_data: RecipeSiteTestCase,
|
||||||
|
unique_user: TestUser,
|
||||||
|
):
|
||||||
|
recipe_url = api_routes.recipes_slug(recipe_data.expected_slug)
|
||||||
|
response = api_client.get(recipe_url, headers=unique_user.token)
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
recipe = json.loads(response.text)
|
||||||
|
|
||||||
|
recipe["recipeInstructions"] = []
|
||||||
|
recipe["recipeIngredient"] = []
|
||||||
|
|
||||||
|
response = api_client.put(recipe_url, json=utils.jsonify(recipe), headers=unique_user.token)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert json.loads(response.text).get("slug") == recipe_data.expected_slug
|
||||||
|
|
||||||
|
response = api_client.get(recipe_url, headers=unique_user.token)
|
||||||
|
assert response.status_code == 200
|
||||||
|
recipe = json.loads(response.text)
|
||||||
|
|
||||||
|
assert recipe["recipeInstructions"] == []
|
||||||
|
assert recipe["recipeIngredient"] == []
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("recipe_data", recipe_test_data)
|
@pytest.mark.parametrize("recipe_data", recipe_test_data)
|
||||||
def test_rename(api_client: TestClient, recipe_data: RecipeSiteTestCase, unique_user: TestUser):
|
def test_rename(api_client: TestClient, recipe_data: RecipeSiteTestCase, unique_user: TestUser):
|
||||||
recipe_url = api_routes.recipes_slug(recipe_data.expected_slug)
|
recipe_url = api_routes.recipes_slug(recipe_data.expected_slug)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user