Example #1
0
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_comment(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_comment(comment)
def test_repository_can_add_a_comment(in_memory_repo):
    user = in_memory_repo.get_user('thorke')
    movie = in_memory_repo.get_movie(1)
    comment = make_comment("Trump's onto it!", user, movie)

    in_memory_repo.add_comment(comment)

    assert comment in in_memory_repo.get_comments()
Example #3
0
def test_make_comment_establishes_relationships(movie, user):
    comment_text = 'COVID-19 in the USA!'
    comment = make_comment(comment_text, user, movie)
    # Check that the User object knows about the Comment.
    assert comment in user.comments
    # Check that the Comment knows about the User.
    assert comment.user is user
    # Check that Article knows about the Comment.
    assert comment in movie.comments
    # Check that the Comment knows about the Article.
    assert comment.movie is movie
def add_comment(movie_id: int, comment_text: str, username: str, repo: AbstractRepository):
    # Check that the movies 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_comment(comment_text, user, movie)

    # Update the repository.
    repo.add_comment(comment)