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

feat: Show Cookbooks from Other Households (#4452)

This commit is contained in:
Michael Genson 2024-11-05 13:57:30 -06:00 committed by GitHub
parent 8983745106
commit 87f4b23711
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 264 additions and 55 deletions

View file

@ -60,6 +60,8 @@ def test_create_cookbook(api_client: TestClient, unique_user: TestUser):
page_data = get_page_data(unique_user.group_id, unique_user.household_id)
response = api_client.post(api_routes.households_cookbooks, json=page_data, headers=unique_user.token)
assert response.status_code == 201
assert response.json()["groupId"] == unique_user.group_id
assert response.json()["householdId"] == unique_user.household_id
@pytest.mark.parametrize("name_input", ["", " ", "@"])
@ -78,9 +80,22 @@ def test_create_cookbook_bad_name(api_client: TestClient, unique_user: TestUser,
assert response.status_code == 422
def test_read_cookbook(api_client: TestClient, unique_user: TestUser, cookbooks: list[TestCookbook]):
@pytest.mark.parametrize("use_other_household", [True, False])
def test_read_cookbook(
api_client: TestClient,
unique_user: TestUser,
h2_user: TestUser,
cookbooks: list[TestCookbook],
use_other_household: bool,
):
sample = random.choice(cookbooks)
response = api_client.get(api_routes.households_cookbooks_item_id(sample.id), headers=unique_user.token)
if use_other_household:
headers = h2_user.token
else:
headers = unique_user.token
# all households should be able to fetch all cookbooks
response = api_client.get(api_routes.households_cookbooks_item_id(sample.id), headers=headers)
assert response.status_code == 200
page_data = response.json()
@ -111,6 +126,28 @@ def test_update_cookbook(api_client: TestClient, unique_user: TestUser, cookbook
assert page_data["slug"] == update_data["name"]
def test_update_cookbook_other_household(
api_client: TestClient, unique_user: TestUser, h2_user: TestUser, cookbooks: list[TestCookbook]
):
cookbook = random.choice(cookbooks)
update_data = get_page_data(unique_user.group_id, unique_user.household_id)
update_data["name"] = random_string(10)
response = api_client.put(
api_routes.households_cookbooks_item_id(cookbook.id), json=update_data, headers=h2_user.token
)
assert response.status_code == 404
response = api_client.get(api_routes.households_cookbooks_item_id(cookbook.id), headers=unique_user.token)
assert response.status_code == 200
page_data = response.json()
assert page_data["name"] != update_data["name"]
assert page_data["slug"] != update_data["name"]
def test_update_cookbooks_many(api_client: TestClient, unique_user: TestUser, cookbooks: list[TestCookbook]):
pages = [x.data for x in cookbooks]
@ -135,6 +172,20 @@ def test_update_cookbooks_many(api_client: TestClient, unique_user: TestUser, co
assert str(know) in server_ids
def test_update_cookbooks_many_other_household(
api_client: TestClient, unique_user: TestUser, h2_user: TestUser, cookbooks: list[TestCookbook]
):
pages = [x.data for x in cookbooks]
reverse_order = sorted(pages, key=lambda x: x["position"], reverse=True)
for x, page in enumerate(reverse_order):
page["position"] = x
page["group_id"] = str(unique_user.group_id)
response = api_client.put(api_routes.households_cookbooks, json=utils.jsonify(reverse_order), headers=h2_user.token)
assert response.status_code == 404
def test_delete_cookbook(api_client: TestClient, unique_user: TestUser, cookbooks: list[TestCookbook]):
sample = random.choice(cookbooks)
response = api_client.delete(api_routes.households_cookbooks_item_id(sample.id), headers=unique_user.token)
@ -145,6 +196,18 @@ def test_delete_cookbook(api_client: TestClient, unique_user: TestUser, cookbook
assert response.status_code == 404
def test_delete_cookbook_other_household(
api_client: TestClient, unique_user: TestUser, h2_user: TestUser, cookbooks: list[TestCookbook]
):
sample = random.choice(cookbooks)
response = api_client.delete(api_routes.households_cookbooks_item_id(sample.id), headers=h2_user.token)
assert response.status_code == 404
response = api_client.get(api_routes.households_cookbooks_item_id(sample.slug), headers=unique_user.token)
assert response.status_code == 200
@pytest.mark.parametrize(
"qf_string, expected_code",
[

View file

@ -299,3 +299,16 @@ def test_cookbook_recipes_includes_all_households(api_client: TestClient, unique
assert recipe.id in fetched_recipe_ids
for recipe in other_recipes:
assert recipe.id in fetched_recipe_ids
def test_cookbooks_from_other_households(api_client: TestClient, unique_user: TestUser, h2_user: TestUser):
h2_cookbook = h2_user.repos.cookbooks.create(
SaveCookBook(
name=random_string(),
group_id=h2_user.group_id,
household_id=h2_user.household_id,
)
)
response = api_client.get(api_routes.recipes, params={"cookbook": h2_cookbook.slug}, headers=unique_user.token)
assert response.status_code == 200