コード例 #1
0
 def test_filter_beer_by_alcohol(self):
     populate_beers(2)
     beer_alcohol = beers_data[0]['alcohol']
     query_filter_alcohol = Beer.filter_beer_alcohol(beer_alcohol)
     serialized = beers_serializer(query_filter_alcohol, True)
     assert serialized[0]['alcohol'] == beers_data[0]['alcohol']
     assert serialized[0]['beer_name'] == beers_data[0]['beer_name']
コード例 #2
0
 def test_filter_beer_by_temperature(self):
     populate_beers(2)
     beer_temperature = beers_data[0]['temperature']
     query_filter_temperature = Beer.filter_beer_temperature(beer_temperature)
     serialized = beers_serializer(query_filter_temperature, True)
     assert serialized[0]['temperature'] == beers_data[0]['temperature']
     assert serialized[0]['beer_name'] == beers_data[0]['beer_name']
コード例 #3
0
 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']
コード例 #4
0
 def test_filter_beer_by_color(self):
     populate_beers(2)
     beer_color = beers_data[0]['color']
     query_filter_color = Beer.filter_beer_color(beer_color)
     serialized = beers_serializer(query_filter_color, True)
     assert serialized[0]['color'] == beers_data[0]['color']
     assert serialized[0]['beer_name'] == beers_data[0]['beer_name']
コード例 #5
0
 def test_filter_beer_by_alcohol(self):
     populate_beers(2)
     beer_alcohol = BEERS_DATA[0]['alcohol']
     query_filter_alcohol = Beer.filter_beer_alcohol(beer_alcohol)
     serialized = beers_serializer(query_filter_alcohol, True)
     assert str(serialized[0]['alcohol']) == str(
         float(BEERS_DATA[0]['alcohol']))
     assert serialized[0]['beer_name'] == BEERS_DATA[0]['beer_name']
コード例 #6
0
 def test_filter_beer_by_temperature(self):
     populate_beers(2)
     beer_temperature = BEERS_DATA[0]['temperature']
     query_filter_temperature = Beer.filter_beer_temperature(
         beer_temperature)
     serialized = beers_serializer(query_filter_temperature, True)
     assert str(serialized[0]['temperature']) == str(
         float(BEERS_DATA[0]['temperature']))
     assert serialized[0]['beer_name'] == BEERS_DATA[0]['beer_name']
コード例 #7
0
    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)
コード例 #8
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)
コード例 #9
0
 def test_list_all_beers(self):
     populate_beers(2)
     get_all_beers = Beer.get_beers()
     serialized = beers_serializer(get_all_beers, True)
     assert len(serialized) > 0
     assert serialized[0]['beer_name'] == beers_data[0]['beer_name']