def test_filter_beer_by_name(self):
     populate_beers(2)
     beer_name = beers_data[0]['beer_name']
     query_filter_name = Beer.filter_beer_name(beer_name)
     serialized = beers_serializer(query_filter_name, True)
     assert serialized[0]['id'] == 1
     assert serialized[0]['beer_name'] == beers_data[0]['beer_name']
Esempio n. 2
0
    def get(self):
        beer_name = self.beer_args['beer_name']
        color = self.beer_args['color']
        alcohol = self.beer_args['alcohol']
        temperature = self.beer_args['temperature']
        ingredient = self.ingredients_args['ingredient']

        query_beers = BeerModel.get_beers()
        serialized = beers_serializer(query_beers, True)
        if not query_beers:
            return resp_empty_data_base()

        if beer_name:
            query_name = BeerModel.filter_beer_name(beer_name)
            error_does_not_exist(query_name, beer_name)
            serialized = serializer(query_name)
            return resp_content_successfully(serialized)

        if color:
            query_color = BeerModel.filter_beer_color(color)
            error_does_not_exist(query_color, color)
            serialized = serializer(query_color)
            return resp_content_successfully(serialized)

        if alcohol:
            query_alcohol = BeerModel.filter_beer_alcohol(alcohol)
            error_does_not_exist(query_alcohol, alcohol)
            serialized = serializer(query_alcohol)
            return resp_content_successfully(serialized)

        if temperature:
            query_temperature = BeerModel.filter_beer_temperature(temperature)
            error_does_not_exist(query_temperature, temperature)
            serialized = serializer(query_temperature)
            return resp_content_successfully(serialized)

        if ingredient:
            query_ingredient = IngredientsModel.filter_ingredient_name(
                ingredient)
            error_does_not_exist(query_ingredient, ingredient)
            serialized = add_ingredients(query_beers, serialized)
            response_parser = parser_beers(serialized, ingredient)
            return resp_content_successfully(response_parser)

        serialized = add_ingredients(query_beers, serialized)
        return resp_content_successfully(serialized)