def test_repo_can_add_review(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    #user = repo.get_user('nton939')
    movie = repo.get_movie(500)
    review = Review(movie, "wow!", 10)
    #user.add_review(review)

    repo.add_review(review)

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

    # Fetch Movie and User.
    movie = repo.get_movie(1000)
    user = repo.get_user('nton939')

    # Create a new Review, connecting it to the Movie and User.
    review = Review(movie, "So good!", 9)
    user.add_review(review)
    repo.add_review(review)

    fetched_reviews = repo.get_reviews()
    fetched_user = repo.get_user('nton939')
    fetched_movie = repo.get_movie(1000)

    assert review in fetched_reviews
    assert review in fetched_user.reviews
    assert fetched_reviews[1].movie == fetched_movie
def test_repo_can_retrieve_reviews(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    assert len(repo.get_reviews()) == 1