def test_repository_can_get_reviews_from_a_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    movie_reviews = iter(repo.get_movie_reviews(repo.get_movie_by_index(1)))

    assert next(movie_reviews).review_text == "This movie is great!"
    assert next(movie_reviews).review_text == "This movie is awesome"
    assert next(movie_reviews).review_text == "Love it!"
    with pytest.raises(StopIteration):
        assert repr(next(movie_reviews).review_text) == StopIteration
def test_repository_can_add_a_review(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    user = repo.get_user('thorke')
    movie = repo.get_movie_by_index(10)
    review = Review(user=user,
                    movie=movie,
                    review_text='Great!',
                    rating=10,
                    timestamp=date.today())
    assert repo.get_total_number_of_reviews() == 4
    assert review in repo.get_movie_reviews(movie)
    assert review in repo.get_user_reviews(user)