Ejemplo n.º 1
0
 def test_food_with_no_nutrients(self):
     food = models.Food.objects.create(name="Chicken")
     models.FoodWeight.objects.create(food=food,
                                      amount=1,
                                      desc="Pinch",
                                      value=1)
     food = ingredient.Ingredient(food.name)
     assert food.energy is None
Ejemplo n.º 2
0
 def test_sample_water(self):
     nutrients = [
         "ENERC_KCAL",
         "PROCNT",
         "FAT",
         "FASAT",
         "FAPU",
         "FAMS",
         "CHOCDF",
         "SUGAR",
         "CHOLE",
         "NA",
         "K",
         "FIBTG",
     ]
     water = models.Food.objects.create(name="Water")
     models.FoodWeight.objects.create(food=water,
                                      amount=1,
                                      desc="ml",
                                      value=1)
     for n in nutrients:
         models.FoodNutrition.objects.create(food=water,
                                             desc=n,
                                             value=0.0,
                                             units="mg",
                                             tagname=n)
     ing = ingredient.Ingredient(water.name)
     assert ing.matched_food.id == water.id
     assert ing.energy == 0.0
     assert ing.protein == 0.0
     assert ing.fat == 0.0
     assert ing.fat_sat == 0.0
     assert ing.fat_poly == 0.0
     assert ing.fat_mono == 0.0
     assert ing.carb == 0.0
     assert ing.sugar == 0.0
     assert ing.chol == 0.0
     assert ing.fiber == 0.0
     assert ing.potas == 0.0
     assert ing.sodium == 0.0
Ejemplo n.º 3
0
 def test_raise_when_no_weight(self):
     models.Food.objects.create(name="Chicken breast")
     with pytest.raises(ingredient.IngredientError):
         ingredient.Ingredient(
             "Chicken breast"
         )  # Unit wasn't specified and Chicken doesn't have any weight objects so it should raise IngredientError
Ejemplo n.º 4
0
 def test_assign_weight(self):
     models.Food.objects.create(name="Chicken breast")
     ing = ingredient.Ingredient("1 g of chicken breast")
     assert ing.weight == 1
Ejemplo n.º 5
0
 def test_parsing_non_existent_ingredient(self):
     with pytest.raises(ingredient.IngredientError):
         assert ingredient.Ingredient("xyz")