Self hosted FLOSS fitness/workout, nutrition and weight tracker
Increase limit for sanity check for total sum for OFF ingredients
Roland Geidercd6c676028b8
diff --git a/wger/nutrition/dataclasses.py b/wger/nutrition/dataclasses.pyindex 483eaa21e..0a1171e35 100644--- a/wger/nutrition/dataclasses.py+++ b/wger/nutrition/dataclasses.py@@ -98,8 +98,13 @@ class IngredientData:f'{self.carbohydrates_sugar} > {self.carbohydrates}')- if self.carbohydrates + self.protein + self.fat > 100:- raise ValueError('Total of carbohydrates, protein and fat is greater than 100!')+ # Labels can legally sum to slightly more than 100g per 100g of product because+ # of the per-nutrient measurement tolerances allowed by EU Regulation 1169/2011:+ # https://food.ec.europa.eu/system/files/2016-10/labelling_nutrition-vitamins_minerals-guidance_tolerances_1212_en.pdf+ # The limit of 105 matches the threshold used by Open Food Facts' own data+ # quality check "nutrition-value-total-over-105".+ if self.carbohydrates + self.protein + self.fat > 105:+ raise ValueError('Total of carbohydrates, protein and fat is greater than 105!')if self.nutriscore is not None and self.nutriscore not in ('a', 'b', 'c', 'd', 'e'):raise ValueError(f'Invalid nutriscore value: {self.nutriscore}')diff --git a/wger/nutrition/tests/test_dataclass.py b/wger/nutrition/tests/test_dataclass.pyindex 701e6e334..37c5363f3 100644--- a/wger/nutrition/tests/test_dataclass.py+++ b/wger/nutrition/tests/test_dataclass.py@@ -63,6 +63,24 @@ class IngredientDataclassTestCase(SimpleTestCase):self.ingredient_data.protein = 101self.assertRaises(ValueError, self.ingredient_data.sanity_checks)+ def test_validation_macro_sum_within_tolerance(self):+ """+ Test that a macro sum slightly over 100 is accepted (label tolerances)+ """+ self.ingredient_data.protein = 12+ self.ingredient_data.carbohydrates = 45+ self.ingredient_data.fat = 47+ self.assertEqual(self.ingredient_data.sanity_checks(), None)++ def test_validation_macro_sum_over_tolerance(self):+ """+ Test that a macro sum over 105 is rejected+ """+ self.ingredient_data.protein = 15+ self.ingredient_data.carbohydrates = 45+ self.ingredient_data.fat = 47+ self.assertRaises(ValueError, self.ingredient_data.sanity_checks)+def test_validation_saturated_fat(self):"""Test the validation for saturated fat