fix: Offene Lebensmittel nach Listen-Import wieder anzeigen
Unmapped ohne Kreuzjoin, Listen-GET kurz, Rebuild im Hintergrund. Tandoor-Zugang (URL/Token) in den Einstellungen mit ausliefern. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
fa542e0fb9
commit
d6838abda7
23 files changed
+786
-114
No files matched your search
@@ -2,8 +2,10 @@ from datetime import date
|
||||
|
||||
from csv_parser.executor import guess_nutrition_item_fields
|
||||
from data_layer.food_mapping import (
|
||||
fetch_unmapped_rows,
|
||||
filter_unmapped_since,
|
||||
list_quantity_units,
|
||||
list_unmapped_payload,
|
||||
merge_unmapped_rows,
|
||||
normalize_food_name,
|
||||
parse_quantity,
|
||||
@@ -84,6 +86,68 @@ def test_recent_window_drops_old_and_dateless_foods():
|
||||
assert len(filter_unmapped_since(rows, 0, today=today)) == 3
|
||||
|
||||
|
||||
class _FakeCur:
|
||||
def __init__(self, batches):
|
||||
self.batches = list(batches)
|
||||
self._i = 0
|
||||
self._rows = []
|
||||
|
||||
def execute(self, sql, params=None):
|
||||
self._rows = self.batches[self._i]
|
||||
self._i += 1
|
||||
|
||||
def fetchall(self):
|
||||
return self._rows
|
||||
|
||||
|
||||
def test_fetch_unmapped_keeps_ingredient_dates_and_skips_mapped():
|
||||
cur = _FakeCur([
|
||||
[{"source_name_normalized": "haferflocken"}],
|
||||
[],
|
||||
[
|
||||
{
|
||||
"source_name_raw": "Salz",
|
||||
"source_name_normalized": "salz",
|
||||
"count": 2,
|
||||
"first_date": date(2026, 9, 10),
|
||||
"last_date": date(2026, 9, 11),
|
||||
"sample_quantity_raw": "1 g",
|
||||
},
|
||||
{
|
||||
"source_name_raw": "Haferflocken",
|
||||
"source_name_normalized": "haferflocken",
|
||||
"count": 1,
|
||||
"first_date": date(2026, 9, 1),
|
||||
"last_date": date(2026, 9, 8),
|
||||
"sample_quantity_raw": "40 g",
|
||||
},
|
||||
],
|
||||
])
|
||||
rows = fetch_unmapped_rows(cur, "p")
|
||||
assert [r["source_name_normalized"] for r in rows] == ["salz"]
|
||||
assert rows[0]["last_date"] == "2026-09-11"
|
||||
assert rows[0]["kind"] == "recipe_ingredient"
|
||||
|
||||
|
||||
def test_unmapped_meta_includes_recent_ingredients():
|
||||
batches = [
|
||||
[],
|
||||
[],
|
||||
[{
|
||||
"source_name_raw": "Salz",
|
||||
"source_name_normalized": "salz",
|
||||
"count": 1,
|
||||
"first_date": date(2026, 9, 10),
|
||||
"last_date": date(2026, 9, 11),
|
||||
"sample_quantity_raw": "1 g",
|
||||
}],
|
||||
]
|
||||
payload = list_unmapped_payload(_FakeCur(batches), "p", since_days=0, meta=True)
|
||||
assert payload["total"] == 1
|
||||
assert payload["count"] == 1
|
||||
assert payload["items"][0]["source_name_normalized"] == "salz"
|
||||
|
||||
|
||||
def test_macros_differ_rounds():
|
||||
assert not macros_differ({"kcal": 1.04, "protein_g": 0, "fat_g": 0, "carbs_g": 0}, {"kcal": 1.0, "protein_g": 0, "fat_g": 0, "carbs_g": 0})
|
||||
assert macros_differ({"kcal": 10, "protein_g": 0, "fat_g": 0, "carbs_g": 0}, {"kcal": 11, "protein_g": 0, "fat_g": 0, "carbs_g": 0})
|
||||
Reference in new issue
Block a user