Exemplo n.º 1
0
def test_supports_paging_by_genre(client):
    filter = {'genres': ['History']}
    (movies0, results0) = get_movies(filter, 0, 20)
    assert len(list(movies0)) == 20
    assert results0 == 46014
    last_page = int(46014 / 20)
    (movies2, results2) = get_movies(filter, last_page, 20)
    assert len(list(movies2)) == results0 % 20
Exemplo n.º 2
0
def test_supports_paging_by_text(client):
    filter = {'text': 'bank robbery'}
    (movies0, results0) = get_movies(filter, 0, 20)
    assert len(list(movies0)) == 20
    assert results0 == 1084
    last_page = int(1084 / 20)
    (movies2, results2) = get_movies(filter, last_page, 20)
    assert len(list(movies2)) == 1084 % 20
Exemplo n.º 3
0
def test_supports_paging_by_cast(client):
    filter = {"cast": ["Tom Hanks"]}
    (movies0, results0) = get_movies(filter, 0, 20)
    assert len(list(movies0)) == 20
    assert results0 == 37
    assert movies0[0].get("title") == "Forrest Gump"
    (movies1, results1) = get_movies(filter, 1, 20)
    assert len(list(movies1)) == 17
    assert movies1[0].get("title") == "Captain Phillips"
Exemplo n.º 4
0
def test_supports_paging_by_cast(client):
    filter = {'cast': ['Tom Hanks']}
    (movies0, results0) = get_movies(filter, 0, 20)
    assert len(list(movies0)) == 20
    assert results0 == 51
    (movies1, results1) = get_movies(filter, 1, 20)
    assert len(list(movies1)) == 20
    (movies2, results2) = get_movies(filter, 2, 20)
    assert len(list(movies2)) == 11
Exemplo n.º 5
0
def test_supports_paging_by_cast(client):
    filter = {'cast': ['Tom Hanks']}
    (movies0, results0) = get_movies(filter, 0, 20)
    assert len(list(movies0)) == 20
    assert results0 == 37
    assert movies0[0].get('title') == 'Forrest Gump'
    (movies1, results1) = get_movies(filter, 1, 20)
    assert len(list(movies1)) == 17
    assert movies1[0].get('title') == 'Captain Phillips'
Exemplo n.º 6
0
def test_supports_paging_by_text(client):
    filter = {'text': 'bank robbery'}
    (movies0, results0) = get_movies(filter, 0, 20)
    assert len(list(movies0)) == 20
    assert results0 == 475
    assert movies0[0].get('title') == 'The Bank'
    last_page = int(475 / 20)
    (movies2, results2) = get_movies(filter, last_page, 20)
    assert len(list(movies2)) == 15
    assert movies2[0].get('title') == "Ugetsu"
Exemplo n.º 7
0
def test_supports_paging_by_text(client):
    filter = {"text": "bank robbery"}
    (movies0, results0) = get_movies(filter, 0, 20)
    assert len(list(movies0)) == 20
    assert results0 == 475
    assert movies0[0].get("title") == "The Bank"
    last_page = int(475 / 20)
    (movies2, results2) = get_movies(filter, last_page, 20)
    assert len(list(movies2)) == 15
    assert movies2[0].get("title") == "Ugetsu"
Exemplo n.º 8
0
def test_supports_paging_by_genre(client):
    filter = {'genres': ['History']}
    (movies0, results0) = get_movies(filter, 0, 20)
    assert len(list(movies0)) == 20
    assert results0 == 999
    assert movies0[0].get('title') == 'Braveheart'
    last_page = int(999 / 20)
    (movies2, results2) = get_movies(filter, last_page, 20)
    assert len(list(movies2)) == 19
    assert movies2[0].get('title') == 'Only the Dead'
Exemplo n.º 9
0
def test_supports_paging_by_genre(client):
    filter = {"genres": ["History"]}
    (movies0, results0) = get_movies(filter, 0, 20)
    assert len(list(movies0)) == 20
    assert results0 == 999
    assert movies0[0].get("title") == "Braveheart"
    last_page = int(999 / 20)
    (movies2, results2) = get_movies(filter, last_page, 20)
    assert len(list(movies2)) == 19
    assert movies2[0].get("title") == "Only the Dead"
Exemplo n.º 10
0
def test_text_search(client):
    # ensure you sort text results based on their metaScore!!
    filter = {'text': 'mongo'}
    (movies, results) = get_movies(filter, 0, 20)
    movies = list(movies)
    assert len(movies) == 9
    assert results == 9
    assert movies[0].get('title') == "Flash Gordon Conquers the Universe"
def test_text_search(client):
    # ensure you sort text results based on their metaScore!!
    filter = {"text": "mongo"}
    (movies, results) = get_movies(filter, 0, 20)
    movies = list(movies)
    assert len(movies) == 6
    assert results == 6
    assert movies[0].get("title") == "Flash Gordon"
