def test_verify_ingredient_should_verifyIngredientFromCacheIfCached_and_log(self):

        self.cache.get.return_value = self.edamam_json
        self.sut._get_edamam_nutrition_data = mock.Mock()

        self.sut.verify_ingredient(Ingredient(''))
        self.logger.info.assert_called_with('Retrieved ingredient information from CACHE')
Example #2
0
 def test_create_should_calculateCorrectPrice_whenUnitIsKg(self):
     ingredient = Ingredient('1 apple', 255, 'apple', 1)
     costing_ingredient = CustomChangesIngredientDataProvider.get(
     ).with_unit('kg').with_gross_price(100).build()
     actual = self.sut.create(Recipes(), costing_ingredient, ingredient,
                              self.order)
     self.assertEqual(actual.price, 25.5)
    def init_ingredient_to_add_to_recipe_without_verify_edamam(
            self, amount, measure, costing_ingredient):
        text = amount + ' ' + measure + ' ' + costing_ingredient.ingredient
        quantity = float(amount)
        if measure == 'kg':
            weight_in_gr = quantity * 1000
        elif measure == 'lbs':
            weight_in_gr = quantity * 453.59
        else:
            weight_in_gr = 0

        ingredient = Ingredient(text, weight_in_gr, measure, quantity)
        return ingredient
    def test_verify_ingredient_should_verifyIngredientFromServerIfNoCache(self):
        self.cache.get.return_value = None
        ingredient = Ingredient('')

        edamam_response = json.loads(self.edamam_json)
        self.sut._get_edamam_nutrition_data = mock.MagicMock()
        self.sut._get_edamam_nutrition_data.return_value = edamam_response

        actual = self.sut.verify_ingredient(ingredient)

        self.assertTrue(isinstance(actual, Ingredient))

        self.logger.info.assert_called_with('Retrieved ingredient information from SERVER')
Example #5
0
 def test_create_should_throw_whenInvalid(self):
     test_cases = [{
         "recipe": {},
         "costing_ingredient": {},
         "ingredient": {},
         "exception": InvalidRecipeException
     }, {
         "recipe": Recipes(),
         "costing_ingredient": {},
         "ingredient": {},
         "exception": InvalidEdamamIngredientException
     }, {
         "recipe": Recipes(),
         "costing_ingredient": {},
         "ingredient": Ingredient(''),
         "exception": InvalidIngredientException
     }]
     for test in test_cases:
         self.assertRaises(test['exception'], self.sut.create,
                           test['recipe'], test['costing_ingredient'],
                           test['ingredient'], self.order)
Example #6
0
 def verify_ingredient(self, text):
     ingredient = Ingredient(text)
     return self.edamam_gateway.verify_ingredient(ingredient)
Example #7
0
 def test_create_should_notThrow_whenInputValid(self):
     self.sut.create(Recipes(), GenericIngredient(), Ingredient(''),
                     self.order)
     self.assert_(True)