Example #1
0
    def put(self, beer_id):
        beer_name = self.beer_args['beer_name']
        description = self.beer_args['description']
        harmonization = self.beer_args['harmonization']
        color = self.beer_args['color']
        alcohol = self.beer_args['alcohol']
        temperature = self.beer_args['temperature']
        beer_ingredients = self.ingredients_args['ingredients']

        query_beer = BeerModel.get_beer_id(beer_id)
        if not query_beer:
            return error_does_not_exist(None, beer_id)

        for ingredient in beer_ingredients['list']:
            query_ingredient = IngredientsModel.get_ingredient_id(
                ingredient['id'])
            if not query_ingredient:
                return error_does_not_exist(None, ingredient['id'])

            data_ingredient = {
                'ingredient_name': ingredient['ingredient_name'],
                'beer_id': beer_id
            }
            IngredientsModel.update(query_ingredient, data_ingredient)

        data_beer = {
            'beer_name': beer_name.lower(),
            'description': description,
            'harmonization': harmonization,
            'color': color,
            'alcohol': alcohol,
            'temperature': temperature
        }
        BeerModel.update(query_beer, data_beer)
        return resp_updated_successfully('Beer')
Example #2
0
 def test_update_beer(self):
     populate_beers(2)
     query_beer = Beer.get_beer_id(1)
     Beer.update(query_beer, NEW_BEER_DATA)
     get_beer = Beer.get_beer_id(1)
     assert get_beer.id == 1
     assert get_beer.beer_name == NEW_BEER_DATA['beer_name']
 def test_update_beer(self):
     populate_beers(2)
     new_data = update_beer
     query_beer = Beer.get_beer_id(1)
     Beer.update(query_beer, new_data)
     get_beer = Beer.get_beer_id(1)
     assert get_beer.id == 1
     assert get_beer.beer_name == new_data['beer_name']
    def test_update_ingredients(self):
        populate_beers(3)
        new_beers = beers_data[1]
        new_ingredients = ingredients_data[2]['ingredients'][0]['names']

        query_beer = Beer.get_beer_id(2)
        query_ingredients = BeerIngredients.filter_beer_id(query_beer.id)
        count = 0
        for ingredient in new_ingredients:
            data_ingredients = {
                'ingredient_name': ingredient,
                'beer_id': query_beer.id
            }
            query_ingredient = query_ingredients[count]
            BeerIngredients.update(query_ingredient, data_ingredients)
            count += 1

        Beer.update(query_beer, new_beers)

        query_update_ingredients = BeerIngredients.filter_beer_id(query_beer.id)
        serialized = ingredients_serializer(query_update_ingredients, True)
        for r in range(0, len(serialized)):
            assert serialized[r]['ingredient_name'] == new_ingredients[r]