mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 06:23:34 -07:00
Merge 323e41a01f
into d6d247f1f8
This commit is contained in:
commit
8a3b2acd0b
3 changed files with 56 additions and 15 deletions
|
@ -159,6 +159,27 @@ export default defineNuxtComponent({
|
|||
label: i18n.t("general.date-updated"),
|
||||
type: "date",
|
||||
},
|
||||
{
|
||||
name: "nutrition.calories",
|
||||
label: i18n.tc("recipe.calories"),
|
||||
type: "number",
|
||||
},
|
||||
{
|
||||
name: "nutrition.carbohydrateContent",
|
||||
label: i18n.tc("recipe.carbohydrate-content"),
|
||||
type: "number",
|
||||
},
|
||||
{
|
||||
name: "nutrition.proteinContent",
|
||||
label: i18n.tc("recipe.protein-content"),
|
||||
type: "number",
|
||||
},
|
||||
{
|
||||
name: "nutrition.fatContent",
|
||||
label: i18n.tc("recipe.fat-content"),
|
||||
type: "number",
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
return {
|
||||
|
|
|
@ -140,12 +140,20 @@ def test_group_mealplan_rules_delete(api_client: TestClient, unique_user: TestUs
|
|||
"qf_string, expected_code",
|
||||
[
|
||||
('tags.name CONTAINS ALL ["tag1","tag2"]', 200),
|
||||
("nutrition.calories >= 100", 200),
|
||||
("nutrition.fatContent <= 10", 200),
|
||||
("nutrition.proteinContent >= 40", 200),
|
||||
("nutrition.carbohydrateContent = 200", 200),
|
||||
('badfield = "badvalue"', 422),
|
||||
('recipe_category.id IN ["1"]', 422),
|
||||
('created_at >= "not-a-date"', 422),
|
||||
],
|
||||
ids=[
|
||||
"valid qf",
|
||||
"valid calorie filter",
|
||||
"valid fat filter",
|
||||
"valid protein filter",
|
||||
"valid carb filter",
|
||||
"invalid field",
|
||||
"invalid UUID",
|
||||
"invalid date",
|
||||
|
|
|
@ -167,7 +167,10 @@ def test_pagination_guides(unique_user: TestUser):
|
|||
next_params: dict = dict(parse_qsl(urlsplit(random_page_of_results.next).query)) # type: ignore
|
||||
assert int(next_params["page"]) == random_page + 1
|
||||
|
||||
prev_params: dict = dict(parse_qsl(urlsplit(random_page_of_results.previous).query)) # type: ignore
|
||||
prev_params: dict = dict(
|
||||
# type: ignore
|
||||
parse_qsl(urlsplit(random_page_of_results.previous).query)
|
||||
)
|
||||
assert int(prev_params["page"]) == random_page - 1
|
||||
|
||||
source_params = camelize(query.model_dump())
|
||||
|
@ -639,7 +642,7 @@ def test_pagination_filter_datetimes(
|
|||
# units are created in order with increasing createdAt values
|
||||
units_repo, unit_1, unit_2, unit_3 = query_units
|
||||
|
||||
## GT
|
||||
# GT
|
||||
past_dt: datetime = unit_1.created_at - timedelta(seconds=1) # type: ignore
|
||||
dt = past_dt.isoformat()
|
||||
query = PaginationQuery(page=1, per_page=-1, query_filter=f'createdAt>"{dt}"')
|
||||
|
@ -681,7 +684,7 @@ def test_pagination_filter_datetimes(
|
|||
unit_ids = {unit.id for unit in unit_results}
|
||||
assert len(unit_ids) == 0
|
||||
|
||||
## GTE
|
||||
# GTE
|
||||
past_dt = unit_1.created_at - timedelta(seconds=1) # type: ignore
|
||||
dt = past_dt.isoformat()
|
||||
query = PaginationQuery(page=1, per_page=-1, query_filter=f'createdAt>="{dt}"')
|
||||
|
@ -1044,7 +1047,7 @@ def test_pagination_filter_dates(api_client: TestClient, unique_user: TestUser):
|
|||
response = api_client.post(api_routes.households_mealplans, json=data, headers=unique_user.token)
|
||||
assert response.status_code == 201
|
||||
|
||||
## Yesterday
|
||||
# Yesterday
|
||||
params = {
|
||||
"page": 1,
|
||||
"perPage": -1,
|
||||
|
@ -1073,7 +1076,7 @@ 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
|
||||
|
||||
## Today
|
||||
# Today
|
||||
params = {
|
||||
"page": 1,
|
||||
"perPage": -1,
|
||||
|
@ -1102,7 +1105,7 @@ 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
|
||||
|
||||
## Tomorrow
|
||||
# Tomorrow
|
||||
params = {
|
||||
"page": 1,
|
||||
"perPage": -1,
|
||||
|
@ -1128,7 +1131,7 @@ def test_pagination_filter_dates(api_client: TestClient, unique_user: TestUser):
|
|||
|
||||
assert len(response_json["items"]) == 0
|
||||
|
||||
## Day After Tomorrow
|
||||
# Day After Tomorrow
|
||||
params = {
|
||||
"page": 1,
|
||||
"perPage": -1,
|
||||
|
@ -1157,7 +1160,8 @@ def test_pagination_filter_booleans(query_units: tuple[RepositoryUnit, Ingredien
|
|||
query = PaginationQuery(
|
||||
page=1,
|
||||
per_page=-1,
|
||||
query_filter=f"useAbbreviation=true AND id IN [{', '.join([str(unit.id) for unit in query_units[1:]])}]",
|
||||
query_filter=f"useAbbreviation=true AND id IN [{
|
||||
', '.join([str(unit.id) for unit in query_units[1:]])}]",
|
||||
)
|
||||
unit_results = units_repo.page_all(query).items
|
||||
assert len(unit_results) == 1
|
||||
|
@ -1168,7 +1172,8 @@ def test_pagination_filter_advanced(query_units: tuple[RepositoryUnit, Ingredien
|
|||
units_repo, unit_1, unit_2, unit_3 = query_units
|
||||
|
||||
dt = str(unit_3.created_at.isoformat()) # type: ignore
|
||||
qf = f'name="test unit 1" OR (useAbbreviation=f AND (name="{unit_2.name}" OR createdAt > "{dt}"))'
|
||||
qf = f'name="test unit 1" OR (useAbbreviation=f AND (name="{
|
||||
unit_2.name}" OR createdAt > "{dt}"))'
|
||||
query = PaginationQuery(page=1, per_page=-1, query_filter=qf)
|
||||
unit_results = units_repo.page_all(query).items
|
||||
|
||||
|
@ -1177,7 +1182,8 @@ def test_pagination_filter_advanced(query_units: tuple[RepositoryUnit, Ingredien
|
|||
assert unit_2.id in result_ids
|
||||
assert unit_3.id not in result_ids
|
||||
|
||||
qf = f'(name LIKE %_1 OR name IN ["{unit_2.name}"]) AND createdAt IS NOT NONE'
|
||||
qf = f'(name LIKE %_1 OR name IN ["{
|
||||
unit_2.name}"]) AND createdAt IS NOT NONE'
|
||||
query = PaginationQuery(page=1, per_page=-1, query_filter=qf)
|
||||
unit_results = units_repo.page_all(query).items
|
||||
|
||||
|
@ -1292,7 +1298,8 @@ def test_pagination_filter_advanced_frontend_sort(unique_user: TestUser):
|
|||
|
||||
repo = database.recipes
|
||||
|
||||
qf = f'recipeCategory.id IN ["{category_1.id}"] AND tools.id IN ["{tool_1.id}"]'
|
||||
qf = f'recipeCategory.id IN ["{
|
||||
category_1.id}"] AND tools.id IN ["{tool_1.id}"]'
|
||||
query = PaginationQuery(page=1, per_page=-1, query_filter=qf)
|
||||
recipe_results = repo.page_all(query).items
|
||||
assert len(recipe_results) == 1
|
||||
|
@ -1305,7 +1312,8 @@ def test_pagination_filter_advanced_frontend_sort(unique_user: TestUser):
|
|||
assert recipe_ct0_tg2_tl2.id not in recipe_ids
|
||||
assert recipe_ct12_tg12_tl2.id not in recipe_ids
|
||||
|
||||
qf = f'recipeCategory.id CONTAINS ALL ["{category_1.id}", "{category_2.id}"] AND tags.id IN ["{tag_1.id}"]'
|
||||
qf = f'recipeCategory.id CONTAINS ALL ["{category_1.id}", "{
|
||||
category_2.id}"] AND tags.id IN ["{tag_1.id}"]'
|
||||
query = PaginationQuery(page=1, per_page=-1, query_filter=qf)
|
||||
recipe_results = repo.page_all(query).items
|
||||
assert len(recipe_results) == 1
|
||||
|
@ -1318,7 +1326,8 @@ def test_pagination_filter_advanced_frontend_sort(unique_user: TestUser):
|
|||
assert recipe_ct0_tg2_tl2.id not in recipe_ids
|
||||
assert recipe_ct12_tg12_tl2.id in recipe_ids
|
||||
|
||||
qf = f'tags.id IN ["{tag_1.id}", "{tag_2.id}"] AND tools.id IN ["{tool_2.id}"]'
|
||||
qf = f'tags.id IN ["{tag_1.id}", "{
|
||||
tag_2.id}"] AND tools.id IN ["{tool_2.id}"]'
|
||||
query = PaginationQuery(page=1, per_page=-1, query_filter=qf)
|
||||
recipe_results = repo.page_all(query).items
|
||||
assert len(recipe_results) == 2
|
||||
|
@ -1332,8 +1341,10 @@ def test_pagination_filter_advanced_frontend_sort(unique_user: TestUser):
|
|||
assert recipe_ct12_tg12_tl2.id in recipe_ids
|
||||
|
||||
qf = (
|
||||
f'recipeCategory.id CONTAINS ALL ["{category_1.id}", "{category_2.id}"]'
|
||||
f'AND tags.id IN ["{tag_1.id}", "{tag_2.id}"] AND tools.id IN ["{tool_1.id}", "{tool_2.id}"]'
|
||||
f'recipeCategory.id CONTAINS ALL ["{
|
||||
category_1.id}", "{category_2.id}"]'
|
||||
f'AND tags.id IN ["{tag_1.id}", "{
|
||||
tag_2.id}"] AND tools.id IN ["{tool_1.id}", "{tool_2.id}"]'
|
||||
)
|
||||
query = PaginationQuery(page=1, per_page=-1, query_filter=qf)
|
||||
recipe_results = repo.page_all(query).items
|
||||
|
@ -1373,6 +1384,7 @@ def test_pagination_filter_advanced_frontend_sort(unique_user: TestUser):
|
|||
'group.preferences.badAttribute="test value"',
|
||||
id="bad double nested attribute",
|
||||
),
|
||||
pytest.param('nutrition.calories="test"', id="comparing int to string"),
|
||||
],
|
||||
)
|
||||
def test_malformed_query_filters(api_client: TestClient, unique_user: TestUser, qf: str):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue