1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-05 13:35:23 +02:00

fix: Typo, assert_derserialize => assert_deserialize (#3814)

This commit is contained in:
boc-the-git 2024-06-30 01:25:04 +10:00 committed by GitHub
parent bdac51bae2
commit e80ba7dff3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 426 additions and 175 deletions

View file

@ -1,8 +1,12 @@
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 mealie.schema.group.group_recipe_action import (
CreateGroupRecipeAction,
GroupRecipeActionOut,
GroupRecipeActionType,
)
from tests.utils import api_routes, assert_deserialize
from tests.utils.factories import random_int, random_string
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):
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)
response = api_client.post(
api_routes.groups_recipe_actions,
json=action_in.model_dump(),
headers=unique_user.token,
)
data = assert_deserialize(response, 201)
action_out = GroupRecipeActionOut(**data)
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(),
headers=unique_user.token,
)
data = assert_derserialize(response, 201)
data = assert_deserialize(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)
data = assert_deserialize(response, 200)
fetched_ids = set(item["id"] for item in data["items"])
for expected_id in expected_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
):
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)
response = api_client.post(
api_routes.groups_recipe_actions,
json=action_in.model_dump(),
headers=unique_user.token,
)
data = assert_deserialize(response, 201)
expected_action_out = GroupRecipeActionOut(**data)
if is_own_group:
@ -61,27 +73,36 @@ def test_group_recipe_actions_get_one(
fetch_user = g2_user
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:
assert response.status_code == 404
return
data = assert_derserialize(response, 200)
data = assert_deserialize(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)
response = api_client.post(
api_routes.groups_recipe_actions,
json=action_in.model_dump(),
headers=unique_user.token,
)
data = assert_deserialize(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)
response = api_client.put(
api_routes.groups_recipe_actions_item_id(action_id),
json=data,
headers=unique_user.token,
)
data = assert_deserialize(response, 200)
updated_action = GroupRecipeActionOut(**data)
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):
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)
response = api_client.post(
api_routes.groups_recipe_actions,
json=action_in.model_dump(),
headers=unique_user.token,
)
data = assert_deserialize(response, 201)
action_id = data["id"]
response = api_client.delete(api_routes.groups_recipe_actions_item_id(action_id), headers=unique_user.token)

View file

@ -16,7 +16,12 @@ from tests.utils.fixture_schemas import TestUser
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:
@ -38,20 +43,26 @@ def test_shopping_list_items_create_one(
item = create_item(shopping_list.id)
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
# Test Item is Getable
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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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
assert as_json["shoppingListId"] == str(shopping_list.id)
# Test Item In List
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
response_list = utils.assert_derserialize(response, 200)
response = api_client.get(
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
@ -64,16 +75,23 @@ def test_shopping_list_items_create_many(
) -> None:
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)
as_json = utils.assert_derserialize(response, 201)
response = api_client.post(
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["updatedItems"]) == 0
assert len(as_json["deletedItems"]) == 0
# test items in list
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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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
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(
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))
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)
as_json = utils.assert_derserialize(response, 201)
as_json = utils.assert_deserialize(response, 201)
assert len(as_json["createdItems"]) == 1
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(
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})
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))
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
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
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
item_out = ShoppingListItemOut.model_validate(as_json["createdItems"][0])
@ -168,9 +192,13 @@ def test_shopping_list_items_get_all(
unique_user: TestUser,
list_with_items: ShoppingListOut,
) -> 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)
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)
@ -193,9 +221,11 @@ def test_shopping_list_items_update_one(
update_data["id"] = str(item.id)
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["updatedItems"]) == 1
@ -204,8 +234,11 @@ def test_shopping_list_items_update_one(
assert item_json["updatedItems"][0]["quantity"] == update_data["quantity"]
# 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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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)
@ -217,8 +250,12 @@ def test_shopping_list_items_update_many(
for item in items:
item["quantity"] += 10
response = api_client.post(api_routes.groups_shopping_items_create_bulk, json=items, headers=unique_user.token)
as_json = utils.assert_derserialize(response, 201)
response = api_client.post(
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)
# update the items and compare values
@ -227,16 +264,23 @@ def test_shopping_list_items_update_many(
update_item["quantity"] += random_int(-5, 5)
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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.put(
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)
for updated_item in as_json["updatedItems"]:
assert item_quantity_map[updated_item["id"]] == updated_item["quantity"]
# 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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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)
@ -266,8 +310,11 @@ def test_shopping_list_items_update_many_reorder(
assert response.status_code == 200
# 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_list = utils.assert_derserialize(response, 200)
response = api_client.get(
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"]):
assert item_data["position"] == i
@ -306,13 +353,18 @@ def test_shopping_list_items_update_many_consolidates_common_items(
# update list
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
# 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_list = utils.assert_derserialize(response, 200)
response = api_client.get(
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 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
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["updatedItems"]) == 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"]
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
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
# 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)
list_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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"])
@ -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])
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["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
response = api_client.get(api_routes.groups_shopping_lists_item_id(list_with_items.id), headers=unique_user.token)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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"]
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)
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["updatedItems"]) == 1
@ -448,7 +508,7 @@ def test_shopping_list_items_checked_off(
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["updatedItems"]) == 1
assert len(as_json["deletedItems"]) == 0
@ -456,8 +516,11 @@ def test_shopping_list_items_checked_off(
assert updated_item["checked"]
# 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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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)
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
# 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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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)
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,
)
as_json = utils.assert_derserialize(response, 200)
as_json = utils.assert_deserialize(response, 200)
assert len(as_json["createdItems"]) == 0
assert len(as_json["updatedItems"]) == 2
assert len(as_json["deletedItems"]) == 0
@ -505,14 +571,19 @@ def test_shopping_list_items_with_zero_quantity(
item["quantity"] = 0
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)
# 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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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"]
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)
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)
as_json = utils.assert_derserialize(response, 201)
response = api_client.post(
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["updatedItems"]) == 1
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"]
# 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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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)
# 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,
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["updatedItems"]) == 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"]
# 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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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
@ -579,7 +660,7 @@ def test_shopping_list_item_extras(
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)
collection = utils.assert_derserialize(response, 201)
collection = utils.assert_deserialize(response, 201)
item_as_json = collection["createdItems"][0]
# 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
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]
# make sure both the new extra and original extra persist