Exemplo n.º 12
0
def api_get_movies():
    MOVIES_PER_PAGE = 20

    (movies, total_num_entries) = get_movies(None,
                                             page=0,
                                             movies_per_page=MOVIES_PER_PAGE)

    response = {
        "movies": movies,
        "page": 0,
        "filters": {},
        "entries_per_page": MOVIES_PER_PAGE,
        "total_results": total_num_entries,
    }

    return jsonify(response)
Exemplo n.º 13
0
def api_search_movies():
    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:\t', e)
        page = 0

    # determine the filters
    filters = {}
    return_filters = {}
    cast = request.args.getlist('cast')
    genre = request.args.getlist('genre')
    if cast:
        filters["cast"] = cast
        return_filters["cast"] = cast
    if genre:
        filters["genres"] = genre
        return_filters["genre"] = genre
    search = request.args.get('text')
    if search:
        filters["text"] = search
        return_filters["search"] = search

    # finally use the database and get what is necessary
    (movies, total_num_entries) = get_movies(filters, page, MOVIES_PER_PAGE)

    response = {
        "status": "success",
        "movies": movies,
        "page": page,
        "filters": return_filters,
        "entries_per_page": MOVIES_PER_PAGE,
        "total_results": total_num_entries,
    }

    return jsonify(response), 200
Exemplo n.º 14
0
def show_movies():
    MOVIES_PER_PAGE = 20

    # first determine the page of the movies to collect
    try:
        page = int(request.args.get('page'))
    except (TypeError, ValueError) as e:
        page = 0

    # format query string correctly for pagination
    args_copy = dict(request.args)

    args_copy["page"] = page - 1
    previous_page = urlencode(args_copy)

    args_copy["page"] = page + 1
    next_page = urlencode(args_copy)

    # determine any filters
    filters = {}
    genre = request.args.get('genre')
    if genre:
        filters["genres"] = genre
    search = request.args.get('search')
    if search:
        filters["$text"] = {"$search": search}

    # finally use the database and get what is necessary
    (movies, total_num_entries) = get_movies(filters, page, MOVIES_PER_PAGE)
    all_genres = get_all_genres()
    print(filters)

    # return the list of movies that works
    return render_template('movies.html',
                           movies=movies,
                           page=page,
                           filters=filters,
                           entries_per_page=MOVIES_PER_PAGE,
                           total_num_entries=total_num_entries,
                           previous_page=previous_page,
                           next_page=next_page,
                           all_genres=all_genres)
Exemplo n.º 15
0
def api_search_movies():
    DEFAULT_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:\t', e)
        page = 0

    # determine the filters
    filters = {}
    return_filters = {}
    cast = request.args.getlist('cast')
    genre = request.args.getlist('genre')
    if cast:
        filters["cast"] = cast
        return_filters["cast"] = cast
    if genre:
        filters["genres"] = genre
        return_filters["genre"] = genre
    search = request.args.get('text')
    if search:
        filters["text"] = search
        return_filters["search"] = search

    # finally use the database and get what is necessary
    (movies, total_num_entries) = get_movies(filters, page,
                                             DEFAULT_MOVIES_PER_PAGE)

    response = {
        "movies": movies,
        "page": page,
        "filters": return_filters,
        "entries_per_page": DEFAULT_MOVIES_PER_PAGE,
        "total_results": total_num_entries
    }

    return jsonify(response), 200
Exemplo n.º 16
0
def test_multiple_genre_search(client):
    filter = {'genres': ['Action', 'Adventure']}
    (movies, results) = get_movies(filter, 0, 25)
    assert len(list(movies)) == 25
    assert results == 8385
def test_multiple_genre_search(client):
    filter = {"genres": ["Action", "Adventure"]}
    (movies, results) = get_movies(filter, 0, 25)
    assert len(list(movies)) == 25
    assert results == 3805
def test_simple_text_search(client):
    (actual, _) = get_movies({"$text": {"$search": "King Kong"}}, 0, 20)
    assert len(list(actual)) >= 4
def test_basic_movies(client):
    (actual, num_found) = get_movies({}, 0, 20)
    assert num_found == 23539
    assert (len(list(actual))) == 20
def test_multiple_cast_search(client):
    filter = {"cast": ["Elon Musk", "Robert Redford", "Julia Roberts"]}
    (movies, results) = get_movies(filter, 0, 33)
    assert (len(list(movies))) == 33
    assert results == 62
def test_cast_search(client):
    filter = {"cast": ["Elon Musk"]}
    (movies, results) = get_movies(filter, 0, 20)
    assert len(list(movies)) == 1
    assert results == 1
Exemplo n.º 22
0
def test_genre_search(client):
    filter = {'genres': ['Action']}
    (movies, results) = get_movies(filter, 0, 20)
    assert len(list(movies)) == 20
    assert results == 5917
Exemplo n.º 23
0
def test_multiple_cast_search(client):
    filter = {'cast': ['Elon Musk', 'Robert Redford', 'Julia Roberts']}
    (movies, results) = get_movies(filter, 0, 33)
    assert (len(list(movies))) == 33
    assert results == 75
def test_genre_search(client):
    filter = {"genres": ["Action"]}
    (movies, results) = get_movies(filter, 0, 20)
    assert len(list(movies)) == 20
    assert results == 2539