Esempio n. 1
0
def test_can_add_review():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)
    # ["Dolittle", "Klaus", "Up"]
    movie_id = 3
    review_text = "Very good!"
    username = "******"
    rating = 5
    mem_repo.add_user(User(username, "CS235"))

    # call the service layer to add the comment
    movie_services.add_review(movie_id, review_text, rating, username,
                              mem_repo)

    # retrieve the reviews for the movie from the repository
    reviews_as_dict = movie_services.get_reviews_for_movie(movie_id, mem_repo)

    # check that the reviews inclue a review with the new review text.
    assert next((dictionary['review_text'] for dictionary in reviews_as_dict
                 if dictionary['review_text'] == review_text),
                None) is not None
Esempio n. 2
0
def test_get_reviews_for_movie(in_memory_repo):
    reviews_as_dict = movies_services.get_reviews_for_movie(1, in_memory_repo)

    # Check that 3 reviews were returned for movie with id 1
    assert len(reviews_as_dict) == 3

    # Check that the reviews relate to the movie whose id is 1
    movie_ids = [review['movie_id'] for review in reviews_as_dict]
    movie_ids = set(movie_ids)
    assert 1 in movie_ids and len(movie_ids) == 1
Esempio n. 3
0
def test_can_add_review(in_memory_repo):
    movie_id = 3
    review_text = 'The loonies are stripping the supermarkets bare!'
    username = '******'

    # Call the service layer to add the comment.
    movie_services.add_review(movie_id, review_text, username, in_memory_repo)

    # Retrieve the comments for the article from the repository.
    reviews_as_dict = movie_services.get_reviews_for_movie(
        movie_id, in_memory_repo)

    # Check that the comments include a comment with the new comment text.
    assert next((dictionary['review_text'] for dictionary in reviews_as_dict
                 if dictionary['review_text'] == review_text),
                None) is not None
Esempio n. 4
0
def test_can_add_review(in_memory_repo):
    movie_id = 2
    review_text = 'What a great movie!'
    username = '******'
    rating = 10

    # Call the service layer to add the review
    movies_services.add_review(review_text=review_text,
                               username=username,
                               movie_id=movie_id,
                               rating=rating,
                               repo=in_memory_repo)

    # Retrieve the reviews for the movie from the repository
    reviews_as_dict = movies_services.get_reviews_for_movie(
        movie_id=movie_id, repo=in_memory_repo)

    # Check that the reviews include a review with the new review text
    assert next((dictionary['review_text'] for dictionary in reviews_as_dict
                 if dictionary['review_text'] == review_text),
                None) is not None
Esempio n. 5
0
def test_get_reviews_for_movie_without_reviews(in_memory_repo):
    reviews_as_dict = movies_services.get_reviews_for_movie(8, in_memory_repo)
    assert len(reviews_as_dict) == 0
Esempio n. 6
0
def test_get_reviews_for_non_existent_movies(in_memory_repo):
    with pytest.raises(NonExistentMovieException):
        reviews_as_dict = movies_services.get_reviews_for_movie(
            30, in_memory_repo)