mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-09 03:04:54 -04:00
fix: Typo, assert_derserialize => assert_deserialize (#3814)
This commit is contained in:
parent
bdac51bae2
commit
e80ba7dff3
@ -11,7 +11,7 @@ from mealie.schema.group.group_migration import SupportedMigrations
|
|||||||
from mealie.schema.reports.reports import ReportEntryOut
|
from mealie.schema.reports.reports import ReportEntryOut
|
||||||
from tests import data as test_data
|
from tests import data as test_data
|
||||||
from tests.utils import api_routes
|
from tests.utils import api_routes
|
||||||
from tests.utils.assertion_helpers import assert_derserialize
|
from tests.utils.assertion_helpers import assert_deserialize
|
||||||
from tests.utils.fixture_schemas import TestUser
|
from tests.utils.fixture_schemas import TestUser
|
||||||
|
|
||||||
|
|
||||||
@ -80,14 +80,14 @@ def test_recipe_migration(api_client: TestClient, unique_user: TestUser, mig: Mi
|
|||||||
# Validate Create Event
|
# Validate Create Event
|
||||||
params = {"orderBy": "created_at", "orderDirection": "desc"}
|
params = {"orderBy": "created_at", "orderDirection": "desc"}
|
||||||
response = api_client.get(api_routes.recipes, params=params, headers=unique_user.token)
|
response = api_client.get(api_routes.recipes, params=params, headers=unique_user.token)
|
||||||
query_data = assert_derserialize(response)
|
query_data = assert_deserialize(response)
|
||||||
assert len(query_data["items"])
|
assert len(query_data["items"])
|
||||||
|
|
||||||
recipe_id = query_data["items"][0]["id"]
|
recipe_id = query_data["items"][0]["id"]
|
||||||
params = {"queryFilter": f"recipe_id={recipe_id}"}
|
params = {"queryFilter": f"recipe_id={recipe_id}"}
|
||||||
|
|
||||||
response = api_client.get(api_routes.recipes_timeline_events, params=params, headers=unique_user.token)
|
response = api_client.get(api_routes.recipes_timeline_events, params=params, headers=unique_user.token)
|
||||||
query_data = assert_derserialize(response)
|
query_data = assert_deserialize(response)
|
||||||
events = query_data["items"]
|
events = query_data["items"]
|
||||||
assert len(events)
|
assert len(events)
|
||||||
|
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
from mealie.schema.group.group_recipe_action import CreateGroupRecipeAction, GroupRecipeActionOut, GroupRecipeActionType
|
from mealie.schema.group.group_recipe_action import (
|
||||||
from tests.utils import api_routes, assert_derserialize
|
CreateGroupRecipeAction,
|
||||||
|
GroupRecipeActionOut,
|
||||||
|
GroupRecipeActionType,
|
||||||
|
)
|
||||||
|
from tests.utils import api_routes, assert_deserialize
|
||||||
from tests.utils.factories import random_int, random_string
|
from tests.utils.factories import random_int, random_string
|
||||||
from tests.utils.fixture_schemas import TestUser
|
from tests.utils.fixture_schemas import TestUser
|
||||||
|
|
||||||
@ -17,8 +21,12 @@ def new_link_action() -> CreateGroupRecipeAction:
|
|||||||
|
|
||||||
def test_group_recipe_actions_create_one(api_client: TestClient, unique_user: TestUser):
|
def test_group_recipe_actions_create_one(api_client: TestClient, unique_user: TestUser):
|
||||||
action_in = new_link_action()
|
action_in = new_link_action()
|
||||||
response = api_client.post(api_routes.groups_recipe_actions, json=action_in.model_dump(), headers=unique_user.token)
|
response = api_client.post(
|
||||||
data = assert_derserialize(response, 201)
|
api_routes.groups_recipe_actions,
|
||||||
|
json=action_in.model_dump(),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
data = assert_deserialize(response, 201)
|
||||||
|
|
||||||
action_out = GroupRecipeActionOut(**data)
|
action_out = GroupRecipeActionOut(**data)
|
||||||
assert action_out.id
|
assert action_out.id
|
||||||
@ -36,11 +44,11 @@ def test_group_recipe_actions_get_all(api_client: TestClient, unique_user: TestU
|
|||||||
json=new_link_action().model_dump(),
|
json=new_link_action().model_dump(),
|
||||||
headers=unique_user.token,
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
data = assert_derserialize(response, 201)
|
data = assert_deserialize(response, 201)
|
||||||
expected_ids.add(data["id"])
|
expected_ids.add(data["id"])
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_recipe_actions, headers=unique_user.token)
|
response = api_client.get(api_routes.groups_recipe_actions, headers=unique_user.token)
|
||||||
data = assert_derserialize(response, 200)
|
data = assert_deserialize(response, 200)
|
||||||
fetched_ids = set(item["id"] for item in data["items"])
|
fetched_ids = set(item["id"] for item in data["items"])
|
||||||
for expected_id in expected_ids:
|
for expected_id in expected_ids:
|
||||||
assert expected_id in fetched_ids
|
assert expected_id in fetched_ids
|
||||||
@ -51,8 +59,12 @@ def test_group_recipe_actions_get_one(
|
|||||||
api_client: TestClient, unique_user: TestUser, g2_user: TestUser, is_own_group: bool
|
api_client: TestClient, unique_user: TestUser, g2_user: TestUser, is_own_group: bool
|
||||||
):
|
):
|
||||||
action_in = new_link_action()
|
action_in = new_link_action()
|
||||||
response = api_client.post(api_routes.groups_recipe_actions, json=action_in.model_dump(), headers=unique_user.token)
|
response = api_client.post(
|
||||||
data = assert_derserialize(response, 201)
|
api_routes.groups_recipe_actions,
|
||||||
|
json=action_in.model_dump(),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
data = assert_deserialize(response, 201)
|
||||||
expected_action_out = GroupRecipeActionOut(**data)
|
expected_action_out = GroupRecipeActionOut(**data)
|
||||||
|
|
||||||
if is_own_group:
|
if is_own_group:
|
||||||
@ -61,27 +73,36 @@ def test_group_recipe_actions_get_one(
|
|||||||
fetch_user = g2_user
|
fetch_user = g2_user
|
||||||
|
|
||||||
response = api_client.get(
|
response = api_client.get(
|
||||||
api_routes.groups_recipe_actions_item_id(expected_action_out.id), headers=fetch_user.token
|
api_routes.groups_recipe_actions_item_id(expected_action_out.id),
|
||||||
|
headers=fetch_user.token,
|
||||||
)
|
)
|
||||||
if not is_own_group:
|
if not is_own_group:
|
||||||
assert response.status_code == 404
|
assert response.status_code == 404
|
||||||
return
|
return
|
||||||
|
|
||||||
data = assert_derserialize(response, 200)
|
data = assert_deserialize(response, 200)
|
||||||
action_out = GroupRecipeActionOut(**data)
|
action_out = GroupRecipeActionOut(**data)
|
||||||
assert action_out == expected_action_out
|
assert action_out == expected_action_out
|
||||||
|
|
||||||
|
|
||||||
def test_group_recipe_actions_update_one(api_client: TestClient, unique_user: TestUser):
|
def test_group_recipe_actions_update_one(api_client: TestClient, unique_user: TestUser):
|
||||||
action_in = new_link_action()
|
action_in = new_link_action()
|
||||||
response = api_client.post(api_routes.groups_recipe_actions, json=action_in.model_dump(), headers=unique_user.token)
|
response = api_client.post(
|
||||||
data = assert_derserialize(response, 201)
|
api_routes.groups_recipe_actions,
|
||||||
|
json=action_in.model_dump(),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
data = assert_deserialize(response, 201)
|
||||||
action_id = data["id"]
|
action_id = data["id"]
|
||||||
|
|
||||||
new_title = random_string()
|
new_title = random_string()
|
||||||
data["title"] = new_title
|
data["title"] = new_title
|
||||||
response = api_client.put(api_routes.groups_recipe_actions_item_id(action_id), json=data, headers=unique_user.token)
|
response = api_client.put(
|
||||||
data = assert_derserialize(response, 200)
|
api_routes.groups_recipe_actions_item_id(action_id),
|
||||||
|
json=data,
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
data = assert_deserialize(response, 200)
|
||||||
updated_action = GroupRecipeActionOut(**data)
|
updated_action = GroupRecipeActionOut(**data)
|
||||||
|
|
||||||
assert updated_action.title == new_title
|
assert updated_action.title == new_title
|
||||||
@ -89,8 +110,12 @@ def test_group_recipe_actions_update_one(api_client: TestClient, unique_user: Te
|
|||||||
|
|
||||||
def test_group_recipe_actions_delete_one(api_client: TestClient, unique_user: TestUser):
|
def test_group_recipe_actions_delete_one(api_client: TestClient, unique_user: TestUser):
|
||||||
action_in = new_link_action()
|
action_in = new_link_action()
|
||||||
response = api_client.post(api_routes.groups_recipe_actions, json=action_in.model_dump(), headers=unique_user.token)
|
response = api_client.post(
|
||||||
data = assert_derserialize(response, 201)
|
api_routes.groups_recipe_actions,
|
||||||
|
json=action_in.model_dump(),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
data = assert_deserialize(response, 201)
|
||||||
action_id = data["id"]
|
action_id = data["id"]
|
||||||
|
|
||||||
response = api_client.delete(api_routes.groups_recipe_actions_item_id(action_id), headers=unique_user.token)
|
response = api_client.delete(api_routes.groups_recipe_actions_item_id(action_id), headers=unique_user.token)
|
||||||
|
@ -16,7 +16,12 @@ from tests.utils.fixture_schemas import TestUser
|
|||||||
|
|
||||||
|
|
||||||
def create_item(list_id: UUID4, **kwargs) -> dict:
|
def create_item(list_id: UUID4, **kwargs) -> dict:
|
||||||
return {"shopping_list_id": str(list_id), "note": random_string(10), "quantity": random_int(1, 10), **kwargs}
|
return {
|
||||||
|
"shopping_list_id": str(list_id),
|
||||||
|
"note": random_string(10),
|
||||||
|
"quantity": random_int(1, 10),
|
||||||
|
**kwargs,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def serialize_list_items(list_items: list[ShoppingListItemOut]) -> list:
|
def serialize_list_items(list_items: list[ShoppingListItemOut]) -> list:
|
||||||
@ -38,20 +43,26 @@ def test_shopping_list_items_create_one(
|
|||||||
item = create_item(shopping_list.id)
|
item = create_item(shopping_list.id)
|
||||||
|
|
||||||
response = api_client.post(api_routes.groups_shopping_items, json=item, headers=unique_user.token)
|
response = api_client.post(api_routes.groups_shopping_items, json=item, headers=unique_user.token)
|
||||||
as_json = utils.assert_derserialize(response, 201)
|
as_json = utils.assert_deserialize(response, 201)
|
||||||
assert len(as_json["createdItems"]) == 1
|
assert len(as_json["createdItems"]) == 1
|
||||||
|
|
||||||
# Test Item is Getable
|
# Test Item is Getable
|
||||||
created_item_id = as_json["createdItems"][0]["id"]
|
created_item_id = as_json["createdItems"][0]["id"]
|
||||||
response = api_client.get(api_routes.groups_shopping_items_item_id(created_item_id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_items_item_id(created_item_id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
# Ensure List Id is Set
|
# Ensure List Id is Set
|
||||||
assert as_json["shoppingListId"] == str(shopping_list.id)
|
assert as_json["shoppingListId"] == str(shopping_list.id)
|
||||||
|
|
||||||
# Test Item In List
|
# Test Item In List
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
response_list = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
response_list = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert len(response_list["listItems"]) == 1
|
assert len(response_list["listItems"]) == 1
|
||||||
|
|
||||||
@ -64,16 +75,23 @@ def test_shopping_list_items_create_many(
|
|||||||
) -> None:
|
) -> None:
|
||||||
items = [create_item(shopping_list.id) for _ in range(10)]
|
items = [create_item(shopping_list.id) for _ in range(10)]
|
||||||
|
|
||||||
response = api_client.post(api_routes.groups_shopping_items_create_bulk, json=items, headers=unique_user.token)
|
response = api_client.post(
|
||||||
as_json = utils.assert_derserialize(response, 201)
|
api_routes.groups_shopping_items_create_bulk,
|
||||||
|
json=items,
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 201)
|
||||||
assert len(as_json["createdItems"]) == len(items)
|
assert len(as_json["createdItems"]) == len(items)
|
||||||
assert len(as_json["updatedItems"]) == 0
|
assert len(as_json["updatedItems"]) == 0
|
||||||
assert len(as_json["deletedItems"]) == 0
|
assert len(as_json["deletedItems"]) == 0
|
||||||
|
|
||||||
# test items in list
|
# test items in list
|
||||||
created_item_ids = [item["id"] for item in as_json["createdItems"]]
|
created_item_ids = [item["id"] for item in as_json["createdItems"]]
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
# make sure the list is the correct size
|
# make sure the list is the correct size
|
||||||
assert len(as_json["listItems"]) == len(items)
|
assert len(as_json["listItems"]) == len(items)
|
||||||
@ -89,13 +107,16 @@ def test_shopping_list_items_create_many(
|
|||||||
|
|
||||||
|
|
||||||
def test_shopping_list_items_auto_assign_label_with_food_without_label(
|
def test_shopping_list_items_auto_assign_label_with_food_without_label(
|
||||||
api_client: TestClient, unique_user: TestUser, shopping_list: ShoppingListOut, database: AllRepositories
|
api_client: TestClient,
|
||||||
|
unique_user: TestUser,
|
||||||
|
shopping_list: ShoppingListOut,
|
||||||
|
database: AllRepositories,
|
||||||
):
|
):
|
||||||
food = database.ingredient_foods.create(SaveIngredientFood(name=random_string(10), group_id=unique_user.group_id))
|
food = database.ingredient_foods.create(SaveIngredientFood(name=random_string(10), group_id=unique_user.group_id))
|
||||||
|
|
||||||
item = create_item(shopping_list.id, food_id=str(food.id))
|
item = create_item(shopping_list.id, food_id=str(food.id))
|
||||||
response = api_client.post(api_routes.groups_shopping_items, json=item, headers=unique_user.token)
|
response = api_client.post(api_routes.groups_shopping_items, json=item, headers=unique_user.token)
|
||||||
as_json = utils.assert_derserialize(response, 201)
|
as_json = utils.assert_deserialize(response, 201)
|
||||||
assert len(as_json["createdItems"]) == 1
|
assert len(as_json["createdItems"]) == 1
|
||||||
|
|
||||||
item_out = ShoppingListItemOut.model_validate(as_json["createdItems"][0])
|
item_out = ShoppingListItemOut.model_validate(as_json["createdItems"][0])
|
||||||
@ -104,7 +125,10 @@ def test_shopping_list_items_auto_assign_label_with_food_without_label(
|
|||||||
|
|
||||||
|
|
||||||
def test_shopping_list_items_auto_assign_label_with_food_with_label(
|
def test_shopping_list_items_auto_assign_label_with_food_with_label(
|
||||||
api_client: TestClient, unique_user: TestUser, shopping_list: ShoppingListOut, database: AllRepositories
|
api_client: TestClient,
|
||||||
|
unique_user: TestUser,
|
||||||
|
shopping_list: ShoppingListOut,
|
||||||
|
database: AllRepositories,
|
||||||
):
|
):
|
||||||
label = database.group_multi_purpose_labels.create({"name": random_string(10), "group_id": unique_user.group_id})
|
label = database.group_multi_purpose_labels.create({"name": random_string(10), "group_id": unique_user.group_id})
|
||||||
food = database.ingredient_foods.create(
|
food = database.ingredient_foods.create(
|
||||||
@ -113,7 +137,7 @@ def test_shopping_list_items_auto_assign_label_with_food_with_label(
|
|||||||
|
|
||||||
item = create_item(shopping_list.id, food_id=str(food.id))
|
item = create_item(shopping_list.id, food_id=str(food.id))
|
||||||
response = api_client.post(api_routes.groups_shopping_items, json=item, headers=unique_user.token)
|
response = api_client.post(api_routes.groups_shopping_items, json=item, headers=unique_user.token)
|
||||||
as_json = utils.assert_derserialize(response, 201)
|
as_json = utils.assert_deserialize(response, 201)
|
||||||
assert len(as_json["createdItems"]) == 1
|
assert len(as_json["createdItems"]) == 1
|
||||||
|
|
||||||
item_out = ShoppingListItemOut.model_validate(as_json["createdItems"][0])
|
item_out = ShoppingListItemOut.model_validate(as_json["createdItems"][0])
|
||||||
@ -142,7 +166,7 @@ def test_shopping_list_items_auto_assign_label_with_food_search(
|
|||||||
item["note"] = name
|
item["note"] = name
|
||||||
|
|
||||||
response = api_client.post(api_routes.groups_shopping_items, json=item, headers=unique_user.token)
|
response = api_client.post(api_routes.groups_shopping_items, json=item, headers=unique_user.token)
|
||||||
as_json = utils.assert_derserialize(response, 201)
|
as_json = utils.assert_deserialize(response, 201)
|
||||||
assert len(as_json["createdItems"]) == 1
|
assert len(as_json["createdItems"]) == 1
|
||||||
|
|
||||||
item_out = ShoppingListItemOut.model_validate(as_json["createdItems"][0])
|
item_out = ShoppingListItemOut.model_validate(as_json["createdItems"][0])
|
||||||
@ -168,9 +192,13 @@ def test_shopping_list_items_get_all(
|
|||||||
unique_user: TestUser,
|
unique_user: TestUser,
|
||||||
list_with_items: ShoppingListOut,
|
list_with_items: ShoppingListOut,
|
||||||
) -> None:
|
) -> None:
|
||||||
params = {"page": 1, "perPage": -1, "queryFilter": f"shopping_list_id={list_with_items.id}"}
|
params = {
|
||||||
|
"page": 1,
|
||||||
|
"perPage": -1,
|
||||||
|
"queryFilter": f"shopping_list_id={list_with_items.id}",
|
||||||
|
}
|
||||||
response = api_client.get(api_routes.groups_shopping_items, params=params, headers=unique_user.token)
|
response = api_client.get(api_routes.groups_shopping_items, params=params, headers=unique_user.token)
|
||||||
pagination_json = utils.assert_derserialize(response, 200)
|
pagination_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(pagination_json["items"]) == len(list_with_items.list_items)
|
assert len(pagination_json["items"]) == len(list_with_items.list_items)
|
||||||
|
|
||||||
|
|
||||||
@ -193,9 +221,11 @@ def test_shopping_list_items_update_one(
|
|||||||
update_data["id"] = str(item.id)
|
update_data["id"] = str(item.id)
|
||||||
|
|
||||||
response = api_client.put(
|
response = api_client.put(
|
||||||
api_routes.groups_shopping_items_item_id(item.id), json=update_data, headers=unique_user.token
|
api_routes.groups_shopping_items_item_id(item.id),
|
||||||
|
json=update_data,
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
item_json = utils.assert_derserialize(response, 200)
|
item_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert len(item_json["createdItems"]) == 0
|
assert len(item_json["createdItems"]) == 0
|
||||||
assert len(item_json["updatedItems"]) == 1
|
assert len(item_json["updatedItems"]) == 1
|
||||||
@ -204,8 +234,11 @@ def test_shopping_list_items_update_one(
|
|||||||
assert item_json["updatedItems"][0]["quantity"] == update_data["quantity"]
|
assert item_json["updatedItems"][0]["quantity"] == update_data["quantity"]
|
||||||
|
|
||||||
# make sure the list didn't change sizes
|
# make sure the list didn't change sizes
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(list_with_items.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(list_with_items.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["listItems"]) == len(list_with_items.list_items)
|
assert len(as_json["listItems"]) == len(list_with_items.list_items)
|
||||||
|
|
||||||
|
|
||||||
@ -217,8 +250,12 @@ def test_shopping_list_items_update_many(
|
|||||||
for item in items:
|
for item in items:
|
||||||
item["quantity"] += 10
|
item["quantity"] += 10
|
||||||
|
|
||||||
response = api_client.post(api_routes.groups_shopping_items_create_bulk, json=items, headers=unique_user.token)
|
response = api_client.post(
|
||||||
as_json = utils.assert_derserialize(response, 201)
|
api_routes.groups_shopping_items_create_bulk,
|
||||||
|
json=items,
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 201)
|
||||||
assert len(as_json["createdItems"]) == len(items)
|
assert len(as_json["createdItems"]) == len(items)
|
||||||
|
|
||||||
# update the items and compare values
|
# update the items and compare values
|
||||||
@ -227,16 +264,23 @@ def test_shopping_list_items_update_many(
|
|||||||
update_item["quantity"] += random_int(-5, 5)
|
update_item["quantity"] += random_int(-5, 5)
|
||||||
item_quantity_map[update_item["id"]] = update_item["quantity"]
|
item_quantity_map[update_item["id"]] = update_item["quantity"]
|
||||||
|
|
||||||
response = api_client.put(api_routes.groups_shopping_items, json=as_json["createdItems"], headers=unique_user.token)
|
response = api_client.put(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_items,
|
||||||
|
json=as_json["createdItems"],
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["updatedItems"]) == len(items)
|
assert len(as_json["updatedItems"]) == len(items)
|
||||||
|
|
||||||
for updated_item in as_json["updatedItems"]:
|
for updated_item in as_json["updatedItems"]:
|
||||||
assert item_quantity_map[updated_item["id"]] == updated_item["quantity"]
|
assert item_quantity_map[updated_item["id"]] == updated_item["quantity"]
|
||||||
|
|
||||||
# make sure the list didn't change sizes
|
# make sure the list didn't change sizes
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["listItems"]) == len(items)
|
assert len(as_json["listItems"]) == len(items)
|
||||||
|
|
||||||
|
|
||||||
@ -266,8 +310,11 @@ def test_shopping_list_items_update_many_reorder(
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
# retrieve list and check positions against list
|
# retrieve list and check positions against list
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(list_with_items.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
response_list = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(list_with_items.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
response_list = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
for i, item_data in enumerate(response_list["listItems"]):
|
for i, item_data in enumerate(response_list["listItems"]):
|
||||||
assert item_data["position"] == i
|
assert item_data["position"] == i
|
||||||
@ -306,13 +353,18 @@ def test_shopping_list_items_update_many_consolidates_common_items(
|
|||||||
|
|
||||||
# update list
|
# update list
|
||||||
response = api_client.put(
|
response = api_client.put(
|
||||||
api_routes.groups_shopping_items, json=serialize_list_items(list_items), headers=unique_user.token
|
api_routes.groups_shopping_items,
|
||||||
|
json=serialize_list_items(list_items),
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
# retrieve list and check positions against list
|
# retrieve list and check positions against list
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(list_with_items.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
response_list = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(list_with_items.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
response_list = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert len(response_list["listItems"]) == 1
|
assert len(response_list["listItems"]) == 1
|
||||||
assert response_list["listItems"][0]["quantity"] == len(list_items)
|
assert response_list["listItems"][0]["quantity"] == len(list_items)
|
||||||
@ -333,9 +385,11 @@ def test_shopping_list_items_add_mergeable(
|
|||||||
merged_qty = sum([item["quantity"] for item in duplicate_items]) # type: ignore
|
merged_qty = sum([item["quantity"] for item in duplicate_items]) # type: ignore
|
||||||
|
|
||||||
response = api_client.post(
|
response = api_client.post(
|
||||||
api_routes.groups_shopping_items_create_bulk, json=items + duplicate_items, headers=unique_user.token
|
api_routes.groups_shopping_items_create_bulk,
|
||||||
|
json=items + duplicate_items,
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
as_json = utils.assert_derserialize(response, 201)
|
as_json = utils.assert_deserialize(response, 201)
|
||||||
assert len(as_json["createdItems"]) == len(items) + 1
|
assert len(as_json["createdItems"]) == len(items) + 1
|
||||||
assert len(as_json["updatedItems"]) == 0
|
assert len(as_json["updatedItems"]) == 0
|
||||||
assert len(as_json["deletedItems"]) == 0
|
assert len(as_json["deletedItems"]) == 0
|
||||||
@ -356,7 +410,7 @@ def test_shopping_list_items_add_mergeable(
|
|||||||
updated_quantity = new_item["quantity"] + item_to_merge_into["quantity"]
|
updated_quantity = new_item["quantity"] + item_to_merge_into["quantity"]
|
||||||
|
|
||||||
response = api_client.post(api_routes.groups_shopping_items, json=new_item, headers=unique_user.token)
|
response = api_client.post(api_routes.groups_shopping_items, json=new_item, headers=unique_user.token)
|
||||||
item_json = utils.assert_derserialize(response, 201)
|
item_json = utils.assert_deserialize(response, 201)
|
||||||
|
|
||||||
# we should have received an updated item, not a created item
|
# we should have received an updated item, not a created item
|
||||||
assert len(item_json["createdItems"]) == 0
|
assert len(item_json["createdItems"]) == 0
|
||||||
@ -366,8 +420,11 @@ def test_shopping_list_items_add_mergeable(
|
|||||||
assert item_json["updatedItems"][0]["quantity"] == updated_quantity
|
assert item_json["updatedItems"][0]["quantity"] == updated_quantity
|
||||||
|
|
||||||
# fetch the list and make sure we have the correct number of items
|
# fetch the list and make sure we have the correct number of items
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
list_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
list_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(list_json["listItems"]) == len(as_json["createdItems"])
|
assert len(list_json["listItems"]) == len(as_json["createdItems"])
|
||||||
|
|
||||||
|
|
||||||
@ -383,7 +440,7 @@ def test_shopping_list_items_update_mergable(
|
|||||||
|
|
||||||
payload = utils.jsonify([item.model_dump() for item in list_with_items.list_items])
|
payload = utils.jsonify([item.model_dump() for item in list_with_items.list_items])
|
||||||
response = api_client.put(api_routes.groups_shopping_items, json=payload, headers=unique_user.token)
|
response = api_client.put(api_routes.groups_shopping_items, json=payload, headers=unique_user.token)
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert len(as_json["createdItems"]) == 0
|
assert len(as_json["createdItems"]) == 0
|
||||||
assert len(as_json["updatedItems"]) == ceil(len(list_with_items.list_items) / 2)
|
assert len(as_json["updatedItems"]) == ceil(len(list_with_items.list_items) / 2)
|
||||||
@ -400,8 +457,11 @@ def test_shopping_list_items_update_mergable(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# confirm the number of items on the list matches
|
# confirm the number of items on the list matches
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(list_with_items.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(list_with_items.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
updated_list_items = as_json["listItems"]
|
updated_list_items = as_json["listItems"]
|
||||||
assert len(updated_list_items) == ceil(len(list_with_items.list_items) / 2)
|
assert len(updated_list_items) == ceil(len(list_with_items.list_items) / 2)
|
||||||
|
|
||||||
@ -415,7 +475,7 @@ def test_shopping_list_items_update_mergable(
|
|||||||
|
|
||||||
payload = utils.jsonify(items_to_merge)
|
payload = utils.jsonify(items_to_merge)
|
||||||
response = api_client.put(api_routes.groups_shopping_items, json=payload, headers=unique_user.token)
|
response = api_client.put(api_routes.groups_shopping_items, json=payload, headers=unique_user.token)
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert len(as_json["createdItems"]) == 0
|
assert len(as_json["createdItems"]) == 0
|
||||||
assert len(as_json["updatedItems"]) == 1
|
assert len(as_json["updatedItems"]) == 1
|
||||||
@ -448,7 +508,7 @@ def test_shopping_list_items_checked_off(
|
|||||||
headers=unique_user.token,
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
|
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["createdItems"]) == 0
|
assert len(as_json["createdItems"]) == 0
|
||||||
assert len(as_json["updatedItems"]) == 1
|
assert len(as_json["updatedItems"]) == 1
|
||||||
assert len(as_json["deletedItems"]) == 0
|
assert len(as_json["deletedItems"]) == 0
|
||||||
@ -456,8 +516,11 @@ def test_shopping_list_items_checked_off(
|
|||||||
assert updated_item["checked"]
|
assert updated_item["checked"]
|
||||||
|
|
||||||
# get the reference item and make sure it didn't change
|
# get the reference item and make sure it didn't change
|
||||||
response = api_client.get(api_routes.groups_shopping_items_item_id(reference_item.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_items_item_id(reference_item.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
reference_item_get = ShoppingListItemOut.model_validate(as_json)
|
reference_item_get = ShoppingListItemOut.model_validate(as_json)
|
||||||
|
|
||||||
assert reference_item_get.id == reference_item.id
|
assert reference_item_get.id == reference_item.id
|
||||||
@ -467,8 +530,11 @@ def test_shopping_list_items_checked_off(
|
|||||||
assert reference_item_get.checked == reference_item.checked
|
assert reference_item_get.checked == reference_item.checked
|
||||||
|
|
||||||
# rename an item to match another item and check both off, and make sure they are not merged
|
# rename an item to match another item and check both off, and make sure they are not merged
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(list_with_items.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(list_with_items.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
updated_list = ShoppingListOut.model_validate(as_json)
|
updated_list = ShoppingListOut.model_validate(as_json)
|
||||||
|
|
||||||
item_1, item_2 = random.sample(updated_list.list_items, 2)
|
item_1, item_2 = random.sample(updated_list.list_items, 2)
|
||||||
@ -482,7 +548,7 @@ def test_shopping_list_items_checked_off(
|
|||||||
headers=unique_user.token,
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
|
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["createdItems"]) == 0
|
assert len(as_json["createdItems"]) == 0
|
||||||
assert len(as_json["updatedItems"]) == 2
|
assert len(as_json["updatedItems"]) == 2
|
||||||
assert len(as_json["deletedItems"]) == 0
|
assert len(as_json["deletedItems"]) == 0
|
||||||
@ -505,14 +571,19 @@ def test_shopping_list_items_with_zero_quantity(
|
|||||||
item["quantity"] = 0
|
item["quantity"] = 0
|
||||||
|
|
||||||
response = api_client.post(
|
response = api_client.post(
|
||||||
api_routes.groups_shopping_items_create_bulk, json=normal_items + zero_qty_items, headers=unique_user.token
|
api_routes.groups_shopping_items_create_bulk,
|
||||||
|
json=normal_items + zero_qty_items,
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
as_json = utils.assert_derserialize(response, 201)
|
as_json = utils.assert_deserialize(response, 201)
|
||||||
assert len(as_json["createdItems"]) == len(normal_items + zero_qty_items)
|
assert len(as_json["createdItems"]) == len(normal_items + zero_qty_items)
|
||||||
|
|
||||||
# confirm the number of items on the list matches
|
# confirm the number of items on the list matches
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
created_items = as_json["listItems"]
|
created_items = as_json["listItems"]
|
||||||
assert len(created_items) == len(normal_items + zero_qty_items)
|
assert len(created_items) == len(normal_items + zero_qty_items)
|
||||||
|
|
||||||
@ -522,8 +593,12 @@ def test_shopping_list_items_with_zero_quantity(
|
|||||||
target_item = random.choice(created_items)
|
target_item = random.choice(created_items)
|
||||||
new_item_to_merge["note"] = target_item["note"]
|
new_item_to_merge["note"] = target_item["note"]
|
||||||
|
|
||||||
response = api_client.post(api_routes.groups_shopping_items, json=new_item_to_merge, headers=unique_user.token)
|
response = api_client.post(
|
||||||
as_json = utils.assert_derserialize(response, 201)
|
api_routes.groups_shopping_items,
|
||||||
|
json=new_item_to_merge,
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 201)
|
||||||
assert len(as_json["createdItems"]) == 0
|
assert len(as_json["createdItems"]) == 0
|
||||||
assert len(as_json["updatedItems"]) == 1
|
assert len(as_json["updatedItems"]) == 1
|
||||||
assert len(as_json["deletedItems"]) == 0
|
assert len(as_json["deletedItems"]) == 0
|
||||||
@ -534,8 +609,11 @@ def test_shopping_list_items_with_zero_quantity(
|
|||||||
assert updated_item["quantity"] == target_item["quantity"]
|
assert updated_item["quantity"] == target_item["quantity"]
|
||||||
|
|
||||||
# confirm the number of items on the list stayed the same
|
# confirm the number of items on the list stayed the same
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["listItems"]) == len(normal_items + zero_qty_items)
|
assert len(as_json["listItems"]) == len(normal_items + zero_qty_items)
|
||||||
|
|
||||||
# update an existing item to zero quantity and make sure it merges into the existing item
|
# update an existing item to zero quantity and make sure it merges into the existing item
|
||||||
@ -548,7 +626,7 @@ def test_shopping_list_items_with_zero_quantity(
|
|||||||
json=update_item_to_merge,
|
json=update_item_to_merge,
|
||||||
headers=unique_user.token,
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["createdItems"]) == 0
|
assert len(as_json["createdItems"]) == 0
|
||||||
assert len(as_json["updatedItems"]) == 1
|
assert len(as_json["updatedItems"]) == 1
|
||||||
assert len(as_json["deletedItems"]) == 1
|
assert len(as_json["deletedItems"]) == 1
|
||||||
@ -560,8 +638,11 @@ def test_shopping_list_items_with_zero_quantity(
|
|||||||
assert updated_item["quantity"] == target_item["quantity"]
|
assert updated_item["quantity"] == target_item["quantity"]
|
||||||
|
|
||||||
# confirm the number of items on the list shrunk by one
|
# confirm the number of items on the list shrunk by one
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["listItems"]) == len(normal_items + zero_qty_items) - 1
|
assert len(as_json["listItems"]) == len(normal_items + zero_qty_items) - 1
|
||||||
|
|
||||||
|
|
||||||
@ -579,7 +660,7 @@ def test_shopping_list_item_extras(
|
|||||||
new_item_data["extras"] = {key_str_1: val_str_1}
|
new_item_data["extras"] = {key_str_1: val_str_1}
|
||||||
|
|
||||||
response = api_client.post(api_routes.groups_shopping_items, json=new_item_data, headers=unique_user.token)
|
response = api_client.post(api_routes.groups_shopping_items, json=new_item_data, headers=unique_user.token)
|
||||||
collection = utils.assert_derserialize(response, 201)
|
collection = utils.assert_deserialize(response, 201)
|
||||||
item_as_json = collection["createdItems"][0]
|
item_as_json = collection["createdItems"][0]
|
||||||
|
|
||||||
# make sure the extra persists
|
# make sure the extra persists
|
||||||
@ -591,9 +672,11 @@ def test_shopping_list_item_extras(
|
|||||||
item_as_json["extras"][key_str_2] = val_str_2
|
item_as_json["extras"][key_str_2] = val_str_2
|
||||||
|
|
||||||
response = api_client.put(
|
response = api_client.put(
|
||||||
api_routes.groups_shopping_items_item_id(item_as_json["id"]), json=item_as_json, headers=unique_user.token
|
api_routes.groups_shopping_items_item_id(item_as_json["id"]),
|
||||||
|
json=item_as_json,
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
collection = utils.assert_derserialize(response, 200)
|
collection = utils.assert_deserialize(response, 200)
|
||||||
item_as_json = collection["updatedItems"][0]
|
item_as_json = collection["updatedItems"][0]
|
||||||
|
|
||||||
# make sure both the new extra and original extra persist
|
# make sure both the new extra and original extra persist
|
||||||
|
@ -12,7 +12,7 @@ from mealie.schema.group.group_shopping_list import (
|
|||||||
from mealie.schema.recipe.recipe import Recipe
|
from mealie.schema.recipe.recipe import Recipe
|
||||||
from tests import utils
|
from tests import utils
|
||||||
from tests.utils import api_routes
|
from tests.utils import api_routes
|
||||||
from tests.utils.assertion_helpers import assert_derserialize
|
from tests.utils.assertion_helpers import assert_deserialize
|
||||||
from tests.utils.factories import random_int, random_string
|
from tests.utils.factories import random_int, random_string
|
||||||
from tests.utils.fixture_schemas import TestUser
|
from tests.utils.fixture_schemas import TestUser
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ def test_shopping_lists_create_one(api_client: TestClient, unique_user: TestUser
|
|||||||
}
|
}
|
||||||
|
|
||||||
response = api_client.post(api_routes.groups_shopping_lists, json=payload, headers=unique_user.token)
|
response = api_client.post(api_routes.groups_shopping_lists, json=payload, headers=unique_user.token)
|
||||||
response_list = utils.assert_derserialize(response, 201)
|
response_list = utils.assert_deserialize(response, 201)
|
||||||
|
|
||||||
assert response_list["name"] == payload["name"]
|
assert response_list["name"] == payload["name"]
|
||||||
assert response_list["groupId"] == str(unique_user.group_id)
|
assert response_list["groupId"] == str(unique_user.group_id)
|
||||||
@ -46,7 +46,10 @@ def test_shopping_lists_create_one(api_client: TestClient, unique_user: TestUser
|
|||||||
def test_shopping_lists_get_one(api_client: TestClient, unique_user: TestUser, shopping_lists: list[ShoppingListOut]):
|
def test_shopping_lists_get_one(api_client: TestClient, unique_user: TestUser, shopping_lists: list[ShoppingListOut]):
|
||||||
shopping_list = shopping_lists[0]
|
shopping_list = shopping_lists[0]
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
response_list = response.json()
|
response_list = response.json()
|
||||||
@ -71,7 +74,9 @@ def test_shopping_lists_update_one(
|
|||||||
}
|
}
|
||||||
|
|
||||||
response = api_client.put(
|
response = api_client.put(
|
||||||
api_routes.groups_shopping_lists_item_id(sample_list.id), json=payload, headers=unique_user.token
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
json=payload,
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
@ -88,10 +93,16 @@ def test_shopping_lists_delete_one(
|
|||||||
):
|
):
|
||||||
sample_list = random.choice(shopping_lists)
|
sample_list = random.choice(shopping_lists)
|
||||||
|
|
||||||
response = api_client.delete(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.delete(
|
||||||
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
assert response.status_code == 404
|
assert response.status_code == 404
|
||||||
|
|
||||||
|
|
||||||
@ -105,13 +116,17 @@ def test_shopping_lists_add_recipe(
|
|||||||
recipe = recipe_ingredient_only
|
recipe = recipe_ingredient_only
|
||||||
|
|
||||||
response = api_client.post(
|
response = api_client.post(
|
||||||
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id), headers=unique_user.token
|
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id),
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
# get list and verify items against ingredients
|
# get list and verify items against ingredients
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
|
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
|
||||||
|
|
||||||
known_ingredients = {ingredient.note: ingredient for ingredient in recipe.recipe_ingredient}
|
known_ingredients = {ingredient.note: ingredient for ingredient in recipe.recipe_ingredient}
|
||||||
@ -129,12 +144,16 @@ def test_shopping_lists_add_recipe(
|
|||||||
|
|
||||||
# add the recipe again and check the resulting items
|
# add the recipe again and check the resulting items
|
||||||
response = api_client.post(
|
response = api_client.post(
|
||||||
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id), headers=unique_user.token
|
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id),
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
|
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
|
||||||
|
|
||||||
for item in as_json["listItems"]:
|
for item in as_json["listItems"]:
|
||||||
@ -158,18 +177,26 @@ def test_shopping_lists_add_one_with_zero_quantity(
|
|||||||
|
|
||||||
# build a recipe that has some ingredients with a null quantity
|
# build a recipe that has some ingredients with a null quantity
|
||||||
response = api_client.post(api_routes.recipes, json={"name": random_string()}, headers=unique_user.token)
|
response = api_client.post(api_routes.recipes, json={"name": random_string()}, headers=unique_user.token)
|
||||||
recipe_slug = utils.assert_derserialize(response, 201)
|
recipe_slug = utils.assert_deserialize(response, 201)
|
||||||
|
|
||||||
response = api_client.get(f"{api_routes.recipes}/{recipe_slug}", headers=unique_user.token)
|
response = api_client.get(f"{api_routes.recipes}/{recipe_slug}", headers=unique_user.token)
|
||||||
recipe_data = utils.assert_derserialize(response, 200)
|
recipe_data = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
ingredient_1 = {"quantity": random_int(1, 10), "note": random_string()}
|
ingredient_1 = {"quantity": random_int(1, 10), "note": random_string()}
|
||||||
ingredient_2 = {"quantity": random_int(1, 10), "note": random_string()}
|
ingredient_2 = {"quantity": random_int(1, 10), "note": random_string()}
|
||||||
ingredient_3_null_qty = {"quantity": None, "note": random_string()}
|
ingredient_3_null_qty = {"quantity": None, "note": random_string()}
|
||||||
|
|
||||||
recipe_data["recipeIngredient"] = [ingredient_1, ingredient_2, ingredient_3_null_qty]
|
recipe_data["recipeIngredient"] = [
|
||||||
response = api_client.put(f"{api_routes.recipes}/{recipe_slug}", json=recipe_data, headers=unique_user.token)
|
ingredient_1,
|
||||||
utils.assert_derserialize(response, 200)
|
ingredient_2,
|
||||||
|
ingredient_3_null_qty,
|
||||||
|
]
|
||||||
|
response = api_client.put(
|
||||||
|
f"{api_routes.recipes}/{recipe_slug}",
|
||||||
|
json=recipe_data,
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
recipe = Recipe.model_validate_json(
|
recipe = Recipe.model_validate_json(
|
||||||
api_client.get(f"{api_routes.recipes}/{recipe_slug}", headers=unique_user.token).content
|
api_client.get(f"{api_routes.recipes}/{recipe_slug}", headers=unique_user.token).content
|
||||||
@ -183,8 +210,11 @@ def test_shopping_lists_add_one_with_zero_quantity(
|
|||||||
headers=unique_user.token,
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
shopping_list_out = ShoppingListOut.model_validate(utils.assert_derserialize(response, 200))
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
shopping_list_out = ShoppingListOut.model_validate(utils.assert_deserialize(response, 200))
|
||||||
|
|
||||||
assert len(shopping_list_out.list_items) == 3
|
assert len(shopping_list_out.list_items) == 3
|
||||||
|
|
||||||
@ -209,7 +239,8 @@ def test_shopping_lists_add_custom_recipe_items(
|
|||||||
recipe = recipe_ingredient_only
|
recipe = recipe_ingredient_only
|
||||||
|
|
||||||
response = api_client.post(
|
response = api_client.post(
|
||||||
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id), headers=unique_user.token
|
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id),
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
@ -222,8 +253,11 @@ def test_shopping_lists_add_custom_recipe_items(
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
# get list and verify items against ingredients
|
# get list and verify items against ingredients
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
|
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
|
||||||
|
|
||||||
known_ingredients = {ingredient.note: ingredient for ingredient in recipe.recipe_ingredient}
|
known_ingredients = {ingredient.note: ingredient for ingredient in recipe.recipe_ingredient}
|
||||||
@ -246,7 +280,10 @@ def test_shopping_lists_add_custom_recipe_items(
|
|||||||
|
|
||||||
|
|
||||||
def test_shopping_list_ref_removes_itself(
|
def test_shopping_list_ref_removes_itself(
|
||||||
api_client: TestClient, unique_user: TestUser, shopping_list: ShoppingListOut, recipe_ingredient_only: Recipe
|
api_client: TestClient,
|
||||||
|
unique_user: TestUser,
|
||||||
|
shopping_list: ShoppingListOut,
|
||||||
|
recipe_ingredient_only: Recipe,
|
||||||
):
|
):
|
||||||
# add a recipe to a list, then check off all recipe items and make sure the recipe ref is deleted
|
# add a recipe to a list, then check off all recipe items and make sure the recipe ref is deleted
|
||||||
recipe = recipe_ingredient_only
|
recipe = recipe_ingredient_only
|
||||||
@ -254,10 +291,13 @@ def test_shopping_list_ref_removes_itself(
|
|||||||
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(shopping_list.id, recipe.id),
|
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(shopping_list.id, recipe.id),
|
||||||
headers=unique_user.token,
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
utils.assert_derserialize(response, 200)
|
utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
shopping_list_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
shopping_list_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(shopping_list_json["listItems"]) == len(recipe.recipe_ingredient)
|
assert len(shopping_list_json["listItems"]) == len(recipe.recipe_ingredient)
|
||||||
assert len(shopping_list_json["recipeReferences"]) == 1
|
assert len(shopping_list_json["recipeReferences"]) == 1
|
||||||
|
|
||||||
@ -265,12 +305,17 @@ def test_shopping_list_ref_removes_itself(
|
|||||||
item["checked"] = True
|
item["checked"] = True
|
||||||
|
|
||||||
response = api_client.put(
|
response = api_client.put(
|
||||||
api_routes.groups_shopping_items, json=shopping_list_json["listItems"], headers=unique_user.token
|
api_routes.groups_shopping_items,
|
||||||
|
json=shopping_list_json["listItems"],
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
utils.assert_derserialize(response, 200)
|
utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
shopping_list_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
shopping_list_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(shopping_list_json["recipeReferences"]) == 0
|
assert len(shopping_list_json["recipeReferences"]) == 0
|
||||||
|
|
||||||
|
|
||||||
@ -283,19 +328,31 @@ def test_shopping_lists_add_recipe_with_merge(
|
|||||||
|
|
||||||
# build a recipe that has some ingredients more than once
|
# build a recipe that has some ingredients more than once
|
||||||
response = api_client.post(api_routes.recipes, json={"name": random_string()}, headers=unique_user.token)
|
response = api_client.post(api_routes.recipes, json={"name": random_string()}, headers=unique_user.token)
|
||||||
recipe_slug = utils.assert_derserialize(response, 201)
|
recipe_slug = utils.assert_deserialize(response, 201)
|
||||||
|
|
||||||
response = api_client.get(f"{api_routes.recipes}/{recipe_slug}", headers=unique_user.token)
|
response = api_client.get(f"{api_routes.recipes}/{recipe_slug}", headers=unique_user.token)
|
||||||
recipe_data = utils.assert_derserialize(response, 200)
|
recipe_data = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
ingredient_1 = {"quantity": random_int(1, 10), "note": random_string()}
|
ingredient_1 = {"quantity": random_int(1, 10), "note": random_string()}
|
||||||
ingredient_2 = {"quantity": random_int(1, 10), "note": random_string()}
|
ingredient_2 = {"quantity": random_int(1, 10), "note": random_string()}
|
||||||
ingredient_duplicate_1 = {"quantity": random_int(1, 10), "note": random_string()}
|
ingredient_duplicate_1 = {"quantity": random_int(1, 10), "note": random_string()}
|
||||||
ingredient_duplicate_2 = {"quantity": random_int(1, 10), "note": ingredient_duplicate_1["note"]}
|
ingredient_duplicate_2 = {
|
||||||
|
"quantity": random_int(1, 10),
|
||||||
|
"note": ingredient_duplicate_1["note"],
|
||||||
|
}
|
||||||
|
|
||||||
recipe_data["recipeIngredient"] = [ingredient_1, ingredient_2, ingredient_duplicate_1, ingredient_duplicate_2]
|
recipe_data["recipeIngredient"] = [
|
||||||
response = api_client.put(f"{api_routes.recipes}/{recipe_slug}", json=recipe_data, headers=unique_user.token)
|
ingredient_1,
|
||||||
utils.assert_derserialize(response, 200)
|
ingredient_2,
|
||||||
|
ingredient_duplicate_1,
|
||||||
|
ingredient_duplicate_2,
|
||||||
|
]
|
||||||
|
response = api_client.put(
|
||||||
|
f"{api_routes.recipes}/{recipe_slug}",
|
||||||
|
json=recipe_data,
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
recipe = Recipe.model_validate_json(
|
recipe = Recipe.model_validate_json(
|
||||||
api_client.get(f"{api_routes.recipes}/{recipe_slug}", headers=unique_user.token).content
|
api_client.get(f"{api_routes.recipes}/{recipe_slug}", headers=unique_user.token).content
|
||||||
@ -309,8 +366,11 @@ def test_shopping_lists_add_recipe_with_merge(
|
|||||||
headers=unique_user.token,
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
shopping_list_out = ShoppingListOut.model_validate(utils.assert_derserialize(response, 200))
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
shopping_list_out = ShoppingListOut.model_validate(utils.assert_deserialize(response, 200))
|
||||||
|
|
||||||
assert len(shopping_list_out.list_items) == 3
|
assert len(shopping_list_out.list_items) == 3
|
||||||
|
|
||||||
@ -350,11 +410,15 @@ def test_shopping_list_add_recipe_scale(
|
|||||||
recipe = recipe_ingredient_only
|
recipe = recipe_ingredient_only
|
||||||
|
|
||||||
response = api_client.post(
|
response = api_client.post(
|
||||||
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id), headers=unique_user.token
|
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(sample_list.id, recipe.id),
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert len(as_json["recipeReferences"]) == 1
|
assert len(as_json["recipeReferences"]) == 1
|
||||||
assert as_json["recipeReferences"][0]["recipeQuantity"] == 1
|
assert as_json["recipeReferences"][0]["recipeQuantity"] == 1
|
||||||
@ -381,8 +445,11 @@ def test_shopping_list_add_recipe_scale(
|
|||||||
json=payload,
|
json=payload,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert len(as_json["recipeReferences"]) == 1
|
assert len(as_json["recipeReferences"]) == 1
|
||||||
assert as_json["recipeReferences"][0]["recipeQuantity"] == 1 + recipe_scale
|
assert as_json["recipeReferences"][0]["recipeQuantity"] == 1 + recipe_scale
|
||||||
@ -422,8 +489,11 @@ def test_shopping_lists_remove_recipe(
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
# get list and verify items against ingredients
|
# get list and verify items against ingredients
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
|
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
|
||||||
|
|
||||||
known_ingredients = {ingredient.note: ingredient for ingredient in recipe.recipe_ingredient}
|
known_ingredients = {ingredient.note: ingredient for ingredient in recipe.recipe_ingredient}
|
||||||
@ -446,8 +516,11 @@ def test_shopping_lists_remove_recipe(
|
|||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
assert len(as_json["listItems"]) == 0
|
assert len(as_json["listItems"]) == 0
|
||||||
assert len(as_json["recipeReferences"]) == 0
|
assert len(as_json["recipeReferences"]) == 0
|
||||||
|
|
||||||
@ -468,8 +541,11 @@ def test_shopping_lists_remove_recipe_multiple_quantity(
|
|||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
|
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
|
||||||
|
|
||||||
@ -485,8 +561,11 @@ def test_shopping_lists_remove_recipe_multiple_quantity(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Get List and Check for Ingredients
|
# Get List and Check for Ingredients
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
# All Items Should Still Exists
|
# All Items Should Still Exists
|
||||||
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
|
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
|
||||||
@ -519,8 +598,11 @@ def test_shopping_list_remove_recipe_scale(
|
|||||||
json=payload,
|
json=payload,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert len(as_json["recipeReferences"]) == 1
|
assert len(as_json["recipeReferences"]) == 1
|
||||||
assert as_json["recipeReferences"][0]["recipeQuantity"] == recipe_initital_scale
|
assert as_json["recipeReferences"][0]["recipeQuantity"] == recipe_initital_scale
|
||||||
@ -544,8 +626,11 @@ def test_shopping_list_remove_recipe_scale(
|
|||||||
json=payload,
|
json=payload,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert len(as_json["recipeReferences"]) == 1
|
assert len(as_json["recipeReferences"]) == 1
|
||||||
assert as_json["recipeReferences"][0]["recipeQuantity"] == recipe_expected_scale
|
assert as_json["recipeReferences"][0]["recipeQuantity"] == recipe_expected_scale
|
||||||
@ -578,8 +663,11 @@ def test_recipe_decrement_max(
|
|||||||
json=payload,
|
json=payload,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert len(as_json["recipeReferences"]) == 1
|
assert len(as_json["recipeReferences"]) == 1
|
||||||
assert as_json["recipeReferences"][0]["recipeQuantity"] == recipe_scale
|
assert as_json["recipeReferences"][0]["recipeQuantity"] == recipe_scale
|
||||||
@ -598,9 +686,11 @@ def test_recipe_decrement_max(
|
|||||||
item_json["quantity"] += item_additional_quantity
|
item_json["quantity"] += item_additional_quantity
|
||||||
|
|
||||||
response = api_client.put(
|
response = api_client.put(
|
||||||
api_routes.groups_shopping_items_item_id(item_json["id"]), json=item_json, headers=unique_user.token
|
api_routes.groups_shopping_items_item_id(item_json["id"]),
|
||||||
|
json=item_json,
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
item_json = as_json["updatedItems"][0]
|
item_json = as_json["updatedItems"][0]
|
||||||
assert item_json["quantity"] == recipe_scale + item_additional_quantity
|
assert item_json["quantity"] == recipe_scale + item_additional_quantity
|
||||||
|
|
||||||
@ -612,8 +702,11 @@ def test_recipe_decrement_max(
|
|||||||
json=payload,
|
json=payload,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
as_json = utils.assert_derserialize(response, 200)
|
api_routes.groups_shopping_lists_item_id(sample_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
# check that only the original recipe quantity and its reference were removed, not the additional quantity
|
# check that only the original recipe quantity and its reference were removed, not the additional quantity
|
||||||
assert len(as_json["recipeReferences"]) == 0
|
assert len(as_json["recipeReferences"]) == 0
|
||||||
@ -633,10 +726,10 @@ def test_recipe_manipulation_with_zero_quantities(
|
|||||||
|
|
||||||
# create a recipe with one item that has a quantity of zero
|
# create a recipe with one item that has a quantity of zero
|
||||||
response = api_client.post(api_routes.recipes, json={"name": random_string()}, headers=unique_user.token)
|
response = api_client.post(api_routes.recipes, json={"name": random_string()}, headers=unique_user.token)
|
||||||
recipe_slug = utils.assert_derserialize(response, 201)
|
recipe_slug = utils.assert_deserialize(response, 201)
|
||||||
|
|
||||||
response = api_client.get(f"{api_routes.recipes}/{recipe_slug}", headers=unique_user.token)
|
response = api_client.get(f"{api_routes.recipes}/{recipe_slug}", headers=unique_user.token)
|
||||||
recipe_data = utils.assert_derserialize(response, 200)
|
recipe_data = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
note_with_zero_quantity = random_string()
|
note_with_zero_quantity = random_string()
|
||||||
recipe_data["recipeIngredient"] = [
|
recipe_data["recipeIngredient"] = [
|
||||||
@ -646,8 +739,12 @@ def test_recipe_manipulation_with_zero_quantities(
|
|||||||
{"quantity": 0, "note": note_with_zero_quantity},
|
{"quantity": 0, "note": note_with_zero_quantity},
|
||||||
]
|
]
|
||||||
|
|
||||||
response = api_client.put(f"{api_routes.recipes}/{recipe_slug}", json=recipe_data, headers=unique_user.token)
|
response = api_client.put(
|
||||||
utils.assert_derserialize(response, 200)
|
f"{api_routes.recipes}/{recipe_slug}",
|
||||||
|
json=recipe_data,
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
recipe = Recipe.model_validate_json(
|
recipe = Recipe.model_validate_json(
|
||||||
api_client.get(f"{api_routes.recipes}/{recipe_slug}", headers=unique_user.token).content
|
api_client.get(f"{api_routes.recipes}/{recipe_slug}", headers=unique_user.token).content
|
||||||
@ -660,15 +757,18 @@ def test_recipe_manipulation_with_zero_quantities(
|
|||||||
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(shopping_list.id, recipe.id),
|
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(shopping_list.id, recipe.id),
|
||||||
headers=unique_user.token,
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
utils.assert_derserialize(response, 200)
|
utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
response = api_client.post(
|
response = api_client.post(
|
||||||
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(shopping_list.id, recipe.id),
|
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(shopping_list.id, recipe.id),
|
||||||
headers=unique_user.token,
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
utils.assert_derserialize(response, 200)
|
utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
updated_list = ShoppingListOut.model_validate_json(response.content)
|
updated_list = ShoppingListOut.model_validate_json(response.content)
|
||||||
assert len(updated_list.list_items) == 4
|
assert len(updated_list.list_items) == 4
|
||||||
|
|
||||||
@ -694,7 +794,10 @@ def test_recipe_manipulation_with_zero_quantities(
|
|||||||
headers=unique_user.token,
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
updated_list = ShoppingListOut.model_validate_json(response.content)
|
updated_list = ShoppingListOut.model_validate_json(response.content)
|
||||||
assert len(updated_list.list_items) == 4
|
assert len(updated_list.list_items) == 4
|
||||||
|
|
||||||
@ -720,7 +823,10 @@ def test_recipe_manipulation_with_zero_quantities(
|
|||||||
headers=unique_user.token,
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
|
response = api_client.get(
|
||||||
|
api_routes.groups_shopping_lists_item_id(shopping_list.id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
updated_list = ShoppingListOut.model_validate_json(response.content)
|
updated_list = ShoppingListOut.model_validate_json(response.content)
|
||||||
assert len(updated_list.list_items) == 0
|
assert len(updated_list.list_items) == 0
|
||||||
|
|
||||||
@ -740,7 +846,7 @@ def test_shopping_list_extras(
|
|||||||
new_list_data["extras"] = {key_str_1: val_str_1}
|
new_list_data["extras"] = {key_str_1: val_str_1}
|
||||||
|
|
||||||
response = api_client.post(api_routes.groups_shopping_lists, json=new_list_data, headers=unique_user.token)
|
response = api_client.post(api_routes.groups_shopping_lists, json=new_list_data, headers=unique_user.token)
|
||||||
list_as_json = utils.assert_derserialize(response, 201)
|
list_as_json = utils.assert_deserialize(response, 201)
|
||||||
|
|
||||||
# make sure the extra persists
|
# make sure the extra persists
|
||||||
extras = list_as_json["extras"]
|
extras = list_as_json["extras"]
|
||||||
@ -751,9 +857,11 @@ def test_shopping_list_extras(
|
|||||||
list_as_json["extras"][key_str_2] = val_str_2
|
list_as_json["extras"][key_str_2] = val_str_2
|
||||||
|
|
||||||
response = api_client.put(
|
response = api_client.put(
|
||||||
api_routes.groups_shopping_lists_item_id(list_as_json["id"]), json=list_as_json, headers=unique_user.token
|
api_routes.groups_shopping_lists_item_id(list_as_json["id"]),
|
||||||
|
json=list_as_json,
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
list_as_json = utils.assert_derserialize(response, 200)
|
list_as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
# make sure both the new extra and original extra persist
|
# make sure both the new extra and original extra persist
|
||||||
extras = list_as_json["extras"]
|
extras = list_as_json["extras"]
|
||||||
@ -764,7 +872,10 @@ def test_shopping_list_extras(
|
|||||||
|
|
||||||
|
|
||||||
def test_modify_shopping_list_items_updates_shopping_list(
|
def test_modify_shopping_list_items_updates_shopping_list(
|
||||||
database: AllRepositories, api_client: TestClient, unique_user: TestUser, shopping_lists: list[ShoppingListOut]
|
database: AllRepositories,
|
||||||
|
api_client: TestClient,
|
||||||
|
unique_user: TestUser,
|
||||||
|
shopping_lists: list[ShoppingListOut],
|
||||||
):
|
):
|
||||||
shopping_list = random.choice(shopping_lists)
|
shopping_list = random.choice(shopping_lists)
|
||||||
last_update_at = shopping_list.update_at
|
last_update_at = shopping_list.update_at
|
||||||
@ -773,7 +884,7 @@ def test_modify_shopping_list_items_updates_shopping_list(
|
|||||||
# Create
|
# Create
|
||||||
new_item_data = {"note": random_string(), "shopping_list_id": str(shopping_list.id)}
|
new_item_data = {"note": random_string(), "shopping_list_id": str(shopping_list.id)}
|
||||||
response = api_client.post(api_routes.groups_shopping_items, json=new_item_data, headers=unique_user.token)
|
response = api_client.post(api_routes.groups_shopping_items, json=new_item_data, headers=unique_user.token)
|
||||||
data = assert_derserialize(response, 201)
|
data = assert_deserialize(response, 201)
|
||||||
updated_list = database.group_shopping_lists.get_one(shopping_list.id)
|
updated_list = database.group_shopping_lists.get_one(shopping_list.id)
|
||||||
assert updated_list and updated_list.update_at
|
assert updated_list and updated_list.update_at
|
||||||
assert updated_list.update_at > last_update_at
|
assert updated_list.update_at > last_update_at
|
||||||
@ -797,7 +908,10 @@ def test_modify_shopping_list_items_updates_shopping_list(
|
|||||||
last_update_at = updated_list.update_at
|
last_update_at = updated_list.update_at
|
||||||
|
|
||||||
# Delete
|
# Delete
|
||||||
response = api_client.delete(api_routes.groups_shopping_items_item_id(list_item_id), headers=unique_user.token)
|
response = api_client.delete(
|
||||||
|
api_routes.groups_shopping_items_item_id(list_item_id),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
updated_list = database.group_shopping_lists.get_one(shopping_list.id)
|
updated_list = database.group_shopping_lists.get_one(shopping_list.id)
|
||||||
assert updated_list and updated_list.update_at
|
assert updated_list and updated_list.update_at
|
||||||
@ -805,7 +919,10 @@ def test_modify_shopping_list_items_updates_shopping_list(
|
|||||||
|
|
||||||
|
|
||||||
def test_bulk_modify_shopping_list_items_updates_shopping_list(
|
def test_bulk_modify_shopping_list_items_updates_shopping_list(
|
||||||
database: AllRepositories, api_client: TestClient, unique_user: TestUser, shopping_lists: list[ShoppingListOut]
|
database: AllRepositories,
|
||||||
|
api_client: TestClient,
|
||||||
|
unique_user: TestUser,
|
||||||
|
shopping_lists: list[ShoppingListOut],
|
||||||
):
|
):
|
||||||
shopping_list = random.choice(shopping_lists)
|
shopping_list = random.choice(shopping_lists)
|
||||||
last_update_at = shopping_list.update_at
|
last_update_at = shopping_list.update_at
|
||||||
@ -816,9 +933,11 @@ def test_bulk_modify_shopping_list_items_updates_shopping_list(
|
|||||||
{"note": random_string(), "shopping_list_id": str(shopping_list.id)} for _ in range(random_int(3, 5))
|
{"note": random_string(), "shopping_list_id": str(shopping_list.id)} for _ in range(random_int(3, 5))
|
||||||
]
|
]
|
||||||
response = api_client.post(
|
response = api_client.post(
|
||||||
api_routes.groups_shopping_items_create_bulk, json=new_item_data, headers=unique_user.token
|
api_routes.groups_shopping_items_create_bulk,
|
||||||
|
json=new_item_data,
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
data = assert_derserialize(response, 201)
|
data = assert_deserialize(response, 201)
|
||||||
updated_list = database.group_shopping_lists.get_one(shopping_list.id)
|
updated_list = database.group_shopping_lists.get_one(shopping_list.id)
|
||||||
assert updated_list and updated_list.update_at
|
assert updated_list and updated_list.update_at
|
||||||
assert updated_list.update_at > last_update_at
|
assert updated_list.update_at > last_update_at
|
||||||
|
@ -3,7 +3,7 @@ from datetime import datetime, timezone
|
|||||||
import pytest
|
import pytest
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
from tests.utils import api_routes, assert_derserialize, jsonify
|
from tests.utils import api_routes, assert_deserialize, jsonify
|
||||||
from tests.utils.fixture_schemas import TestUser
|
from tests.utils.fixture_schemas import TestUser
|
||||||
|
|
||||||
|
|
||||||
@ -19,16 +19,24 @@ def webhook_data():
|
|||||||
|
|
||||||
|
|
||||||
def test_create_webhook(api_client: TestClient, unique_user: TestUser, webhook_data):
|
def test_create_webhook(api_client: TestClient, unique_user: TestUser, webhook_data):
|
||||||
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
|
response = api_client.post(
|
||||||
|
api_routes.groups_webhooks,
|
||||||
|
json=jsonify(webhook_data),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
assert response.status_code == 201
|
assert response.status_code == 201
|
||||||
|
|
||||||
|
|
||||||
def test_read_webhook(api_client: TestClient, unique_user: TestUser, webhook_data):
|
def test_read_webhook(api_client: TestClient, unique_user: TestUser, webhook_data):
|
||||||
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
|
response = api_client.post(
|
||||||
|
api_routes.groups_webhooks,
|
||||||
|
json=jsonify(webhook_data),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
item_id = response.json()["id"]
|
item_id = response.json()["id"]
|
||||||
|
|
||||||
response = api_client.get(api_routes.groups_webhooks_item_id(item_id), headers=unique_user.token)
|
response = api_client.get(api_routes.groups_webhooks_item_id(item_id), headers=unique_user.token)
|
||||||
webhook = assert_derserialize(response, 200)
|
webhook = assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert webhook["id"] == item_id
|
assert webhook["id"] == item_id
|
||||||
assert webhook["name"] == webhook_data["name"]
|
assert webhook["name"] == webhook_data["name"]
|
||||||
@ -38,8 +46,12 @@ def test_read_webhook(api_client: TestClient, unique_user: TestUser, webhook_dat
|
|||||||
|
|
||||||
|
|
||||||
def test_update_webhook(api_client: TestClient, webhook_data, unique_user: TestUser):
|
def test_update_webhook(api_client: TestClient, webhook_data, unique_user: TestUser):
|
||||||
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
|
response = api_client.post(
|
||||||
item_dict = assert_derserialize(response, 201)
|
api_routes.groups_webhooks,
|
||||||
|
json=jsonify(webhook_data),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
item_dict = assert_deserialize(response, 201)
|
||||||
item_id = item_dict["id"]
|
item_id = item_dict["id"]
|
||||||
|
|
||||||
webhook_data["name"] = "My New Name"
|
webhook_data["name"] = "My New Name"
|
||||||
@ -47,9 +59,11 @@ def test_update_webhook(api_client: TestClient, webhook_data, unique_user: TestU
|
|||||||
webhook_data["enabled"] = False
|
webhook_data["enabled"] = False
|
||||||
|
|
||||||
response = api_client.put(
|
response = api_client.put(
|
||||||
api_routes.groups_webhooks_item_id(item_id), json=jsonify(webhook_data), headers=unique_user.token
|
api_routes.groups_webhooks_item_id(item_id),
|
||||||
|
json=jsonify(webhook_data),
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
updated_webhook = assert_derserialize(response, 200)
|
updated_webhook = assert_deserialize(response, 200)
|
||||||
|
|
||||||
assert updated_webhook["name"] == webhook_data["name"]
|
assert updated_webhook["name"] == webhook_data["name"]
|
||||||
assert updated_webhook["url"] == webhook_data["url"]
|
assert updated_webhook["url"] == webhook_data["url"]
|
||||||
@ -57,8 +71,12 @@ def test_update_webhook(api_client: TestClient, webhook_data, unique_user: TestU
|
|||||||
|
|
||||||
|
|
||||||
def test_delete_webhook(api_client: TestClient, webhook_data, unique_user: TestUser):
|
def test_delete_webhook(api_client: TestClient, webhook_data, unique_user: TestUser):
|
||||||
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
|
response = api_client.post(
|
||||||
item_dict = assert_derserialize(response, 201)
|
api_routes.groups_webhooks,
|
||||||
|
json=jsonify(webhook_data),
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
|
item_dict = assert_deserialize(response, 201)
|
||||||
item_id = item_dict["id"]
|
item_id = item_dict["id"]
|
||||||
|
|
||||||
response = api_client.delete(api_routes.groups_webhooks_item_id(item_id), headers=unique_user.token)
|
response = api_client.delete(api_routes.groups_webhooks_item_id(item_id), headers=unique_user.token)
|
||||||
|
@ -53,7 +53,11 @@ def test_update_food(api_client: TestClient, food: dict, unique_user: TestUser):
|
|||||||
"name": random_string(10),
|
"name": random_string(10),
|
||||||
"description": random_string(10),
|
"description": random_string(10),
|
||||||
}
|
}
|
||||||
response = api_client.put(api_routes.foods_item_id(food["id"]), json=update_data, headers=unique_user.token)
|
response = api_client.put(
|
||||||
|
api_routes.foods_item_id(food["id"]),
|
||||||
|
json=update_data,
|
||||||
|
headers=unique_user.token,
|
||||||
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
as_json = response.json()
|
as_json = response.json()
|
||||||
|
|
||||||
@ -88,7 +92,7 @@ def test_food_extras(
|
|||||||
new_food_data["extras"] = {key_str_1: val_str_1}
|
new_food_data["extras"] = {key_str_1: val_str_1}
|
||||||
|
|
||||||
response = api_client.post(api_routes.foods, json=new_food_data, headers=unique_user.token)
|
response = api_client.post(api_routes.foods, json=new_food_data, headers=unique_user.token)
|
||||||
food_as_json = utils.assert_derserialize(response, 201)
|
food_as_json = utils.assert_deserialize(response, 201)
|
||||||
|
|
||||||
# make sure the extra persists
|
# make sure the extra persists
|
||||||
extras = food_as_json["extras"]
|
extras = food_as_json["extras"]
|
||||||
@ -99,9 +103,11 @@ def test_food_extras(
|
|||||||
food_as_json["extras"][key_str_2] = val_str_2
|
food_as_json["extras"][key_str_2] = val_str_2
|
||||||
|
|
||||||
response = api_client.put(
|
response = api_client.put(
|
||||||
api_routes.foods_item_id(food_as_json["id"]), json=food_as_json, headers=unique_user.token
|
api_routes.foods_item_id(food_as_json["id"]),
|
||||||
|
json=food_as_json,
|
||||||
|
headers=unique_user.token,
|
||||||
)
|
)
|
||||||
food_as_json = utils.assert_derserialize(response, 200)
|
food_as_json = utils.assert_deserialize(response, 200)
|
||||||
|
|
||||||
# make sure both the new extra and original extra persist
|
# make sure both the new extra and original extra persist
|
||||||
extras = food_as_json["extras"]
|
extras = food_as_json["extras"]
|
||||||
|
@ -3,7 +3,7 @@ from httpx import Response
|
|||||||
|
|
||||||
def assert_ignore_keys(dict1: dict, dict2: dict, ignore_keys: list | None = None) -> None:
|
def assert_ignore_keys(dict1: dict, dict2: dict, ignore_keys: list | None = None) -> None:
|
||||||
"""
|
"""
|
||||||
Itterates through a list of keys and checks if they are in the the provided ignore_keys list,
|
Iterates through a list of keys and checks if they are in the the provided ignore_keys list,
|
||||||
if they are not in the ignore_keys list, it checks the value of the key in the provided against
|
if they are not in the ignore_keys list, it checks the value of the key in the provided against
|
||||||
the value provided in dict2. If the value of the key in dict1 is not equal to the value of the
|
the value provided in dict2. If the value of the key in dict1 is not equal to the value of the
|
||||||
key in dict2, The assertion fails. Useful for testing id / group_id agnostic data
|
key in dict2, The assertion fails. Useful for testing id / group_id agnostic data
|
||||||
@ -20,6 +20,6 @@ def assert_ignore_keys(dict1: dict, dict2: dict, ignore_keys: list | None = None
|
|||||||
assert value == dict2[key]
|
assert value == dict2[key]
|
||||||
|
|
||||||
|
|
||||||
def assert_derserialize(response: Response, expected_status_code=200) -> dict:
|
def assert_deserialize(response: Response, expected_status_code=200) -> dict:
|
||||||
assert response.status_code == expected_status_code
|
assert response.status_code == expected_status_code
|
||||||
return response.json()
|
return response.json()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user