def test_get_reviews_for_movie(in_memory_repo): reviews_as_dict = movies_services.get_reviews_for_movie(1, in_memory_repo) # Check that 2 reviews were returned for movie with id 1. assert len(reviews_as_dict) == 2 # 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
def test_can_add_review(in_memory_repo): movie_id = 3 review_text = 'Really Enjoyableeeee!!' user = User('fmercury', 'ASdwdc9') # Call the service layer to add the review. movies_services.add_review(movie_id, review_text, user, in_memory_repo) # Retrieve the reviews for the movie from the repository. reviews_as_dict = movies_services.get_reviews_for_movie( movie_id, 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
def test_get_reviews_for_movie(in_memory_repo): #add a review to movie id 1 movie_id = 1 review_text = 'Really Enjoyableeeee!!' user = User('fmercury', 'ASdwdc9') # Call the service layer to add the review. movies_services.add_review(movie_id, review_text, user, in_memory_repo) reviews_as_dict = movies_services.get_reviews_for_movie(1, in_memory_repo) # Check that 1 review were returned for movie with id 1. assert len(reviews_as_dict) == 1 # Check that the reviews relate to the movie whose id is 1. review_ids = [review['movie_id'] for review in reviews_as_dict] review_ids = set(review_ids) assert 1 in review_ids and len(review_ids) == 1
def test_get_reviews_for_movie_without_reviews(in_memory_repo): reviews_as_dict = movies_services.get_reviews_for_movie(2, in_memory_repo) assert len(reviews_as_dict) == 0
def test_get_reviews_for_non_existent_movie(in_memory_repo): with pytest.raises(NonExistentMovieException): reviews_as_dict = movies_services.get_reviews_for_movie( 1009, in_memory_repo)