View file

@ -12,7 +12,7 @@ from mealie.schema.group.group_shopping_list import (
from mealie.schema.recipe.recipe import Recipe
from tests import utils
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.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_list = utils.assert_derserialize(response, 201)
response_list = utils.assert_deserialize(response, 201)
assert response_list["name"] == payload["name"]
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]):
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
response_list = response.json()
@ -71,7 +74,9 @@ def test_shopping_lists_update_one(
}
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
@ -88,10 +93,16 @@ def test_shopping_lists_delete_one(
):
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
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
@ -105,13 +116,17 @@ def test_shopping_lists_add_recipe(
recipe = recipe_ingredient_only
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
# 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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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)
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
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
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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)
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
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)
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_2 = {"quantity": random_int(1, 10), "note": random_string()}
ingredient_3_null_qty = {"quantity": None, "note": random_string()}
recipe_data["recipeIngredient"] = [ingredient_1, 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_derserialize(response, 200)
recipe_data["recipeIngredient"] = [
ingredient_1,
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(
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,
)
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
shopping_list_out = ShoppingListOut.model_validate(utils.assert_derserialize(response, 200))
response = api_client.get(
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
@ -209,7 +239,8 @@ def test_shopping_lists_add_custom_recipe_items(
recipe = recipe_ingredient_only
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
@ -222,8 +253,11 @@ def test_shopping_lists_add_custom_recipe_items(
assert response.status_code == 200
# 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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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)
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(
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
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),
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)
shopping_list_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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["recipeReferences"]) == 1
@ -265,12 +305,17 @@ def test_shopping_list_ref_removes_itself(
item["checked"] = True
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)
shopping_list_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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
@ -283,19 +328,31 @@ def test_shopping_lists_add_recipe_with_merge(
# 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)
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)
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_2 = {"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]
response = api_client.put(f"{api_routes.recipes}/{recipe_slug}", json=recipe_data, headers=unique_user.token)
utils.assert_derserialize(response, 200)
recipe_data["recipeIngredient"] = [
ingredient_1,
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(
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,
)
response = api_client.get(api_routes.groups_shopping_lists_item_id(shopping_list.id), headers=unique_user.token)
shopping_list_out = ShoppingListOut.model_validate(utils.assert_derserialize(response, 200))
response = api_client.get(
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
@ -350,11 +410,15 @@ def test_shopping_list_add_recipe_scale(
recipe = recipe_ingredient_only
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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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 as_json["recipeReferences"][0]["recipeQuantity"] == 1
@ -381,8 +445,11 @@ def test_shopping_list_add_recipe_scale(
json=payload,
)
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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 as_json["recipeReferences"][0]["recipeQuantity"] == 1 + recipe_scale
@ -422,8 +489,11 @@ def test_shopping_lists_remove_recipe(
assert response.status_code == 200
# 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)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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)
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
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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["recipeReferences"]) == 0
@ -468,8 +541,11 @@ def test_shopping_lists_remove_recipe_multiple_quantity(
)
assert response.status_code == 200
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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)
@ -485,8 +561,11 @@ def test_shopping_lists_remove_recipe_multiple_quantity(
)
# Get List and Check for Ingredients
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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
assert len(as_json["listItems"]) == len(recipe.recipe_ingredient)
@ -519,8 +598,11 @@ def test_shopping_list_remove_recipe_scale(
json=payload,
)
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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 as_json["recipeReferences"][0]["recipeQuantity"] == recipe_initital_scale
@ -544,8 +626,11 @@ def test_shopping_list_remove_recipe_scale(
json=payload,
)
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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 as_json["recipeReferences"][0]["recipeQuantity"] == recipe_expected_scale
@ -578,8 +663,11 @@ def test_recipe_decrement_max(
json=payload,
)
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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 as_json["recipeReferences"][0]["recipeQuantity"] == recipe_scale
@ -598,9 +686,11 @@ def test_recipe_decrement_max(
item_json["quantity"] += item_additional_quantity
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]
assert item_json["quantity"] == recipe_scale + item_additional_quantity
@ -612,8 +702,11 @@ def test_recipe_decrement_max(
json=payload,
)
response = api_client.get(api_routes.groups_shopping_lists_item_id(sample_list.id), headers=unique_user.token)
as_json = utils.assert_derserialize(response, 200)
response = api_client.get(
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
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
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)
recipe_data = utils.assert_derserialize(response, 200)
recipe_data = utils.assert_deserialize(response, 200)
note_with_zero_quantity = random_string()
recipe_data["recipeIngredient"] = [
@ -646,8 +739,12 @@ def test_recipe_manipulation_with_zero_quantities(
{"quantity": 0, "note": note_with_zero_quantity},
]
response = api_client.put(f"{api_routes.recipes}/{recipe_slug}", json=recipe_data, headers=unique_user.token)
utils.assert_derserialize(response, 200)
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(
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),
headers=unique_user.token,
)
utils.assert_derserialize(response, 200)
utils.assert_deserialize(response, 200)
response = api_client.post(
api_routes.groups_shopping_lists_item_id_recipe_recipe_id(shopping_list.id, recipe.id),
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)
assert len(updated_list.list_items) == 4
@ -694,7 +794,10 @@ def test_recipe_manipulation_with_zero_quantities(
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)
assert len(updated_list.list_items) == 4
@ -720,7 +823,10 @@ def test_recipe_manipulation_with_zero_quantities(
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)
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}
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
extras = list_as_json["extras"]
@ -751,9 +857,11 @@ def test_shopping_list_extras(
list_as_json["extras"][key_str_2] = val_str_2
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
extras = list_as_json["extras"]
@ -764,7 +872,10 @@ def test_shopping_list_extras(
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)
last_update_at = shopping_list.update_at
@ -773,7 +884,7 @@ def test_modify_shopping_list_items_updates_shopping_list(
# Create
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)
data = assert_derserialize(response, 201)
data = assert_deserialize(response, 201)
updated_list = database.group_shopping_lists.get_one(shopping_list.id)
assert updated_list and updated_list.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
# 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
updated_list = database.group_shopping_lists.get_one(shopping_list.id)
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(
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)
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))
]
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)
assert updated_list and updated_list.update_at
assert updated_list.update_at > last_update_at

View file

@ -3,7 +3,7 @@ from datetime import datetime, timezone
import pytest
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
@ -19,16 +19,24 @@ def 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
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"]
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["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):
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
item_dict = assert_derserialize(response, 201)
response = api_client.post(
api_routes.groups_webhooks,
json=jsonify(webhook_data),
headers=unique_user.token,
)
item_dict = assert_deserialize(response, 201)
item_id = item_dict["id"]
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
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["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):
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
item_dict = assert_derserialize(response, 201)
response = api_client.post(
api_routes.groups_webhooks,
json=jsonify(webhook_data),
headers=unique_user.token,
)
item_dict = assert_deserialize(response, 201)
item_id = item_dict["id"]
response = api_client.delete(api_routes.groups_webhooks_item_id(item_id), headers=unique_user.token)