mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 07:39:41 +02:00
chore: remove black (#3437)
This commit is contained in:
parent
94678fe6e0
commit
9e6ae2e514
10 changed files with 189 additions and 133 deletions
|
@ -22,9 +22,17 @@ from mealie.schema.labels.multi_purpose_label import MultiPurposeLabelSave
|
|||
from mealie.schema.meal_plan.new_meal import CreatePlanEntry
|
||||
from mealie.schema.recipe import Recipe
|
||||
from mealie.schema.recipe.recipe_category import CategorySave, TagSave
|
||||
from mealie.schema.recipe.recipe_ingredient import IngredientUnit, SaveIngredientFood, SaveIngredientUnit
|
||||
from mealie.schema.recipe.recipe_ingredient import (
|
||||
IngredientUnit,
|
||||
SaveIngredientFood,
|
||||
SaveIngredientUnit,
|
||||
)
|
||||
from mealie.schema.recipe.recipe_tool import RecipeToolSave
|
||||
from mealie.schema.response.pagination import OrderByNullPosition, OrderDirection, PaginationQuery
|
||||
from mealie.schema.response.pagination import (
|
||||
OrderByNullPosition,
|
||||
OrderDirection,
|
||||
PaginationQuery,
|
||||
)
|
||||
from mealie.services.seeder.seeder_service import SeederService
|
||||
from tests.utils import api_routes
|
||||
from tests.utils.factories import random_int, random_string
|
||||
|
@ -205,16 +213,27 @@ def test_pagination_filter_basic(query_units: tuple[RepositoryUnit, IngredientUn
|
|||
|
||||
def test_pagination_filter_null(database: AllRepositories, unique_user: TestUser):
|
||||
recipe_not_made_1 = database.recipes.create(
|
||||
Recipe(user_id=unique_user.user_id, group_id=unique_user.group_id, name=random_string())
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=unique_user.group_id,
|
||||
name=random_string(),
|
||||
)
|
||||
)
|
||||
recipe_not_made_2 = database.recipes.create(
|
||||
Recipe(user_id=unique_user.user_id, group_id=unique_user.group_id, name=random_string())
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=unique_user.group_id,
|
||||
name=random_string(),
|
||||
)
|
||||
)
|
||||
|
||||
# give one recipe a last made date
|
||||
recipe_made = database.recipes.create(
|
||||
Recipe(
|
||||
user_id=unique_user.user_id, group_id=unique_user.group_id, name=random_string(), last_made=datetime.now()
|
||||
user_id=unique_user.user_id,
|
||||
group_id=unique_user.group_id,
|
||||
name=random_string(),
|
||||
last_made=datetime.now(),
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -294,22 +313,46 @@ def test_pagination_filter_in_advanced(database: AllRepositories, unique_user: T
|
|||
# Bootstrap the database with recipes
|
||||
slug = random_string()
|
||||
recipe_0 = database.recipes.create(
|
||||
Recipe(user_id=unique_user.user_id, group_id=unique_user.group_id, name=slug, slug=slug, tags=[])
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=unique_user.group_id,
|
||||
name=slug,
|
||||
slug=slug,
|
||||
tags=[],
|
||||
)
|
||||
)
|
||||
|
||||
slug = random_string()
|
||||
recipe_1 = database.recipes.create(
|
||||
Recipe(user_id=unique_user.user_id, group_id=unique_user.group_id, name=slug, slug=slug, tags=[tag_1])
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=unique_user.group_id,
|
||||
name=slug,
|
||||
slug=slug,
|
||||
tags=[tag_1],
|
||||
)
|
||||
)
|
||||
|
||||
slug = random_string()
|
||||
recipe_2 = database.recipes.create(
|
||||
Recipe(user_id=unique_user.user_id, group_id=unique_user.group_id, name=slug, slug=slug, tags=[tag_2])
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=unique_user.group_id,
|
||||
name=slug,
|
||||
slug=slug,
|
||||
tags=[tag_2],
|
||||
)
|
||||
)
|
||||
|
||||
slug = random_string()
|
||||
recipe_1_2 = database.recipes.create(
|
||||
Recipe(user_id=unique_user.user_id, group_id=unique_user.group_id, name=slug, slug=slug, tags=[tag_1, tag_2])
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=unique_user.group_id,
|
||||
name=slug,
|
||||
slug=slug,
|
||||
tags=[tag_1, tag_2],
|
||||
)
|
||||
)
|
||||
|
||||
query = PaginationQuery(page=1, per_page=-1, query_filter=f"tags.name IN [{tag_1.name}]")
|
||||
|
@ -330,7 +373,11 @@ def test_pagination_filter_in_advanced(database: AllRepositories, unique_user: T
|
|||
assert recipe_2.id in recipe_ids
|
||||
assert recipe_1_2.id in recipe_ids
|
||||
|
||||
query = PaginationQuery(page=1, per_page=-1, query_filter=f"tags.name CONTAINS ALL [{tag_1.name}, {tag_2.name}]")
|
||||
query = PaginationQuery(
|
||||
page=1,
|
||||
per_page=-1,
|
||||
query_filter=f"tags.name CONTAINS ALL [{tag_1.name}, {tag_2.name}]",
|
||||
)
|
||||
recipe_results = database.recipes.page_all(query).items
|
||||
assert len(recipe_results) == 1
|
||||
recipe_ids = {recipe.id for recipe in recipe_results}
|
||||
|
@ -373,14 +420,29 @@ def test_pagination_filter_like(query_units: tuple[RepositoryUnit, IngredientUni
|
|||
|
||||
def test_pagination_filter_keyword_namespace_conflict(database: AllRepositories, unique_user: TestUser):
|
||||
recipe_rating_1 = database.recipes.create(
|
||||
Recipe(user_id=unique_user.user_id, group_id=unique_user.group_id, name=random_string(), rating=1)
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=unique_user.group_id,
|
||||
name=random_string(),
|
||||
rating=1,
|
||||
)
|
||||
)
|
||||
recipe_rating_2 = database.recipes.create(
|
||||
Recipe(user_id=unique_user.user_id, group_id=unique_user.group_id, name=random_string(), rating=2)
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=unique_user.group_id,
|
||||
name=random_string(),
|
||||
rating=2,
|
||||
)
|
||||
)
|
||||
|
||||
recipe_rating_3 = database.recipes.create(
|
||||
Recipe(user_id=unique_user.user_id, group_id=unique_user.group_id, name=random_string(), rating=3)
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=unique_user.group_id,
|
||||
name=random_string(),
|
||||
rating=3,
|
||||
)
|
||||
)
|
||||
|
||||
recipe_repo = database.recipes.by_group(unique_user.group_id) # type: ignore
|
||||
|
@ -415,7 +477,12 @@ def test_pagination_filter_logical_namespace_conflict(database: AllRepositories,
|
|||
# Bootstrap the database with recipes
|
||||
slug = random_string()
|
||||
recipe_category_0 = database.recipes.create(
|
||||
Recipe(user_id=unique_user.user_id, group_id=unique_user.group_id, name=slug, slug=slug)
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=unique_user.group_id,
|
||||
name=slug,
|
||||
slug=slug,
|
||||
)
|
||||
)
|
||||
|
||||
slug = random_string()
|
||||
|
@ -451,7 +518,7 @@ def test_pagination_filter_logical_namespace_conflict(database: AllRepositories,
|
|||
|
||||
|
||||
def test_pagination_filter_datetimes(
|
||||
query_units: tuple[RepositoryUnit, IngredientUnit, IngredientUnit, IngredientUnit]
|
||||
query_units: tuple[RepositoryUnit, IngredientUnit, IngredientUnit, IngredientUnit],
|
||||
):
|
||||
# units are created in order with increasing createdAt values
|
||||
units_repo, unit_1, unit_2, unit_3 = query_units
|
||||
|
@ -544,7 +611,11 @@ def test_pagination_filter_datetimes(
|
|||
assert len(unit_ids) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("order_direction", [OrderDirection.asc, OrderDirection.desc], ids=["ascending", "descending"])
|
||||
@pytest.mark.parametrize(
|
||||
"order_direction",
|
||||
[OrderDirection.asc, OrderDirection.desc],
|
||||
ids=["ascending", "descending"],
|
||||
)
|
||||
def test_pagination_order_by_multiple(
|
||||
database: AllRepositories, unique_user: TestUser, order_direction: OrderDirection
|
||||
):
|
||||
|
@ -571,7 +642,10 @@ def test_pagination_order_by_multiple(
|
|||
)
|
||||
|
||||
sorted_units = database.ingredient_units.create_many(units_to_create)
|
||||
sorted_units.sort(key=lambda x: (x.abbreviation, x.description), reverse=order_direction is OrderDirection.desc)
|
||||
sorted_units.sort(
|
||||
key=lambda x: (x.abbreviation, x.description),
|
||||
reverse=order_direction is OrderDirection.desc,
|
||||
)
|
||||
|
||||
query = database.ingredient_units.page_all(
|
||||
PaginationQuery(
|
||||
|
@ -602,7 +676,10 @@ def test_pagination_order_by_multiple(
|
|||
],
|
||||
)
|
||||
def test_pagination_order_by_multiple_directions(
|
||||
database: AllRepositories, unique_user: TestUser, order_by_str: str, order_direction: OrderDirection
|
||||
database: AllRepositories,
|
||||
unique_user: TestUser,
|
||||
order_by_str: str,
|
||||
order_direction: OrderDirection,
|
||||
):
|
||||
current_time = datetime.now()
|
||||
|
||||
|
@ -695,7 +772,11 @@ def test_pagination_order_by_doesnt_filter(database: AllRepositories, unique_use
|
|||
)
|
||||
|
||||
query = database.ingredient_foods.by_group(unique_user.group_id).page_all(
|
||||
PaginationQuery(per_page=-1, query_filter=f"created_at>{current_time.isoformat()}", order_by="label.name")
|
||||
PaginationQuery(
|
||||
per_page=-1,
|
||||
query_filter=f"created_at>{current_time.isoformat()}",
|
||||
order_by="label.name",
|
||||
)
|
||||
)
|
||||
assert len(query.items) == 2
|
||||
found_ids = {item.id for item in query.items}
|
||||
|
@ -758,7 +839,11 @@ def test_pagination_order_by_nulls(
|
|||
def test_pagination_shopping_list_items_with_labels(database: AllRepositories, unique_user: TestUser):
|
||||
# create a shopping list and populate it with some items with labels, and some without labels
|
||||
shopping_list = database.group_shopping_lists.create(
|
||||
ShoppingListSave(name=random_string(), group_id=unique_user.group_id, user_id=unique_user.user_id)
|
||||
ShoppingListSave(
|
||||
name=random_string(),
|
||||
group_id=unique_user.group_id,
|
||||
user_id=unique_user.user_id,
|
||||
)
|
||||
)
|
||||
|
||||
labels = database.group_multi_purpose_labels.create_many(
|
||||
|
@ -831,7 +916,10 @@ def test_pagination_filter_dates(api_client: TestClient, unique_user: TestUser):
|
|||
|
||||
mealplan_today = CreatePlanEntry(date=today, entry_type="breakfast", title=random_string(), text=random_string())
|
||||
mealplan_tomorrow = CreatePlanEntry(
|
||||
date=tomorrow, entry_type="breakfast", title=random_string(), text=random_string()
|
||||
date=tomorrow,
|
||||
entry_type="breakfast",
|
||||
title=random_string(),
|
||||
text=random_string(),
|
||||
)
|
||||
|
||||
for mealplan_to_create in [mealplan_today, mealplan_tomorrow]:
|
||||
|
@ -841,7 +929,11 @@ def test_pagination_filter_dates(api_client: TestClient, unique_user: TestUser):
|
|||
assert response.status_code == 201
|
||||
|
||||
## Yesterday
|
||||
params = {f"page": 1, "perPage": -1, "queryFilter": f"date >= {yesterday.strftime('%Y-%m-%d')}"}
|
||||
params = {
|
||||
f"page": 1,
|
||||
"perPage": -1,
|
||||
"queryFilter": f"date >= {yesterday.strftime('%Y-%m-%d')}",
|
||||
}
|
||||
response = api_client.get(api_routes.groups_mealplans, params=params, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
|
@ -851,7 +943,11 @@ def test_pagination_filter_dates(api_client: TestClient, unique_user: TestUser):
|
|||
assert mealplan_today.title in fetched_mealplan_titles
|
||||
assert mealplan_tomorrow.title in fetched_mealplan_titles
|
||||
|
||||
params = {f"page": 1, "perPage": -1, "queryFilter": f"date > {yesterday.strftime('%Y-%m-%d')}"}
|
||||
params = {
|
||||
f"page": 1,
|
||||
"perPage": -1,
|
||||
"queryFilter": f"date > {yesterday.strftime('%Y-%m-%d')}",
|
||||
}
|
||||
response = api_client.get(api_routes.groups_mealplans, params=params, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
|
@ -862,7 +958,11 @@ def test_pagination_filter_dates(api_client: TestClient, unique_user: TestUser):
|
|||
assert mealplan_tomorrow.title in fetched_mealplan_titles
|
||||
|
||||
## Today
|
||||
params = {f"page": 1, "perPage": -1, "queryFilter": f"date >= {today.strftime('%Y-%m-%d')}"}
|
||||
params = {
|
||||
f"page": 1,
|
||||
"perPage": -1,
|
||||
"queryFilter": f"date >= {today.strftime('%Y-%m-%d')}",
|
||||
}
|
||||
response = api_client.get(api_routes.groups_mealplans, params=params, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
|
@ -872,7 +972,11 @@ def test_pagination_filter_dates(api_client: TestClient, unique_user: TestUser):
|
|||
assert mealplan_today.title in fetched_mealplan_titles
|
||||
assert mealplan_tomorrow.title in fetched_mealplan_titles
|
||||
|
||||
params = {f"page": 1, "perPage": -1, "queryFilter": f"date > {today.strftime('%Y-%m-%d')}"}
|
||||
params = {
|
||||
f"page": 1,
|
||||
"perPage": -1,
|
||||
"queryFilter": f"date > {today.strftime('%Y-%m-%d')}",
|
||||
}
|
||||
response = api_client.get(api_routes.groups_mealplans, params=params, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
|
@ -883,7 +987,11 @@ def test_pagination_filter_dates(api_client: TestClient, unique_user: TestUser):
|
|||
assert mealplan_tomorrow.title in fetched_mealplan_titles
|
||||
|
||||
## Tomorrow
|
||||
params = {f"page": 1, "perPage": -1, "queryFilter": f"date >= {tomorrow.strftime('%Y-%m-%d')}"}
|
||||
params = {
|
||||
f"page": 1,
|
||||
"perPage": -1,
|
||||
"queryFilter": f"date >= {tomorrow.strftime('%Y-%m-%d')}",
|
||||
}
|
||||
response = api_client.get(api_routes.groups_mealplans, params=params, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
|
@ -893,7 +1001,11 @@ def test_pagination_filter_dates(api_client: TestClient, unique_user: TestUser):
|
|||
assert mealplan_today.title not in fetched_mealplan_titles
|
||||
assert mealplan_tomorrow.title in fetched_mealplan_titles
|
||||
|
||||
params = {f"page": 1, "perPage": -1, "queryFilter": f"date > {tomorrow.strftime('%Y-%m-%d')}"}
|
||||
params = {
|
||||
f"page": 1,
|
||||
"perPage": -1,
|
||||
"queryFilter": f"date > {tomorrow.strftime('%Y-%m-%d')}",
|
||||
}
|
||||
response = api_client.get(api_routes.groups_mealplans, params=params, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
|
@ -901,13 +1013,21 @@ def test_pagination_filter_dates(api_client: TestClient, unique_user: TestUser):
|
|||
assert len(response_json["items"]) == 0
|
||||
|
||||
## Day After Tomorrow
|
||||
params = {f"page": 1, "perPage": -1, "queryFilter": f"date >= {day_after_tomorrow.strftime('%Y-%m-%d')}"}
|
||||
params = {
|
||||
f"page": 1,
|
||||
"perPage": -1,
|
||||
"queryFilter": f"date >= {day_after_tomorrow.strftime('%Y-%m-%d')}",
|
||||
}
|
||||
response = api_client.get(api_routes.groups_mealplans, params=params, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
assert len(response_json["items"]) == 0
|
||||
|
||||
params = {f"page": 1, "perPage": -1, "queryFilter": f"date > {day_after_tomorrow.strftime('%Y-%m-%d')}"}
|
||||
params = {
|
||||
f"page": 1,
|
||||
"perPage": -1,
|
||||
"queryFilter": f"date > {day_after_tomorrow.strftime('%Y-%m-%d')}",
|
||||
}
|
||||
response = api_client.get(api_routes.groups_mealplans, params=params, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
|
@ -974,7 +1094,12 @@ def test_pagination_filter_advanced_frontend_sort(database: AllRepositories, uni
|
|||
# Bootstrap the database with recipes
|
||||
slug = random_string()
|
||||
recipe_ct0_tg0_tl0 = database.recipes.create(
|
||||
Recipe(user_id=unique_user.user_id, group_id=unique_user.group_id, name=slug, slug=slug)
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
group_id=unique_user.group_id,
|
||||
name=slug,
|
||||
slug=slug,
|
||||
)
|
||||
)
|
||||
|
||||
slug = random_string()
|
||||
|
@ -1111,17 +1236,26 @@ def test_pagination_filter_advanced_frontend_sort(database: AllRepositories, uni
|
|||
[
|
||||
pytest.param('(name="test name" AND useAbbreviation=f))', id="unbalanced parenthesis"),
|
||||
pytest.param('id="this is not a valid UUID"', id="invalid UUID"),
|
||||
pytest.param('createdAt="this is not a valid datetime format"', id="invalid datetime format"),
|
||||
pytest.param(
|
||||
'createdAt="this is not a valid datetime format"',
|
||||
id="invalid datetime format",
|
||||
),
|
||||
pytest.param('name IS "test name"', id="IS can only be used with NULL or NONE"),
|
||||
pytest.param('name IS NOT "test name"', id="IS NOT can only be used with NULL or NONE"),
|
||||
pytest.param('name IN "test name"', id="IN must use a list of values"),
|
||||
pytest.param('name NOT IN "test name"', id="NOT IN must use a list of values"),
|
||||
pytest.param('name CONTAINS ALL "test name"', id="CONTAINS ALL must use a list of values"),
|
||||
pytest.param('createdAt LIKE "2023-02-25"', id="LIKE is only valid for string columns"),
|
||||
pytest.param('createdAt NOT LIKE "2023-02-25"', id="NOT LIKE is only valid for string columns"),
|
||||
pytest.param(
|
||||
'createdAt NOT LIKE "2023-02-25"',
|
||||
id="NOT LIKE is only valid for string columns",
|
||||
),
|
||||
pytest.param('badAttribute="test value"', id="invalid attribute"),
|
||||
pytest.param('group.badAttribute="test value"', id="bad nested attribute"),
|
||||
pytest.param('group.preferences.badAttribute="test value"', id="bad double nested attribute"),
|
||||
pytest.param(
|
||||
'group.preferences.badAttribute="test value"',
|
||||
id="bad double nested attribute",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_malformed_query_filters(api_client: TestClient, unique_user: TestUser, qf: str):
|
||||
|
@ -1162,7 +1296,11 @@ def test_pagination_filter_nested(api_client: TestClient, user_tuple: list[TestU
|
|||
|
||||
# query timeline events with a double nested recipe.user filter
|
||||
for i, user in enumerate(user_tuple):
|
||||
params = {"page": 1, "perPage": -1, "queryFilter": f'recipe.user.id="{user.user_id}"'}
|
||||
params = {
|
||||
"page": 1,
|
||||
"perPage": -1,
|
||||
"queryFilter": f'recipe.user.id="{user.user_id}"',
|
||||
}
|
||||
response = api_client.get(api_routes.recipes_timeline_events, params=params, headers=user.token)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue