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 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')
def delete(beer_id): query_beer = BeerModel.get_beer_id(beer_id) if not query_beer: return error_does_not_exist(None, beer_id) query_ingredients = IngredientsModel.filter_beer_id(beer_id) for query in query_ingredients: ingredient = IngredientsModel.get_ingredient_id(query.id) ingredient.delete() query_beer.delete() return resp_deleted_successfully('Beer')
def get(beer_id): query_beer = BeerModel.get_beer_id(beer_id) if not query_beer: error_does_not_exist(None, beer_id) serialized = beers_serializer(query_beer, False) query_filter = IngredientsModel.filter_beer_id(beer_id) count = 0 ingredients_list = [] for item in query_filter: ingredients_list.append(ingredients_serializer(item, False)) serialized['ingredients'] = ingredients_list count += 1 return resp_content_successfully(serialized)
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]
def test_delete_beer(self): populate_beers(2) query_beer = Beer.get_beer_id(1) query_beer.delete() get_beer = Beer.get_beer_id(1) assert get_beer is None
def test_create_beer(self): populate_beers(2) get_beer = Beer.get_beer_id(1) assert get_beer.id == 1 assert get_beer.beer_name == beers_data[0]['beer_name']
def test_create_beer(self): populate_beers(2) get_beer = Beer.get_beer_id(1) assert get_beer.id == 1 assert get_beer.beer_name == BEERS_DATA[0]['beer_name']