From 13e7dfe920ef6898795c41043e26e21ad5a7df62 Mon Sep 17 00:00:00 2001 From: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com> Date: Mon, 5 Feb 2024 14:37:15 +0100 Subject: [PATCH 1/9] getAll if array is empty or non existant (#3120) --- frontend/composables/store/use-food-store.ts | 4 ++-- frontend/composables/store/use-label-store.ts | 4 ++-- frontend/composables/store/use-unit-store.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/composables/store/use-food-store.ts b/frontend/composables/store/use-food-store.ts index b7c3953e3d22..37038e7259d6 100644 --- a/frontend/composables/store/use-food-store.ts +++ b/frontend/composables/store/use-food-store.ts @@ -43,7 +43,7 @@ export const usePublicFoodStore = function (groupSlug: string) { }, }; - if (!foodStore.value) { + if (!foodStore.value || foodStore.value.length === 0) { foodStore = actions.getAll(); } @@ -61,7 +61,7 @@ export const useFoodStore = function () { }, }; - if (!foodStore) { + if (!foodStore.value || foodStore.value.length === 0) { foodStore = actions.getAll(); } diff --git a/frontend/composables/store/use-label-store.ts b/frontend/composables/store/use-label-store.ts index 37fc48552fef..77da62f07f9d 100644 --- a/frontend/composables/store/use-label-store.ts +++ b/frontend/composables/store/use-label-store.ts @@ -33,11 +33,11 @@ export function useLabelStore() { const actions = { ...useStoreActions(api.multiPurposeLabels, labelStore, loading), flushStore() { - labelStore.value =[]; + labelStore.value = []; }, }; - if (!labelStore.value) { + if (!labelStore.value || labelStore.value?.length === 0) { labelStore = actions.getAll(); } diff --git a/frontend/composables/store/use-unit-store.ts b/frontend/composables/store/use-unit-store.ts index b2af6e9057d0..bf4c3cf3216d 100644 --- a/frontend/composables/store/use-unit-store.ts +++ b/frontend/composables/store/use-unit-store.ts @@ -44,7 +44,7 @@ export const useUnitStore = function () { }, }; - if (!unitStore.value) { + if (!unitStore.value || unitStore.value.length === 0) { unitStore = actions.getAll(); } From 026ca0364edf52baa836e402231382ef1bc9b95c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 6 Feb 2024 09:12:30 -0600 Subject: [PATCH 2/9] chore(deps): update dependency ruff to v0.2.1 (#3122) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- poetry.lock | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/poetry.lock b/poetry.lock index 1422f81dae18..705df7950995 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2381,28 +2381,28 @@ pyasn1 = ">=0.1.3" [[package]] name = "ruff" -version = "0.2.0" +version = "0.2.1" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.2.0-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:638ea3294f800d18bae84a492cb5a245c8d29c90d19a91d8e338937a4c27fca0"}, - {file = "ruff-0.2.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:3ff35433fcf4dff6d610738712152df6b7d92351a1bde8e00bd405b08b3d5759"}, - {file = "ruff-0.2.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bf9faafbdcf4f53917019f2c230766da437d4fd5caecd12ddb68bb6a17d74399"}, - {file = "ruff-0.2.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:8153a3e4128ed770871c47545f1ae7b055023e0c222ff72a759f5a341ee06483"}, - {file = "ruff-0.2.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e8a75a98ae989a27090e9c51f763990ad5bbc92d20626d54e9701c7fe597f399"}, - {file = "ruff-0.2.0-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:87057dd2fdde297130ff99553be8549ca38a2965871462a97394c22ed2dfc19d"}, - {file = "ruff-0.2.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6d232f99d3ab00094ebaf88e0fb7a8ccacaa54cc7fa3b8993d9627a11e6aed7a"}, - {file = "ruff-0.2.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3d3c641f95f435fc6754b05591774a17df41648f0daf3de0d75ad3d9f099ab92"}, - {file = "ruff-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3826fb34c144ef1e171b323ed6ae9146ab76d109960addca730756dc19dc7b22"}, - {file = "ruff-0.2.0-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:eceab7d85d09321b4de18b62d38710cf296cb49e98979960a59c6b9307c18cfe"}, - {file = "ruff-0.2.0-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:30ad74687e1f4a9ff8e513b20b82ccadb6bd796fe5697f1e417189c5cde6be3e"}, - {file = "ruff-0.2.0-py3-none-musllinux_1_2_i686.whl", hash = "sha256:a7e3818698f8460bd0f8d4322bbe99db8327e9bc2c93c789d3159f5b335f47da"}, - {file = "ruff-0.2.0-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:edf23041242c48b0d8295214783ef543847ef29e8226d9f69bf96592dba82a83"}, - {file = "ruff-0.2.0-py3-none-win32.whl", hash = "sha256:e155147199c2714ff52385b760fe242bb99ea64b240a9ffbd6a5918eb1268843"}, - {file = "ruff-0.2.0-py3-none-win_amd64.whl", hash = "sha256:ba918e01cdd21e81b07555564f40d307b0caafa9a7a65742e98ff244f5035c59"}, - {file = "ruff-0.2.0-py3-none-win_arm64.whl", hash = "sha256:3fbaff1ba9564a2c5943f8f38bc221f04bac687cc7485e45237579fee7ccda79"}, - {file = "ruff-0.2.0.tar.gz", hash = "sha256:63856b91837606c673537d2889989733d7dffde553828d3b0f0bacfa6def54be"}, + {file = "ruff-0.2.1-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:dd81b911d28925e7e8b323e8d06951554655021df8dd4ac3045d7212ac4ba080"}, + {file = "ruff-0.2.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:dc586724a95b7d980aa17f671e173df00f0a2eef23f8babbeee663229a938fec"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c92db7101ef5bfc18e96777ed7bc7c822d545fa5977e90a585accac43d22f18a"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:13471684694d41ae0f1e8e3a7497e14cd57ccb7dd72ae08d56a159d6c9c3e30e"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a11567e20ea39d1f51aebd778685582d4c56ccb082c1161ffc10f79bebe6df35"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:00a818e2db63659570403e44383ab03c529c2b9678ba4ba6c105af7854008105"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:be60592f9d218b52f03384d1325efa9d3b41e4c4d55ea022cd548547cc42cd2b"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:fbd2288890b88e8aab4499e55148805b58ec711053588cc2f0196a44f6e3d855"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f3ef052283da7dec1987bba8d8733051c2325654641dfe5877a4022108098683"}, + {file = "ruff-0.2.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:7022d66366d6fded4ba3889f73cd791c2d5621b2ccf34befc752cb0df70f5fad"}, + {file = "ruff-0.2.1-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:0a725823cb2a3f08ee743a534cb6935727d9e47409e4ad72c10a3faf042ad5ba"}, + {file = "ruff-0.2.1-py3-none-musllinux_1_2_i686.whl", hash = "sha256:0034d5b6323e6e8fe91b2a1e55b02d92d0b582d2953a2b37a67a2d7dedbb7acc"}, + {file = "ruff-0.2.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:e5cb5526d69bb9143c2e4d2a115d08ffca3d8e0fddc84925a7b54931c96f5c02"}, + {file = "ruff-0.2.1-py3-none-win32.whl", hash = "sha256:6b95ac9ce49b4fb390634d46d6ece32ace3acdd52814671ccaf20b7f60adb232"}, + {file = "ruff-0.2.1-py3-none-win_amd64.whl", hash = "sha256:e3affdcbc2afb6f5bd0eb3130139ceedc5e3f28d206fe49f63073cb9e65988e0"}, + {file = "ruff-0.2.1-py3-none-win_arm64.whl", hash = "sha256:efababa8e12330aa94a53e90a81eb6e2d55f348bc2e71adbf17d9cad23c03ee6"}, + {file = "ruff-0.2.1.tar.gz", hash = "sha256:3b42b5d8677cd0c72b99fcaf068ffc62abb5a19e71b4a3b9cfa50658a0af02f1"}, ] [[package]] From 47b60e9ad56fb836d95b54d34bf757b9d6b59629 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Tue, 6 Feb 2024 17:51:59 -0600 Subject: [PATCH 3/9] New translations en-us.json (Hungarian) --- frontend/lang/messages/hu-HU.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/lang/messages/hu-HU.json b/frontend/lang/messages/hu-HU.json index db2fe839943c..12fe6abc3e94 100644 --- a/frontend/lang/messages/hu-HU.json +++ b/frontend/lang/messages/hu-HU.json @@ -200,7 +200,7 @@ "created-on-date": "Létrehozva: {0}", "unsaved-changes": "El nem mentett módosításai vannak. Szeretné elmenteni, mielőtt kilép? A mentéshez kattintson az Ok, a módosítások elvetéséhez a Mégsem gombra.", "clipboard-copy-failure": "Nem sikerült a vágólapra másolás.", - "confirm-delete-generic-items": "Are you sure you want to delete the following items?" + "confirm-delete-generic-items": "Biztos benne, hogy törölni szeretné az alábbi tételeket?" }, "group": { "are-you-sure-you-want-to-delete-the-group": "Biztosan törölni szeretnéd ezt: {groupName}?", From c960c00cbeef501a75d64f731bd908f16b515cee Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Tue, 6 Feb 2024 17:52:00 -0600 Subject: [PATCH 4/9] New translations en-us.json (Swedish) --- frontend/lang/messages/sv-SE.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/lang/messages/sv-SE.json b/frontend/lang/messages/sv-SE.json index 8580b0aab987..0e9334840c33 100644 --- a/frontend/lang/messages/sv-SE.json +++ b/frontend/lang/messages/sv-SE.json @@ -200,7 +200,7 @@ "created-on-date": "Skapad {0}", "unsaved-changes": "Du har osparade ändringar. Vill du spara innan du lämnar? Tryck Okej att spara, Avbryt för att ignorera ändringar.", "clipboard-copy-failure": "Det gick inte att kopiera till urklipp.", - "confirm-delete-generic-items": "Are you sure you want to delete the following items?" + "confirm-delete-generic-items": "Är du säker på att du vill radera följande objekt?" }, "group": { "are-you-sure-you-want-to-delete-the-group": "Är du säker på att du vill radera {groupName}?", From a0b6cc3e62e215d24137c906e78b958c1b3886c5 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Tue, 6 Feb 2024 17:52:01 -0600 Subject: [PATCH 5/9] New translations en-us.json (Turkish) --- frontend/lang/messages/tr-TR.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/lang/messages/tr-TR.json b/frontend/lang/messages/tr-TR.json index b249a11692d8..af306197a2b9 100644 --- a/frontend/lang/messages/tr-TR.json +++ b/frontend/lang/messages/tr-TR.json @@ -200,7 +200,7 @@ "created-on-date": "{0} tarihinde oluşturuldu", "unsaved-changes": "Kaydedilmemiş değişiklikleriniz mevcut. Ayrılmadan önce kaydetmek ister misiniz? Kaydetmek için Tamam'ı, değişiklikleri iptal etmek için İptal'i seçin.", "clipboard-copy-failure": "Panoya kopyalanamadı.", - "confirm-delete-generic-items": "Are you sure you want to delete the following items?" + "confirm-delete-generic-items": "Aşağıdaki öğeleri silmek istediğinizden emin misiniz?" }, "group": { "are-you-sure-you-want-to-delete-the-group": "{groupName}'i silmek istediğine emin misin?", @@ -1187,7 +1187,7 @@ "require-all-tools": "Require All Tools", "cookbook-name": "Cookbook Name", "cookbook-with-name": "Cookbook {0}", - "create-a-cookbook": "Create a Cookbook", - "cookbook": "Cookbook" + "create-a-cookbook": "Yemek Kitabı Oluştur", + "cookbook": "Yemek kitabı" } } From 597e6c8e0f802f3a9d971c3322ec8d79b3af7fb6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 7 Feb 2024 04:38:04 +0000 Subject: [PATCH 6/9] chore(deps): update dependency mkdocs-material to v9.5.8 (#3124) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- poetry.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/poetry.lock b/poetry.lock index 705df7950995..5b64e4f68904 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1220,13 +1220,13 @@ min-versions = ["babel (==2.9.0)", "click (==7.0)", "colorama (==0.4)", "ghp-imp [[package]] name = "mkdocs-material" -version = "9.5.7" +version = "9.5.8" description = "Documentation that simply works" optional = false python-versions = ">=3.8" files = [ - {file = "mkdocs_material-9.5.7-py3-none-any.whl", hash = "sha256:0be8ce8bcfebb52bae9b00cf9b851df45b8a92d629afcfd7f2c09b2dfa155ea3"}, - {file = "mkdocs_material-9.5.7.tar.gz", hash = "sha256:16110292575d88a338d2961f3cb665cf12943ff8829e551a9b364f24019e46af"}, + {file = "mkdocs_material-9.5.8-py3-none-any.whl", hash = "sha256:14563314bbf97da4bfafc69053772341babfaeb3329cde01d3e63cec03997af8"}, + {file = "mkdocs_material-9.5.8.tar.gz", hash = "sha256:2a429213e83f84eda7a588e2b186316d806aac602b7f93990042f7a1f3d3cf65"}, ] [package.dependencies] @@ -1243,7 +1243,7 @@ regex = ">=2022.4" requests = ">=2.26,<3.0" [package.extras] -git = ["mkdocs-git-committers-plugin-2 (>=1.1,<2.0)", "mkdocs-git-revision-date-localized-plugin (>=1.2,<2.0)"] +git = ["mkdocs-git-committers-plugin-2 (>=1.1,<2.0)", "mkdocs-git-revision-date-localized-plugin (>=1.2.4,<2.0)"] imaging = ["cairosvg (>=2.6,<3.0)", "pillow (>=10.2,<11.0)"] recommended = ["mkdocs-minify-plugin (>=0.7,<1.0)", "mkdocs-redirects (>=1.2,<2.0)", "mkdocs-rss-plugin (>=1.6,<2.0)"] From e686fa671cf6473f391203618458d0cde18eb519 Mon Sep 17 00:00:00 2001 From: RealFoxie <52831920+RealFoxie@users.noreply.github.com> Date: Wed, 7 Feb 2024 16:16:20 +0100 Subject: [PATCH 7/9] Better bruteforce parsing for units (#3066) * try to match units when brute parsing and no amount is matched * brute parser: better handle multiple word food items Also checks the case when a food might have been split in a unit + ingredient * fix formatting * add test cases for ingredient parsing that don't start with an amount * parametrized tests and added ingredient data fixture * fixed group_id ref in tests * fixed test inputs * add extra tests for units as third token --------- Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> --- .../services/parser_services/brute/process.py | 22 ++-- .../parser_services/ingredient_parser.py | 22 +++- tests/unit_tests/test_ingredient_parser.py | 117 ++++++++++++++---- 3 files changed, 123 insertions(+), 38 deletions(-) diff --git a/mealie/services/parser_services/brute/process.py b/mealie/services/parser_services/brute/process.py index ade777cf8a1f..30ac690bf65d 100644 --- a/mealie/services/parser_services/brute/process.py +++ b/mealie/services/parser_services/brute/process.py @@ -132,7 +132,7 @@ def parse_ingredient(tokens) -> tuple[str, str]: return ingredient, note -def parse(ing_str) -> BruteParsedIngredient: +def parse(ing_str, parser) -> BruteParsedIngredient: amount = 0.0 unit = "" ingredient = "" @@ -192,12 +192,20 @@ def parse(ing_str) -> BruteParsedIngredient: # which means this is the ingredient ingredient = tokens[1] except ValueError: - try: - # can't parse first argument as amount - # -> no unit -> parse everything as ingredient - ingredient, note = parse_ingredient(tokens) - except ValueError: - ingredient = " ".join(tokens[1:]) + # can't parse first argument as amount + # try to parse as unit and ingredient (e.g. "a tblsp salt"), with unit in first three tokens + # won't work for units that have spaces + for index, token in enumerate(tokens[:3]): + if parser.find_unit_match(token): + unit = token + ingredient, note = parse_ingredient(tokens[index + 1 :]) + break + if not unit: + try: + # no unit -> parse everything as ingredient + ingredient, note = parse_ingredient(tokens) + except ValueError: + ingredient = " ".join(tokens[1:]) if unit_note not in note: note += " " + unit_note diff --git a/mealie/services/parser_services/ingredient_parser.py b/mealie/services/parser_services/ingredient_parser.py index b487c4c85e3c..26508310353b 100644 --- a/mealie/services/parser_services/ingredient_parser.py +++ b/mealie/services/parser_services/ingredient_parser.py @@ -126,22 +126,24 @@ class ABCIngredientParser(ABC): return store_map[fuzz_result[0]] - def find_food_match(self, food: IngredientFood | CreateIngredientFood) -> IngredientFood | None: + def find_food_match(self, food: IngredientFood | CreateIngredientFood | str) -> IngredientFood | None: if isinstance(food, IngredientFood): return food - match_value = IngredientFoodModel.normalize(food.name) + food_name = food if isinstance(food, str) else food.name + match_value = IngredientFoodModel.normalize(food_name) return self.find_match( match_value, store_map=self.foods_by_alias, fuzzy_match_threshold=self.food_fuzzy_match_threshold, ) - def find_unit_match(self, unit: IngredientUnit | CreateIngredientUnit) -> IngredientUnit | None: + def find_unit_match(self, unit: IngredientUnit | CreateIngredientUnit | str) -> IngredientUnit | None: if isinstance(unit, IngredientUnit): return unit - match_value = IngredientUnitModel.normalize(unit.name) + unit_name = unit if isinstance(unit, str) else unit.name + match_value = IngredientUnitModel.normalize(unit_name) return self.find_match( match_value, store_map=self.units_by_alias, @@ -155,6 +157,16 @@ class ABCIngredientParser(ABC): if ingredient.ingredient.unit and (unit_match := self.find_unit_match(ingredient.ingredient.unit)): ingredient.ingredient.unit = unit_match + # Parser might have wrongly split a food into a unit and food. + if isinstance(ingredient.ingredient.food, CreateIngredientFood) and isinstance( + ingredient.ingredient.unit, CreateIngredientUnit + ): + if food_match := self.find_food_match( + f"{ingredient.ingredient.unit.name} {ingredient.ingredient.food.name}" + ): + ingredient.ingredient.food = food_match + ingredient.ingredient.unit = None + return ingredient @@ -164,7 +176,7 @@ class BruteForceParser(ABCIngredientParser): """ def parse_one(self, ingredient: str) -> ParsedIngredient: - bfi = brute.parse(ingredient) + bfi = brute.parse(ingredient, self) parsed_ingredient = ParsedIngredient( input=ingredient, diff --git a/tests/unit_tests/test_ingredient_parser.py b/tests/unit_tests/test_ingredient_parser.py index df7a336af714..dde303762731 100644 --- a/tests/unit_tests/test_ingredient_parser.py +++ b/tests/unit_tests/test_ingredient_parser.py @@ -135,7 +135,7 @@ test_ingredients = [ @pytest.mark.skipif(not crf_exists(), reason="CRF++ not installed") -def test_nlp_parser(): +def test_nlp_parser() -> None: models: list[CRFIngredient] = convert_list_to_crf_model([x.input for x in test_ingredients]) # Iterate over models and test_ingredients to gather @@ -147,37 +147,102 @@ def test_nlp_parser(): assert model.unit == test_ingredient.unit -def test_brute_parser(unique_user: TestUser): - # input: (quantity, unit, food, comments) - expectations = { - # Dutch - "1 theelepel koffie": (1, "theelepel", "koffie", ""), - "3 theelepels koffie": (3, "theelepels", "koffie", ""), - "1 eetlepel tarwe": (1, "eetlepel", "tarwe", ""), - "20 eetlepels bloem": (20, "eetlepels", "bloem", ""), - "1 mespunt kaneel": (1, "mespunt", "kaneel", ""), - "1 snuf(je) zout": (1, "snuf(je)", "zout", ""), - "2 tbsp minced cilantro, leaves and stems": (2, "tbsp", "minced cilantro", "leaves and stems"), - "1 large yellow onion, coarsely chopped": (1, "large", "yellow onion", "coarsely chopped"), - "1 1/2 tsp garam masala": (1.5, "tsp", "garam masala", ""), - "2 cups mango chunks, (2 large mangoes) (fresh or frozen)": ( +@pytest.mark.parametrize( + "input, quantity, unit, food, comment", + [ + pytest.param("1 theelepel koffie", 1, "theelepel", "koffie", "", id="1 theelepel koffie"), + pytest.param("3 theelepels koffie", 3, "theelepels", "koffie", "", id="3 theelepels koffie"), + pytest.param("1 eetlepel tarwe", 1, "eetlepel", "tarwe", "", id="1 eetlepel tarwe"), + pytest.param("20 eetlepels bloem", 20, "eetlepels", "bloem", "", id="20 eetlepels bloem"), + pytest.param("1 mespunt kaneel", 1, "mespunt", "kaneel", "", id="1 mespunt kaneel"), + pytest.param("1 snuf(je) zout", 1, "snuf(je)", "zout", "", id="1 snuf(je) zout"), + pytest.param( + "2 tbsp minced cilantro, leaves and stems", 2, - "cups", + "tbsp", + "minced cilantro", + "leaves and stems", + id="2 tbsp minced cilantro, leaves and stems", + ), + pytest.param( + "1 large yellow onion, coarsely chopped", + 1, + "large", + "yellow onion", + "coarsely chopped", + id="1 large yellow onion, coarsely chopped", + ), + pytest.param("1 1/2 tsp garam masala", 1.5, "tsp", "garam masala", "", id="1 1/2 tsp garam masala"), + pytest.param( + "2 cups mango chunks, (2 large mangoes) (fresh or frozen)", + 2, + "Cups", "mango chunks, (2 large mangoes)", "fresh or frozen", + id="2 cups mango chunks, (2 large mangoes) (fresh or frozen)", ), - } - + pytest.param("stalk onion", 0, "Stalk", "onion", "", id="stalk onion"), + pytest.param("a stalk bell peppers", 0, "Stalk", "bell peppers", "", id="a stalk bell peppers"), + pytest.param("a tablespoon unknownFood", 0, "Tablespoon", "unknownFood", "", id="a tablespoon unknownFood"), + pytest.param( + "stalk bell peppers, cut in pieces", + 0, + "Stalk", + "bell peppers", + "cut in pieces", + id="stalk bell peppers, cut in pieces", + ), + pytest.param( + "a stalk bell peppers, cut in pieces", + 0, + "Stalk", + "bell peppers", + "cut in pieces", + id="stalk bell peppers, cut in pieces", + ), + pytest.param("red pepper flakes", 0, "", "red pepper flakes", "", id="red pepper flakes"), + pytest.param("1 red pepper flakes", 1, "", "red pepper flakes", "", id="1 red pepper flakes"), + pytest.param("1 bell peppers", 1, "", "bell peppers", "", id="1 bell peppers"), + pytest.param("1 stalk bell peppers", 1, "Stalk", "bell peppers", "", id="1 big stalk bell peppers"), + pytest.param("a big stalk bell peppers", 0, "Stalk", "bell peppers", "", id="a big stalk bell peppers"), + pytest.param( + "1 bell peppers, cut in pieces", 1, "", "bell peppers", "cut in pieces", id="1 bell peppers, cut in pieces" + ), + pytest.param( + "bell peppers, cut in pieces", 0, "", "bell peppers", "cut in pieces", id="bell peppers, cut in pieces" + ), + ], +) +def test_brute_parser( + unique_local_group_id: UUID4, + parsed_ingredient_data: tuple[list[IngredientFood], list[IngredientUnit]], # required so database is populated + input: str, + quantity: int | float, + unit: str, + food: str, + comment: str, +): with session_context() as session: - parser = get_parser(RegisteredParser.brute, unique_user.group_id, session) + parser = get_parser(RegisteredParser.brute, unique_local_group_id, session) + parsed = parser.parse_one(input) + ing = parsed.ingredient - for key, val in expectations.items(): - parsed = parser.parse_one(key) - - assert parsed.ingredient.quantity == val[0] - assert parsed.ingredient.unit.name == val[1] - assert parsed.ingredient.food.name == val[2] - assert parsed.ingredient.note in {val[3], None} + if ing.quantity: + assert ing.quantity == quantity + else: + assert not quantity + if ing.unit: + assert ing.unit.name == unit + else: + assert not unit + if ing.food: + assert ing.food.name == food + else: + assert not food + if ing.note: + assert ing.note == comment + else: + assert not comment @pytest.mark.parametrize( From f42114e96676d35b6dc59e3cfa80a655b964fe11 Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:53:55 -0600 Subject: [PATCH 8/9] feat: Redirect Logged Out Users to Default Group, If It's Public (#2772) * add default group slug to app info if public * redirect public user to default group * added tests --------- Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com> --- frontend/lib/api/types/admin.ts | 1 + frontend/pages/index.vue | 15 +++++++++-- mealie/routes/app/app_about.py | 11 +++++++- mealie/schema/admin/about.py | 1 + .../admin_tests/test_admin_about.py | 25 +++++++++++++++++++ 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/frontend/lib/api/types/admin.ts b/frontend/lib/api/types/admin.ts index fe4225d2d7ce..0df40dec5f00 100644 --- a/frontend/lib/api/types/admin.ts +++ b/frontend/lib/api/types/admin.ts @@ -33,6 +33,7 @@ export interface AppInfo { version: string; demoStatus: boolean; allowSignup: boolean; + defaultGroupSlug?: string; } export interface AppStartupInfo { isFirstLogin: boolean; diff --git a/frontend/pages/index.vue b/frontend/pages/index.vue index 0fa12543b45d..795b423388ce 100644 --- a/frontend/pages/index.vue +++ b/frontend/pages/index.vue @@ -4,17 +4,28 @@