feat: Rezepte beim Zuordnen anlegen und offene Zutaten listen
Deploy Development / deploy (push) Successful in 1m1s
Build Test / pytest-backend (push) Successful in 8s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 29s

Lebensmittel oder Rezept wählbar; gemappte Zutaten werden übernommen, offene erscheinen in der Liste. Dazu Fettgehalt-Suche, EPA-Stoffe, Rezept-CRUD und Wechsel bestehender Zuordnungen.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-09-12 16:59:24 +02:00
1 parent 132a364a3a
commit a7e5511039
26 files changed
+1234 -147

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
from data_layer.food_attributes import macros_and_attributes_to_values, scale_to_per_100g
def test_scale_serving_to_per_100g():
assert scale_to_per_100g(1.1, 8) == 1.1 * (100 / 8)
assert scale_to_per_100g(10, 100) == 10
assert scale_to_per_100g(10, None) == 10
def test_norsan_label_epa_converts():
"""Etikett: 1100 mg EPA = 1.1 g in 8 g Portion → g/100 g."""
vals = macros_and_attributes_to_values(
{"kcal": 72, "protein_g": 0, "fat_g": 8, "carbs_g": 0},
{"EPA": 1.1},
serving_g=8,
)
assert abs(vals["FAT"] - 100) < 0.01
assert abs(vals["EPA"] - 13.75) < 0.01
assert abs(vals["ENERCC"] - 900) < 0.01
+15
View File
@@ -1,5 +1,9 @@
from decimal import Decimal
from uuid import uuid4
from data_layer.food_knowledge import (
BUNDLE_FORMAT,
_jsonable,
parse_food_knowledge_bundle,
portable_mapping,
)
@@ -40,3 +44,14 @@ def test_portable_mapping_drops_ids():
assert "food_id" not in row
assert row["bls_code"] == "C131000"
assert row["source_name_raw"] == "Haferflocken, Großblatt"
def test_jsonable_export_types():
payload = _jsonable({
"grams": Decimal("1.50"),
"id": uuid4(),
"nested": [Decimal("2")],
})
assert isinstance(payload["grams"], float)
assert isinstance(payload["id"], str)
assert payload["nested"] == [2.0]
+6
View File
@@ -7,10 +7,16 @@ from data_layer.food_mapping import (
normalize_food_name,
parse_quantity,
parse_quantity_g,
primary_search_query,
)
from data_layer.nutrition_items import macros_differ
def test_primary_query_keeps_decimal_comma():
assert primary_search_query("Joghurt 9,5%") == "Joghurt 9,5%"
assert primary_search_query("Joghurt, aus Kuhmilch") == "Joghurt"
def test_normalize_strips_leading_quantity():
assert normalize_food_name("50 g Hähnchen") == "hähnchen"
assert normalize_food_name(" Vollmilch 3,5% ") == "vollmilch 3.5%"
+10
View File
@@ -0,0 +1,10 @@
from data_layer.food_recipes import save_recipe
def test_save_recipe_requires_name():
try:
save_recipe(None, "p", {"name_raw": " ", "ingredients": []})
except ValueError as e:
assert "Rezeptname" in str(e)
else:
raise AssertionError("expected ValueError")
+43 -1
View File
@@ -1,4 +1,25 @@
from data_layer.food_suggest import collapse_key, score_name_match, suggest_batch, suggest_for_name
from data_layer.food_suggest import (
collapse_key,
name_tokens,
score_name_match,
suggest_batch,
suggest_for_name,
)
def _index(*foods):
index = {"foods": [], "by_collapse": {}, "by_token": {}, "by_prefix": {}, "by_suffix": {}}
for food in foods:
food["_c"] = collapse_key(food["name_de"])
food["_t"] = name_tokens(food["name_de"])
if food["_c"]:
index["by_collapse"].setdefault(food["_c"], []).append(food)
index["by_prefix"].setdefault(food["_c"][:4], []).append(food)
if len(food["_c"]) >= 4:
index["by_suffix"].setdefault(food["_c"][-4:], []).append(food)
for tok in food["_t"]:
index["by_token"].setdefault(tok, []).append(food)
return index
def test_collapse_treats_space_as_same():
@@ -63,3 +84,24 @@ def test_suggest_batch_dedupes_names():
out = suggest_batch(_Cur(), None, ["Haferflocken", "Haferflocken", ""], limit=2)
assert "Haferflocken" in out
assert out["Haferflocken"]["suggestions"] == []
def test_number_tokens_keep_decimal_fat():
assert "9.5" in name_tokens("Joghurt 9,5%")
assert "10" in name_tokens("Joghurt, aus Kuhmilch, 10 % Fett")
def test_joghurt_10_ranks_above_35():
light = {"id": "a", "name_de": "Joghurt >3,5% Fett", "name_en": "", "bls_code": "M", "catalog_kind": "official_bls"}
full = {
"id": "b",
"name_de": "Joghurt, aus Kuhmilch, 10 % Fett",
"name_en": "",
"bls_code": "N",
"catalog_kind": "official_bls",
}
index = _index(light, full)
for query in ("Joghurt 10%", "Joghurt 9,5%", "Joghurt 10"):
packed = suggest_for_name(index, query, limit=3)
assert packed["suggestions"][0]["name_de"] == full["name_de"], query
assert packed["suggestions"][0]["score"] > score_name_match(query, light["name_de"])