def test_get_comments_for_movie(in_memory_repo): comments_as_dict = feed_services.get_comments_for_movie(1, in_memory_repo) # Check that 2 comments were returned for movie with rank 1. assert len(comments_as_dict) == 3 # Check that the comments relate to the movie whose rank is 1. movie_ranks = [comment['movie_rank'] for comment in comments_as_dict] movie_ranks = set(movie_ranks) assert 1 in movie_ranks and len(movie_ranks) == 1
def test_can_add_comment(in_memory_repo): movie_rank = 3 comment_text = 'The loonies are stripping the supermarkets bare!' username = '******' # Call the service layer to add the comment. feed_services.add_comment(movie_rank, comment_text, username, in_memory_repo) # Retrieve the comments for the movie from the repository. comments_as_dict = feed_services.get_comments_for_movie(movie_rank, in_memory_repo) # Check that the comments include a comment with the new comment text. assert next( (dictionary['comment_text'] for dictionary in comments_as_dict if dictionary['comment_text'] == comment_text), None) is not None
def test_get_comments_for_movie_without_comments(in_memory_repo): comments_as_dict = feed_services.get_comments_for_movie(2, in_memory_repo) assert len(comments_as_dict) == 0
def test_get_comments_for_non_existent_movie(in_memory_repo): with pytest.raises(NonExistentMovieException): comments_as_dict = feed_services.get_comments_for_movie( 17, in_memory_repo)