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})
|
||||
@@ -0,0 +1,40 @@
|
||||
from data_layer.tandoor_client import TandoorError, normalize_base_url, public_settings, token_hint
|
||||
|
||||
|
||||
def test_normalize_https_strips_slash():
|
||||
assert normalize_base_url("https://tandoor.stommer.de/") == "https://tandoor.stommer.de"
|
||||
|
||||
|
||||
def test_normalize_rejects_empty_and_bare_host():
|
||||
try:
|
||||
normalize_base_url(" ")
|
||||
except TandoorError as e:
|
||||
assert "fehlt" in str(e)
|
||||
else:
|
||||
raise AssertionError("expected TandoorError")
|
||||
try:
|
||||
normalize_base_url("tandoor.stommer.de")
|
||||
except TandoorError:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError("expected TandoorError")
|
||||
|
||||
|
||||
def test_normalize_rejects_public_http():
|
||||
try:
|
||||
normalize_base_url("http://tandoor.stommer.de")
|
||||
except TandoorError as e:
|
||||
assert "https" in str(e)
|
||||
else:
|
||||
raise AssertionError("expected TandoorError")
|
||||
|
||||
|
||||
def test_token_hint_never_full():
|
||||
assert token_hint("abcdefghijklmnop") == "…mnop"
|
||||
assert "abcd" not in (token_hint("secret-token-value") or "")
|
||||
assert public_settings(None)["token_set"] is False
|
||||
pub = public_settings({"base_url": "https://tandoor.example", "api_token": "super-secret-token"})
|
||||
assert pub["token_set"] is True
|
||||
assert pub["token_hint"] == "…oken"
|
||||
assert "super" not in (pub["token_hint"] or "")
|
||||
assert "api_token" not in pub
|
||||
Reference in new issue
Block a user