def load_reviews(data_path: str, repo: MemoryRepository, users): for data_row in read_csv_file(os.path.join(data_path, 'reviews.csv')): movie = repo.get_movie(int(data_row[2])) review = Review(movie, data_row[3], int(data_row[4])) review.user = users[data_row[1]] review.user.add_review(review) movie.add_review(review) repo.add_review(review)
def test_repository_can_add_review_and_get_reviews(in_memory_repo): user = in_memory_repo.get_user('fmercury') movie = in_memory_repo.get_movie(320) review = Review(in_memory_repo.get_movie(320), 'It is very exciting', 6) review.user = user review.user.add_review(review) movie.add_review(review) in_memory_repo.add_review(review) reviews = in_memory_repo.get_reviews() assert (review in reviews) == True
def add_review(movie_id: int, review_text: str, username: str, rating: int, repo: AbstractRepository): # Check that the movie exists. movie = repo.get_movie(movie_id) if movie is None: raise NonExistentArticleException user = repo.get_user(username) if user is None: raise UnknownUserException # Create review. review = Review(movie, review_text, rating) review.user = user review.user.add_review(review) movie.add_review(review) # Update the repository. repo.add_review(review)