1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-05 21:45:25 +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

* bumped pydantic
This commit is contained in:
Michael Genson 2024-02-11 10:47:37 -06:00 committed by GitHub
parent 248459671e
commit 7a107584c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
129 changed files with 1138 additions and 833 deletions

View file

@ -135,14 +135,14 @@ def test_pagination_guides(database: AllRepositories, unique_user: TestUser):
query = PaginationQuery(page=1, per_page=1)
first_page_of_results = foods_repo.page_all(query)
first_page_of_results.set_pagination_guides(foods_route, query.dict())
first_page_of_results.set_pagination_guides(foods_route, query.model_dump())
assert first_page_of_results.next is not None
assert first_page_of_results.previous is None
query = PaginationQuery(page=-1, per_page=1)
last_page_of_results = foods_repo.page_all(query)
last_page_of_results.set_pagination_guides(foods_route, query.dict())
last_page_of_results.set_pagination_guides(foods_route, query.model_dump())
assert last_page_of_results.next is None
assert last_page_of_results.previous is not None
@ -150,7 +150,7 @@ def test_pagination_guides(database: AllRepositories, unique_user: TestUser):
query = PaginationQuery(page=random_page, per_page=1, filter_string="createdAt>2021-02-22")
random_page_of_results = foods_repo.page_all(query)
random_page_of_results.set_pagination_guides(foods_route, query.dict())
random_page_of_results.set_pagination_guides(foods_route, query.model_dump())
next_params: dict = dict(parse_qsl(urlsplit(random_page_of_results.next).query)) # type: ignore
assert int(next_params["page"]) == random_page + 1
@ -158,7 +158,7 @@ def test_pagination_guides(database: AllRepositories, unique_user: TestUser):
prev_params: dict = dict(parse_qsl(urlsplit(random_page_of_results.previous).query)) # type: ignore
assert int(prev_params["page"]) == random_page - 1
source_params = camelize(query.dict())
source_params = camelize(query.model_dump())
for source_param in source_params:
assert source_param in next_params
assert source_param in prev_params
@ -835,7 +835,7 @@ def test_pagination_filter_dates(api_client: TestClient, unique_user: TestUser):
)
for mealplan_to_create in [mealplan_today, mealplan_tomorrow]:
data = mealplan_to_create.dict()
data = mealplan_to_create.model_dump()
data["date"] = data["date"].strftime("%Y-%m-%d")
response = api_client.post(api_routes.groups_mealplans, json=data, headers=unique_user.token)
assert response.status_code == 201

View file

@ -17,7 +17,7 @@ class TestModel2(MealieModel):
def test_camelize_variables():
model = TestModel(long_name="Hello", long_int=1, long_float=1.1)
as_dict = model.dict(by_alias=True)
as_dict = model.model_dump(by_alias=True)
assert as_dict["longName"] == "Hello"
assert as_dict["longInt"] == 1

View file

