def load_comments(data_path: str, repo: MemoryRepository, users): for data_row in read_csv_file(os.path.join(data_path, 'comments.csv')): comment = make_review(comment_text=data_row[3], user=users[data_row[1]], movie=repo.get_movie(int(data_row[2])), timestamp=datetime.fromisoformat(data_row[4])) repo.add_review(comment)
def load_reviews(data_path: str, repo: MemoryRepository, users): for data_row in read_csv_file(os.path.join(data_path, 'reviews.csv')): review = make_review(review_text=data_row[3], user=users[data_row[1]], movie=repo.get_movie(int(data_row[2])), review_num=int(data_row[-1])) repo.add_review(review)
def test_repository_can_add_a_review(in_memory_repo): user = in_memory_repo.get_user('thorke') movie = in_memory_repo.get_movie(2) review = make_review("Trump's onto it!", user, movie,4) in_memory_repo.add_review(review) assert review in in_memory_repo.get_reviews()
def test_repository_can_add_a_comment(in_memory_repo): user = in_memory_repo.get_user('thorke') movie = in_memory_repo.get_movie(2) comment = make_review("nice nice nice", user, movie) in_memory_repo.add_review(comment) assert comment in in_memory_repo.get_reviews()
def add_review(movie_id: int, review_text: str, user: User, repo: AbstractRepository): # Check that the movie exists. movie = repo.get_movie(movie_id) if movie is None: raise NonExistentMovieException if user is None: raise UnknownUserException # Create review. review = make_review(review_text, user, movie) # Update the repository. repo.add_review(review)
def test_make_review_establishes_relationships(movie, user): review_text = 'COVID-19 in the USA!' review = make_review(review_text, user, movie, 8) # Check that the User object knows about the Comment. assert review in user.reviews # Check that the Comment knows about the User. assert review.user is user # Check that Article knows about the Comment. assert review in movie.review # Check that the Comment knows about the Article. assert review.movie is movie
def add_comment(movie_id: int, comment_text: str, username: str, repo: AbstractRepository): # Check that the movie exists. movie = repo.get_movie(movie_id) if movie is None: raise NonExistentMovieException user = repo.get_user(username) if user is None: raise UnknownUserException # Create comment. comment = make_review(comment_text, user, movie) # Update the repository. repo.add_review(comment)
def add_review(movie_rank: int, review_text: str, username: str, repo: AbstractRepository, review_int: int): # Check that the article exists. movie = repo.get_movie(movie_rank) if movie is None: raise NonExistentArticleException user = repo.get_user(username) if user is None: raise UnknownUserException # Create comment. review = make_review(review_text, user, movie, review_int) # Update the repository. repo.add_review(review)