def test_faceted_search_should_also_support_paging(client): filter = {'cast': ['Susan Sarandon'], } result = get_movies_faceted(filter, 3, 20) assert(len(result[0]['movies'])) == 3 assert len(result[0]['rating']) == 1 assert len(result[0]['runtime']) == 2 assert result[1] == 63
def test_faceted_search_should_also_support_paging(client): filter = { "cast": ["Susan Sarandon"], } result = get_movies_faceted(filter, 1, 20) assert (len(result[0]["movies"])) == 18 assert len(result[0]["rating"]) == 3 assert len(result[0]["runtime"]) == 4 assert result[1] == 38
def test_faceted_search_should_return_rating_and_runtime_buckets(client): filter = {"cast": ["Tom Hanks"]} result = get_movies_faceted(filter, 0, 20) # expecting the first entry in the returned tuple to be a dictionary with # the key 'movies' assert len(result[0]["movies"]) == 20 assert len(result[0]["rating"]) == 5 assert len(result[0]["runtime"]) == 4 # expecting the second entry in the returned tuple to be the number of results assert result[1] == 37
def test_faceted_search_should_return_rating_and_runtime_buckets(client): filter = {'cast': ['Tom Hanks']} result = get_movies_faceted(filter, 0, 20) # expecting the first entry in the returned tuple to be a dictionary with # the key 'movies' assert len(result[0]['movies']) == 20 assert len(result[0]['rating']) == 5 assert len(result[0]['runtime']) == 4 # expecting the second entry in the returned tuple to be the number of results assert result[1] == 37 @ pytest.mark.faceted_search
def api_search_movies_faceted(): MOVIES_PER_PAGE = 20 # first determine the page of the movies to collect try: page = request.args.get('page') # if no page, get the first page (0 indexed) if page is None: page = 0 # otherwise pass the page along the client asked for else: page = int(page) except (TypeError, ValueError) as e: print('Got bad value for page, defaulting to 0:\t', e) page = 0 # determine the filters filters = {} return_filters = {} cast = request.args.getlist('cast') if cast: filters["cast"] = cast return_filters["cast"] = cast if not filters: return api_search_movies() # finally use the database and get what is necessary try: (movies, total_num_entries) = get_movies_faceted(filters, page, MOVIES_PER_PAGE) response = { "status": "success", "movies": movies.get('movies'), "facets": { "runtime": movies.get('runtime'), "rating": movies.get('rating') }, "page": page, "filters": return_filters, "entries_per_page": MOVIES_PER_PAGE, "total_results": total_num_entries, } return jsonify(response), 200 except Exception as e: return jsonify({'status': 'fail', 'error': str(e)})
def api_search_movies_faceted(): MOVIES_PER_PAGE = 20 # first determine the page of the movies to collect try: page = int(request.args.get('page', 0)) except (TypeError, ValueError) as e: print('Got bad value for page, defaulting to 0:\t', e) page = 0 # determine the filters filters = {} return_filters = {} cast = request.args.getlist('cast') if cast: filters["cast"] = cast return_filters["cast"] = cast if not filters: return api_search_movies() # finally use the database and get what is necessary try: (movies, total_num_entries) = get_movies_faceted(filters, page, MOVIES_PER_PAGE) print(total_num_entries) #print(movies) response = { "movies": movies.get('movies'), "facets": { "runtime": movies.get('runtime'), "rating": movies.get('rating') }, "page": page, "filters": return_filters, "entries_per_page": MOVIES_PER_PAGE, "total_results": total_num_entries, } return jsonify(response), 200 except Exception as e: return jsonify({'error': str(e)}), 400