@ -24,7 +24,7 @@ def test_new_mealplan_event(api_client: TestClient, unique_user: TestUser):
response = api_client.get(api_routes.recipes_slug(recipe_name), headers=unique_user.token)
original_recipe_data: dict = response.json()
recipe = RecipeSummary.parse_obj(original_recipe_data)
recipe = RecipeSummary.model_validate(original_recipe_data)
recipe_id = recipe.id
assert recipe.last_made is None
@ -34,7 +34,7 @@ def test_new_mealplan_event(api_client: TestClient, unique_user: TestUser):
response_json = response.json()
initial_event_count = len(response_json["items"])
new_plan = CreatePlanEntry(date=date.today(), entry_type="dinner", recipe_id=recipe_id).dict(by_alias=True)
new_plan = CreatePlanEntry(date=date.today(), entry_type="dinner", recipe_id=recipe_id).model_dump(by_alias=True)
new_plan["date"] = date.today().isoformat()
new_plan["recipeId"] = str(recipe_id)
@ -62,7 +62,7 @@ def test_new_mealplan_event(api_client: TestClient, unique_user: TestUser):
# make sure the recipe's last made date was updated
response = api_client.get(api_routes.recipes_slug(recipe_name), headers=unique_user.token)
new_recipe_data: dict = response.json()
recipe = RecipeSummary.parse_obj(new_recipe_data)
recipe = RecipeSummary.model_validate(new_recipe_data)
assert recipe.last_made.date() == date.today() # type: ignore
# make sure nothing else was updated
@ -90,7 +90,7 @@ def test_new_mealplan_event_duplicates(api_client: TestClient, unique_user: Test
assert response.status_code == 201
response = api_client.get(api_routes.recipes_slug(recipe_name), headers=unique_user.token)
recipe = RecipeSummary.parse_obj(response.json())
recipe = RecipeSummary.model_validate(response.json())
recipe_id = recipe.id
# store the number of events, so we can compare later
@ -99,7 +99,7 @@ def test_new_mealplan_event_duplicates(api_client: TestClient, unique_user: Test
response_json = response.json()
initial_event_count = len(response_json["items"])
new_plan = CreatePlanEntry(date=date.today(), entry_type="dinner", recipe_id=recipe_id).dict(by_alias=True)
new_plan = CreatePlanEntry(date=date.today(), entry_type="dinner", recipe_id=recipe_id).model_dump(by_alias=True)
new_plan["date"] = date.today().isoformat()
new_plan["recipeId"] = str(recipe_id)
@ -130,7 +130,7 @@ def test_new_mealplan_events_with_multiple_recipes(api_client: TestClient, uniqu
assert response.status_code == 201
response = api_client.get(api_routes.recipes_slug(recipe_name), headers=unique_user.token)
recipes.append(RecipeSummary.parse_obj(response.json()))
recipes.append(RecipeSummary.model_validate(response.json()))
# store the number of events, so we can compare later
params = {"queryFilter": f"recipe_id={recipes[0].id}"}
@ -143,7 +143,7 @@ def test_new_mealplan_events_with_multiple_recipes(api_client: TestClient, uniqu
for recipe in recipes:
mealplan_count_by_recipe_id[recipe.id] = 0 # type: ignore
for _ in range(random_int(1, 5)):
new_plan = CreatePlanEntry(date=date.today(), entry_type="dinner", recipe_id=str(recipe.id)).dict(
new_plan = CreatePlanEntry(date=date.today(), entry_type="dinner", recipe_id=str(recipe.id)).model_dump(
by_alias=True
)
new_plan["date"] = date.today().isoformat()
@ -193,7 +193,7 @@ def test_preserve_future_made_date(api_client: TestClient, unique_user: TestUser
assert response.status_code == 201
response = api_client.get(api_routes.recipes_slug(recipe_name), headers=unique_user.token)
recipe = RecipeSummary.parse_obj(response.json())
recipe = RecipeSummary.model_validate(response.json())
recipe_id = str(recipe.id)
future_dt = datetime.now() + timedelta(days=random_int(1, 10))
@ -203,7 +203,7 @@ def test_preserve_future_made_date(api_client: TestClient, unique_user: TestUser
)
assert response.status_code == 200
new_plan = CreatePlanEntry(date=date.today(), entry_type="dinner", recipe_id=recipe_id).dict(by_alias=True)
new_plan = CreatePlanEntry(date=date.today(), entry_type="dinner", recipe_id=recipe_id).model_dump(by_alias=True)
new_plan["date"] = date.today().isoformat()
new_plan["recipeId"] = str(recipe_id)
@ -214,5 +214,5 @@ def test_preserve_future_made_date(api_client: TestClient, unique_user: TestUser
create_mealplan_timeline_events()
response = api_client.get(api_routes.recipes_slug(recipe_name), headers=unique_user.token)
recipe = RecipeSummary.parse_obj(response.json())
recipe = RecipeSummary.model_validate(response.json())
assert recipe.last_made == future_dt

View file

@ -7,8 +7,8 @@ from tests.utils.alembic_reader import ALEMBIC_MIGRATIONS, import_file
class AlembicMigration(BaseModel):
path: pathlib.Path
revision: str | None
down_revision: str | None
revision: str | None = None
down_revision: str | None = None
def test_alembic_revisions_are_in_order() -> None: