From 579e8838635b00ad58a34e3b69d0761b31bad266 Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Mon, 4 Aug 2025 18:18:44 +0000 Subject: [PATCH] update tests --- .../test_group_shopping_lists.py | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/integration_tests/user_household_tests/test_group_shopping_lists.py b/tests/integration_tests/user_household_tests/test_group_shopping_lists.py index 93dc976d5..9fe6cb8d4 100644 --- a/tests/integration_tests/user_household_tests/test_group_shopping_lists.py +++ b/tests/integration_tests/user_household_tests/test_group_shopping_lists.py @@ -1,5 +1,6 @@ import random +import pytest from fastapi.testclient import TestClient from mealie.schema.household.group_shopping_list import ( @@ -244,6 +245,67 @@ def test_shopping_lists_add_recipes( assert refs_by_id[str(recipe.id)]["recipeQuantity"] == 2 +@pytest.mark.parametrize("is_private_household", [True, False]) +@pytest.mark.parametrize("household_lock_recipe_edits", [True, False]) +def test_shopping_lists_add_cross_household_recipe( + api_client: TestClient, + unique_user: TestUser, + h2_user: TestUser, + shopping_lists: list[ShoppingListOut], + is_private_household: bool, + household_lock_recipe_edits: bool, +): + sample_list = random.choice(shopping_lists) + item_name = random_string(10) + + # set up household + household = h2_user.repos.households.get_one(h2_user.household_id) + assert household and household.preferences + household.preferences.private_household = is_private_household + household.preferences.lock_recipe_edits_from_other_households = household_lock_recipe_edits + h2_user.repos.household_preferences.update(household.id, household.preferences) + + # set up recipe + recipe = h2_user.repos.recipes.create( + Recipe( + user_id=h2_user.user_id, + group_id=h2_user.group_id, + name=random_string(10), + recipe_ingredient=[{"note": item_name, "quantity": 1}], + ) + ) + + # add recipe once + response = api_client.post( + api_routes.households_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id), + headers=unique_user.token, + ) + assert response.status_code == 200 + response = api_client.get( + api_routes.households_shopping_lists_item_id(sample_list.id), + headers=unique_user.token, + ) + as_json = utils.assert_deserialize(response, 200) + assert len(as_json["listItems"]) == 1 + assert as_json["listItems"][0]["note"] == item_name + assert as_json["listItems"][0]["quantity"] == 1 + + # add recipe again + response = api_client.post( + api_routes.households_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id), + headers=unique_user.token, + ) + assert response.status_code == 200 + response = api_client.get( + api_routes.households_shopping_lists_item_id(sample_list.id), + headers=unique_user.token, + ) + as_json = utils.assert_deserialize(response, 200) + assert len(as_json["listItems"]) == 1 + assert as_json["listItems"][0]["note"] == item_name + assert as_json["listItems"][0]["quantity"] == 2 + + def test_shopping_lists_add_one_with_zero_quantity( api_client: TestClient, unique_user: TestUser,