コード例 #1
0
def test_add_review(in_memory_repo):
    user = User('Dave', '123456789')
    in_memory_repo.add_user(user)
    movie_1 = in_memory_repo.get_movie_by_id(1)
    #review_1 = Review(user, movie_1, "Good!", 8.8)
    review_1 = make_review(user, movie_1, "Good!")
    in_memory_repo.add_review(review_1)
    assert len(in_memory_repo.get_reviews()) == 4
コード例 #2
0
def test_repository_can_add_review(in_memory_repo):
    user = in_memory_repo.get_user('thorke')
    movie = in_memory_repo.get_movie(2)
    review_text = "This movie was very enjoyable."
    rating = 8
    review = make_review(review_text, user, movie, rating)
    in_memory_repo.add_review(review)
    assert review in in_memory_repo.get_review()
コード例 #3
0
def test_write_reviews(movie, user):
    review_text = "This movie was very enjoyable."
    rating = 8
    review = make_review(review_text, user, movie, rating)

    assert review in user.reviews
    assert review.user is user
    assert review in movie.reviews
    assert review.movie is movie
コード例 #4
0
def add_review(user_name: str, movie_id: int, review_text: str,
               repo: AbstractRepository):
    movie = repo.get_movie_by_id(int(movie_id))

    if movie is None:
        raise NonExistentMovieException

    user = repo.get_user(user_name)
    if user is None:
        raise UnknownUserException

    review = make_review(user, movie, review_text)

    repo.add_review(review)
コード例 #5
0
def add_review(movie_rank: int, review_text: str, rating: int, username: str, repo: AbstractRepository):
    # Check that the movie exists.
    movie = repo.get_movie(movie_rank)
    if movie is None:
        raise NonExistentMovieException

    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    # Create review.
    review = make_review(review_text, user, movie, rating)

    # Update the repository.
    repo.add_review(review)
コード例 #6
0
def load_reviews(data_path: str, repo: MemoryRepository, users):
    filename = os.path.join(data_path, 'reviews.csv')
    with open(filename, mode='r', encoding='utf-8-sig') as csvfile:
        review_file_reader = csv.DictReader(csvfile)
        for row in review_file_reader:
            user_name = row['username']
            user = repo.get_user(user_name)
            movie_id = row['movie_id']
            movie = repo.get_movie_by_id(int(movie_id))
            review_text = row['review_text']
            # rating = int(row['rating'])
            # movie_timestamp = datetime.fromisoformat(row['timestamp'])
            #movie_timestamp = row['timestamp']
            review = make_review(user, movie, review_text)
            # review._timestamp = movie_timestamp
            repo.add_review(review)
コード例 #7
0
ファイル: test_orm.py プロジェクト: yyou211/yyou211_235_A3
def test_saving_of_comment(empty_session):
    article_key = insert_article(empty_session)
    user_key = insert_user(empty_session, ("Andrew", "1234"))

    rows = empty_session.query(Movie).all()
    movie = rows[0]
    user = empty_session.query(User).filter(User._User__user_name == "Andrew").one()

    # Create a new Comment that is bidirectionally linked with the User and Article.
    review_text = "Some comment text."
    comment = make_review(user, movie,review_text)

    # Note: if the bidirectional links between the new Comment and the User and
    # Article objects hadn't been established in memory, they would exist following
    # committing the addition of the Comment to the database.
    empty_session.add(comment)
    empty_session.commit()

    rows = list(empty_session.execute('SELECT user_id, movie_id, review FROM reviews'))

    assert rows == [(user_key, article_key, review_text)]