mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-05 13:35:23 +02:00
feat: Upgrade to Pydantic V2 (#3134)
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Docker Nightly Production / Build Tagged Release (push) Blocked by required conditions
Docker Nightly Production / Notify Discord (push) Blocked by required conditions
Docker Nightly Production / Backend Server Tests (push) Waiting to run
Docker Nightly Production / Frontend and End-to-End Tests (push) Waiting to run
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Docker Nightly Production / Build Tagged Release (push) Blocked by required conditions
Docker Nightly Production / Notify Discord (push) Blocked by required conditions
Docker Nightly Production / Backend Server Tests (push) Waiting to run
Docker Nightly Production / Frontend and End-to-End Tests (push) Waiting to run
* bumped pydantic
This commit is contained in:
parent
248459671e
commit
7a107584c7
129 changed files with 1138 additions and 833 deletions
|
@ -46,7 +46,7 @@ def test_bulk_tag_recipes(
|
|||
for _ in range(3):
|
||||
tag_name = random_string()
|
||||
tag = database.tags.create(TagSave(group_id=unique_user.group_id, name=tag_name))
|
||||
tags.append(tag.dict())
|
||||
tags.append(tag.model_dump())
|
||||
|
||||
payload = {"recipes": ten_slugs, "tags": tags}
|
||||
|
||||
|
@ -74,7 +74,7 @@ def test_bulk_categorize_recipes(
|
|||
for _ in range(3):
|
||||
cat_name = random_string()
|
||||
cat = database.categories.create(CategorySave(group_id=unique_user.group_id, name=cat_name))
|
||||
categories.append(cat.dict())
|
||||
categories.append(cat.model_dump())
|
||||
|
||||
payload = {"recipes": ten_slugs, "categories": categories}
|
||||
|
||||
|
|
|
@ -461,7 +461,7 @@ def test_read_update(
|
|||
|
||||
recipe["notes"] = test_notes
|
||||
|
||||
recipe["recipeCategory"] = [x.dict() for x in recipe_categories]
|
||||
recipe["recipeCategory"] = [x.model_dump() for x in recipe_categories]
|
||||
|
||||
response = api_client.put(recipe_url, json=utils.jsonify(recipe), headers=unique_user.token)
|
||||
|
||||
|
@ -625,7 +625,7 @@ def test_remove_notes(api_client: TestClient, unique_user: TestUser):
|
|||
assert response.status_code == 200
|
||||
|
||||
recipe = json.loads(response.text)
|
||||
recipe["notes"] = [RecipeNote(title=random_string(), text=random_string()).dict()]
|
||||
recipe["notes"] = [RecipeNote(title=random_string(), text=random_string()).model_dump()]
|
||||
response = api_client.put(recipe_url, json=recipe, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ def food(api_client: TestClient, unique_user: TestUser) -> Generator[dict, None,
|
|||
data = CreateIngredientFood(
|
||||
name=random_string(10),
|
||||
description=random_string(10),
|
||||
).dict(by_alias=True)
|
||||
).model_dump(by_alias=True)
|
||||
|
||||
response = api_client.post(api_routes.foods, json=data, headers=unique_user.token)
|
||||
|
||||
|
@ -30,7 +30,7 @@ def test_create_food(api_client: TestClient, unique_user: TestUser):
|
|||
data = CreateIngredientFood(
|
||||
name=random_string(10),
|
||||
description=random_string(10),
|
||||
).dict(by_alias=True)
|
||||
).model_dump(by_alias=True)
|
||||
|
||||
response = api_client.post(api_routes.foods, json=data, headers=unique_user.token)
|
||||
assert response.status_code == 201
|
||||
|
|
|
@ -26,7 +26,7 @@ def test_associate_ingredient_with_step(api_client: TestClient, unique_user: Tes
|
|||
|
||||
response = api_client.put(
|
||||
api_routes.recipes_slug(recipe.slug),
|
||||
json=jsonify(recipe.dict()),
|
||||
json=jsonify(recipe.model_dump()),
|
||||
headers=unique_user.token,
|
||||
)
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ def recipes(api_client: TestClient, unique_user: TestUser):
|
|||
response = api_client.get(f"{api_routes.recipes}/{slug}", headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
recipe = Recipe.parse_obj(response.json())
|
||||
recipe = Recipe.model_validate(response.json())
|
||||
recipes.append(recipe)
|
||||
|
||||
yield recipes
|
||||
|
@ -52,7 +52,7 @@ def test_create_timeline_event(api_client: TestClient, unique_user: TestUser, re
|
|||
)
|
||||
assert event_response.status_code == 201
|
||||
|
||||
event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
event = RecipeTimelineEventOut.model_validate(event_response.json())
|
||||
assert event.recipe_id == recipe.id
|
||||
assert str(event.user_id) == str(unique_user.user_id)
|
||||
|
||||
|
@ -77,13 +77,13 @@ def test_get_all_timeline_events(api_client: TestClient, unique_user: TestUser,
|
|||
event_response = api_client.post(
|
||||
api_routes.recipes_timeline_events, params=params, json=event_data, headers=unique_user.token
|
||||
)
|
||||
events.append(RecipeTimelineEventOut.parse_obj(event_response.json()))
|
||||
events.append(RecipeTimelineEventOut.model_validate(event_response.json()))
|
||||
|
||||
# check that we see them all
|
||||
params = {"page": 1, "perPage": -1}
|
||||
|
||||
events_response = api_client.get(api_routes.recipes_timeline_events, params=params, headers=unique_user.token)
|
||||
events_pagination = RecipeTimelineEventPagination.parse_obj(events_response.json())
|
||||
events_pagination = RecipeTimelineEventPagination.model_validate(events_response.json())
|
||||
|
||||
event_ids = [event.id for event in events]
|
||||
paginated_event_ids = [event.id for event in events_pagination.items]
|
||||
|
@ -109,13 +109,13 @@ def test_get_timeline_event(api_client: TestClient, unique_user: TestUser, recip
|
|||
json=new_event_data,
|
||||
headers=unique_user.token,
|
||||
)
|
||||
new_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
new_event = RecipeTimelineEventOut.model_validate(event_response.json())
|
||||
|
||||
# fetch the new event
|
||||
event_response = api_client.get(api_routes.recipes_timeline_events_item_id(new_event.id), headers=unique_user.token)
|
||||
assert event_response.status_code == 200
|
||||
|
||||
event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
event = RecipeTimelineEventOut.model_validate(event_response.json())
|
||||
assert event == new_event
|
||||
|
||||
|
||||
|
@ -133,7 +133,7 @@ def test_update_timeline_event(api_client: TestClient, unique_user: TestUser, re
|
|||
}
|
||||
|
||||
event_response = api_client.post(api_routes.recipes_timeline_events, json=new_event_data, headers=unique_user.token)
|
||||
new_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
new_event = RecipeTimelineEventOut.model_validate(event_response.json())
|
||||
assert new_event.subject == old_subject
|
||||
|
||||
# update the event
|
||||
|
@ -146,7 +146,7 @@ def test_update_timeline_event(api_client: TestClient, unique_user: TestUser, re
|
|||
)
|
||||
assert event_response.status_code == 200
|
||||
|
||||
updated_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
updated_event = RecipeTimelineEventOut.model_validate(event_response.json())
|
||||
assert updated_event.id == new_event.id
|
||||
assert updated_event.subject == new_subject
|
||||
assert updated_event.timestamp == new_event.timestamp
|
||||
|
@ -164,7 +164,7 @@ def test_delete_timeline_event(api_client: TestClient, unique_user: TestUser, re
|
|||
}
|
||||
|
||||
event_response = api_client.post(api_routes.recipes_timeline_events, json=new_event_data, headers=unique_user.token)
|
||||
new_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
new_event = RecipeTimelineEventOut.model_validate(event_response.json())
|
||||
|
||||
# delete the event
|
||||
event_response = api_client.delete(
|
||||
|
@ -172,7 +172,7 @@ def test_delete_timeline_event(api_client: TestClient, unique_user: TestUser, re
|
|||
)
|
||||
assert event_response.status_code == 200
|
||||
|
||||
deleted_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
deleted_event = RecipeTimelineEventOut.model_validate(event_response.json())
|
||||
assert deleted_event.id == new_event.id
|
||||
|
||||
# try to get the event
|
||||
|
@ -198,7 +198,7 @@ def test_timeline_event_message_alias(api_client: TestClient, unique_user: TestU
|
|||
json=new_event_data,
|
||||
headers=unique_user.token,
|
||||
)
|
||||
new_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
new_event = RecipeTimelineEventOut.model_validate(event_response.json())
|
||||
assert str(new_event.user_id) == new_event_data["userId"]
|
||||
assert str(new_event.event_type) == new_event_data["eventType"]
|
||||
assert new_event.message == new_event_data["eventMessage"]
|
||||
|
@ -207,7 +207,7 @@ def test_timeline_event_message_alias(api_client: TestClient, unique_user: TestU
|
|||
event_response = api_client.get(api_routes.recipes_timeline_events_item_id(new_event.id), headers=unique_user.token)
|
||||
assert event_response.status_code == 200
|
||||
|
||||
event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
event = RecipeTimelineEventOut.model_validate(event_response.json())
|
||||
assert event == new_event
|
||||
|
||||
# update the event message
|
||||
|
@ -222,7 +222,7 @@ def test_timeline_event_message_alias(api_client: TestClient, unique_user: TestU
|
|||
)
|
||||
assert event_response.status_code == 200
|
||||
|
||||
updated_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
updated_event = RecipeTimelineEventOut.model_validate(event_response.json())
|
||||
assert updated_event.subject == new_subject
|
||||
assert updated_event.message == new_message
|
||||
|
||||
|
@ -241,7 +241,7 @@ def test_timeline_event_update_image(
|
|||
}
|
||||
|
||||
event_response = api_client.post(api_routes.recipes_timeline_events, json=new_event_data, headers=unique_user.token)
|
||||
new_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
new_event = RecipeTimelineEventOut.model_validate(event_response.json())
|
||||
assert new_event.image == TimelineEventImage.does_not_have_image.value
|
||||
|
||||
with open(test_image_jpg, "rb") as f:
|
||||
|
@ -253,7 +253,7 @@ def test_timeline_event_update_image(
|
|||
)
|
||||
r.raise_for_status()
|
||||
|
||||
update_image_response = UpdateImageResponse.parse_obj(r.json())
|
||||
update_image_response = UpdateImageResponse.model_validate(r.json())
|
||||
assert update_image_response.image == TimelineEventImage.has_image.value
|
||||
|
||||
event_response = api_client.get(
|
||||
|
@ -262,7 +262,7 @@ def test_timeline_event_update_image(
|
|||
)
|
||||
assert event_response.status_code == 200
|
||||
|
||||
updated_event = RecipeTimelineEventOut.parse_obj(event_response.json())
|
||||
updated_event = RecipeTimelineEventOut.model_validate(event_response.json())
|
||||
assert updated_event.subject == new_event.subject
|
||||
assert updated_event.message == new_event.message
|
||||
assert updated_event.timestamp == new_event.timestamp
|
||||
|
@ -274,7 +274,7 @@ def test_create_recipe_with_timeline_event(api_client: TestClient, unique_user:
|
|||
for recipe in recipes:
|
||||
params = {"queryFilter": f"recipe_id={recipe.id}"}
|
||||
events_response = api_client.get(api_routes.recipes_timeline_events, params=params, headers=unique_user.token)
|
||||
events_pagination = RecipeTimelineEventPagination.parse_obj(events_response.json())
|
||||
events_pagination = RecipeTimelineEventPagination.model_validate(events_response.json())
|
||||
assert events_pagination.items
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ def unit(api_client: TestClient, unique_user: TestUser):
|
|||
fraction=random_bool(),
|
||||
abbreviation=f"{random_string(3)}.",
|
||||
use_abbreviation=random_bool(),
|
||||
).dict(by_alias=True)
|
||||
).model_dump(by_alias=True)
|
||||
|
||||
response = api_client.post(api_routes.units, json=data, headers=unique_user.token)
|
||||
|
||||
|
@ -30,7 +30,7 @@ def test_create_unit(api_client: TestClient, unique_user: TestUser):
|
|||
data = CreateIngredientUnit(
|
||||
name=random_string(10),
|
||||
description=random_string(10),
|
||||
).dict(by_alias=True)
|
||||
).model_dump(by_alias=True)
|
||||
|
||||
response = api_client.post(api_routes.units, json=data, headers=unique_user.token)
|
||||
assert response.status_code == 201
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue