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

feat: Recipe Actions (#3448)

Co-authored-by: boc-the-git <3479092+boc-the-git@users.noreply.github.com>
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
Michael Genson 2024-05-01 02:20:52 -05:00 committed by GitHub
parent ee87a14401
commit 3807778e2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 860 additions and 10 deletions

View file

@ -0,0 +1,100 @@
import pytest
from fastapi.testclient import TestClient
from mealie.schema.group.group_recipe_action import CreateGroupRecipeAction, GroupRecipeActionOut, GroupRecipeActionType
from tests.utils import api_routes, assert_derserialize
from tests.utils.factories import random_int, random_string
from tests.utils.fixture_schemas import TestUser
def new_link_action() -> CreateGroupRecipeAction:
return CreateGroupRecipeAction(
action_type=GroupRecipeActionType.link,
title=random_string(),
url=random_string(),
)
def test_group_recipe_actions_create_one(api_client: TestClient, unique_user: TestUser):
action_in = new_link_action()
response = api_client.post(api_routes.groups_recipe_actions, json=action_in.model_dump(), headers=unique_user.token)
data = assert_derserialize(response, 201)
action_out = GroupRecipeActionOut(**data)
assert action_out.id
assert str(action_out.group_id) == unique_user.group_id
assert action_out.action_type == action_in.action_type
assert action_out.title == action_in.title
assert action_out.url == action_in.url
def test_group_recipe_actions_get_all(api_client: TestClient, unique_user: TestUser):
expected_ids: set[str] = set()
for _ in range(random_int(3, 5)):
response = api_client.post(
api_routes.groups_recipe_actions,
json=new_link_action().model_dump(),
headers=unique_user.token,
)
data = assert_derserialize(response, 201)
expected_ids.add(data["id"])
response = api_client.get(api_routes.groups_recipe_actions, headers=unique_user.token)
data = assert_derserialize(response, 200)
fetched_ids = set(item["id"] for item in data["items"])
for expected_id in expected_ids:
assert expected_id in fetched_ids
@pytest.mark.parametrize("is_own_group", [True, False])
def test_group_recipe_actions_get_one(
api_client: TestClient, unique_user: TestUser, g2_user: TestUser, is_own_group: bool
):
action_in = new_link_action()
response = api_client.post(api_routes.groups_recipe_actions, json=action_in.model_dump(), headers=unique_user.token)
data = assert_derserialize(response, 201)
expected_action_out = GroupRecipeActionOut(**data)
if is_own_group:
fetch_user = unique_user
else:
fetch_user = g2_user
response = api_client.get(
api_routes.groups_recipe_actions_item_id(expected_action_out.id), headers=fetch_user.token
)
if not is_own_group:
assert response.status_code == 404
return
data = assert_derserialize(response, 200)
action_out = GroupRecipeActionOut(**data)
assert action_out == expected_action_out
def test_group_recipe_actions_update_one(api_client: TestClient, unique_user: TestUser):
action_in = new_link_action()
response = api_client.post(api_routes.groups_recipe_actions, json=action_in.model_dump(), headers=unique_user.token)
data = assert_derserialize(response, 201)
action_id = data["id"]
new_title = random_string()
data["title"] = new_title
response = api_client.put(api_routes.groups_recipe_actions_item_id(action_id), json=data, headers=unique_user.token)
data = assert_derserialize(response, 200)
updated_action = GroupRecipeActionOut(**data)
assert updated_action.title == new_title
def test_group_recipe_actions_delete_one(api_client: TestClient, unique_user: TestUser):
action_in = new_link_action()
response = api_client.post(api_routes.groups_recipe_actions, json=action_in.model_dump(), headers=unique_user.token)
data = assert_derserialize(response, 201)
action_id = data["id"]
response = api_client.delete(api_routes.groups_recipe_actions_item_id(action_id), headers=unique_user.token)
assert response.status_code == 200
response = api_client.get(api_routes.groups_recipe_actions_item_id(action_id), headers=unique_user.token)
assert response.status_code == 404