Пример #1
0
def test_save_reviewed_movie(empty_session):
    # Create Movie User objects.
    movie = make_movie()
    empty_session.add(movie)
    user = make_user()

    # Save the new Movie.
    empty_session.add(movie)
    empty_session.commit()

    # Create a new review that is bidirectionally linked with the User and Movie.
    review_text = "Some review text."
    review = add_review(review_text, user, movie)

    # Test test_saving_of_movie() checks for insertion into the movies table.
    rows = list(empty_session.execute('SELECT id FROM movies'))
    movie_key = rows[0][0]

    # Test test_saving_of_users() checks for insertion into the users table.
    rows = list(empty_session.execute('SELECT id FROM users'))
    user_key = rows[0][0]

    # Check that the reviews table has a new record that links to the movies and users
    # tables.
    rows = list(
        empty_session.execute('SELECT user_id, movie_id, review FROM reviews'))
    assert rows == [(user_key, movie_key, review_text)]
Пример #2
0
def test_saving_of_review(empty_session):
    movie_key = insert_movie(empty_session)
    user_key = insert_user(empty_session, ("Andrew", "1234"))

    rows = empty_session.query(Movie).all()
    movie = rows[0]
    users = empty_session.query(User).all()
    user = None
    for u in users:
        if u.username == 'Andrew':
            user = u
            break
    # Create a new Review that is bidirectionally linked with the User and Movie.
    review_text = "Some review text."
    review = add_review(review_text, user, movie)

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

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

    assert rows == [(user_key, movie_key, review_text)]
def test_repository_can_add_a_review(in_memory_repo):
    user = User('thorke', '902fjsdf')
    movie = in_memory_repo.get_movie(2)
    review = add_review("Highly recommended!", user, movie, 0)

    in_memory_repo.add_review(review, movie, user)

    assert review in in_memory_repo.get_reviews()
Пример #4
0
def load_reviews(data_path: str, repo: MemoryRepository, users):
    for data_row in read_csv_file(os.path.join(data_path, 'reviews.csv')):
        review = add_review(
            review_text=data_row[3],
            user=users[data_row[1]],
            movie=repo.get_movie(int(data_row[2]))
        )
        repo.add_review(review)
def test_repository_can_add_a_review(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    user = User('thorke', '902fjsdf')
    movie = repo.get_movie(2)
    review = add_review("Highly recommended!", user, movie, 0)

    repo.add_review(review)

    assert review in repo.get_reviews()
def test_can_retrieve_a_movie_and_add_a_review_to_it(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    # Fetch Movie and User.
    movie = repo.get_movie(5)
    author = repo.get_user('thorke')

    # Create a new Review, connecting it to the Movie and User.
    review = add_review('First death in Australia', author, movie)

    movie_fetched = repo.get_movie(5)
    author_fetched = repo.get_user('thorke')

    assert review in movie_fetched.reviews
    assert review in author_fetched.reviews
def test_make_review_establishes_relationships(movie, user):
    review_text = 'Cool movie!'
    rating = 0
    review = add_review(review_text, user, movie, rating)

    # Check that the User object knows about the Review.
    assert review in user.reviews

    # Check that the Review knows about the User.
    assert review.user is user

    # Check that Movie knows about the Review.
    assert review in movie.reviews

    # Check that the Review knows about the Movie.
    assert review.movie is movie