EPA-Chips und mg/µg vom Etikett; fehlende Parameter ohne Admin. Co-authored-by: Cursor <cursoragent@cursor.com>
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
from data_layer.food_attributes import (
|
|
create_extension_attribute,
|
|
macros_and_attributes_to_values,
|
|
normalize_attr_key,
|
|
normalize_attr_unit,
|
|
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_attr_key_and_unit_normalize():
|
|
assert normalize_attr_key("Vitamin D3") == "VITAMIN_D3"
|
|
assert normalize_attr_unit("ug") == "µg"
|
|
assert normalize_attr_unit("mcg") == "µg"
|
|
|
|
|
|
def test_create_extension_returns_existing():
|
|
class _Cur:
|
|
def __init__(self):
|
|
self.calls = 0
|
|
|
|
def execute(self, sql, params=None):
|
|
self.calls += 1
|
|
self._row = {"id": 1, "attr_key": "VITAMIN_D3", "name_de": "Vitamin D3", "name_en": None, "unit": "µg", "category": "extension", "origin": "extension"} if self.calls == 1 else None
|
|
|
|
def fetchone(self):
|
|
return self._row
|
|
|
|
row = create_extension_attribute(_Cur(), "Vitamin D3", "µg")
|
|
assert row["attr_key"] == "VITAMIN_D3"
|
|
|
|
|
|
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
|