def test_search_movies(logged_in_client, field):
    movies, genres = populate_db(num_movies=100, num_genres=50)

    r = logged_in_client.get(MOVIES_URL)
    assert r.data["count"] == len(movies)

    for movie in movies:
        r = logged_in_client.get(MOVIES_URL + "?{}={}".format(field, movie[field]))

        results = get_all_objects_pagination(logged_in_client, r)
        expected_results = list(filter(lambda m: m[field] == movie[field], movies))

        assert r.data["count"] == len(expected_results)

        for result in results:
            assert any([movies_equal(result, m, ignore_description=True) for m in expected_results])
def test_search_movies_by_genre(logged_in_client):
    movies, genres = populate_db(num_movies=100, num_genres=50)

    r = logged_in_client.get(MOVIES_URL)
    assert r.data["count"] == len(movies)

    for genre in genres:
        genre_title = genre["title"]
        r = logged_in_client.get(MOVIES_URL + "?genre={}".format(genre_title))

        results = get_all_objects_pagination(logged_in_client, r)
        expected_results = list(filter(lambda m: genre_title in [g["title"] for g in m["genres"]], movies))

        assert r.data["count"] == len(expected_results)

        for result in results:
            assert any([movies_equal(result, m, ignore_description=True) for m in expected_results])
def test_list_movies(logged_in_client):
    movies, genres = populate_db(num_movies=100, num_genres=50)

    r = logged_in_client.get(MOVIES_URL)
    returned_movies = get_all_objects_pagination(logged_in_client, r)

    assert r.data["count"] == len(movies)

    for movie in returned_movies:
        assert any([movies_equal(movie, m, ignore_description=True) for m in movies])
Exemple #4
0
def test_get_rental(logged_in_client):
    num_rentals = 1
    movies, genres = populate_db(num_movies=1, num_genres=1)
    rentals = create_rentals(movies,
                             logged_in_client.user,
                             num_rentals=num_rentals)

    r = logged_in_client.get(RENTAL_URL.format(uuid=rentals[0]["uuid"]))
    assert r.status_code == 200
    rental = r.data

    #TODO: really needed?
    rental["movie"] = str(rental["movie"])
    assert rentals_equal(rental, rentals[0])
Exemple #5
0
def test_get_rentals(logged_in_client):
    num_rentals = 10
    movies, genres = populate_db(num_movies=num_rentals * 2, num_genres=5)
    rentals = create_rentals(movies,
                             logged_in_client.user,
                             num_rentals=num_rentals)

    r = logged_in_client.get(RENTALS_URL)

    assert r.status_code == 200
    returned_rentals = get_all_objects_pagination(logged_in_client, r)
    assert len(returned_rentals) == num_rentals

    for rental in returned_rentals:
        rental["movie"] = str(
            rental["movie"]
        )  # uuid is returned as UUID obj, cast to str for equality
        assert any([rentals_equal(rental, r) for r in rentals])
def test_get_nonexistent_movie(logged_in_client):
    r = logged_in_client.get(MOVIE_URL.format(uuid=uuid.uuid4()))
    assert r.status_code == 404
def test_get_movie(logged_in_client):
    movies, genres = populate_db(num_movies=10, num_genres=5)

    for movie in movies:
        r = logged_in_client.get(MOVIE_URL.format(uuid=movie["uuid"]))
        assert movies_equal(movie, r.data)
Exemple #8
0
def test_get_nonexistent_rental(logged_in_client):
    r = logged_in_client.get(RENTAL_URL.format(uuid=uuid.uuid4()))
    assert r.status_code == 404