Example #1
0
def get_similar_beer(beer_id):
    '''
    The client sends a get request which represents a request for beers similar
    to the beer in the url
    '''
    try:
        beer_id = int(beer_id)
    except ValueError as e:
        print 'Bad beer id %s' % beer_id
        return jsonify({}), 400

    recommended_beer_id = database.get_nearest_beer(beer_id)
    if recommended_beer_id:
        return jsonify(database.get_metadata(recommended_beer_id))
    else:
        return jsonify({}), 404
Example #2
0
 def test_get_nearest_beer(self):
     beer_recomendation = database.get_nearest_beer(2093)
     eq_(isinstance(beer_recomendation, (int)), True, 'get_nearest_beer should return a single beer id')
     eq_(database.get_nearest_beer(9999999), None, 'get_nearest_beer should gracefully return None for a bad beer id')