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

    movie = repo.get_movie(1)

    # Check that the movie has the expected title.
    assert movie.title == 'Prometheus'
def test_repo_does_not_add_review_without_a_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie = repo.get_movie(0)
    review = Review(movie, "good", 7)

    with pytest.raises(RepositoryException):
        repo.add_review(review)
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_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_repo_can_retrieve_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie = repo.get_movie(1)

    # Check that the Movie has the expected title.
    assert movie.title == 'Guardians of the Galaxy'

    # Check that the Movie is reviewed as expected.
    user = repo.get_user('nton939')
    assert user.reviews[
        0].review_text == 'GOTG is my new favourite movie of all time!'

    # Check that the Movie has the expected genres.
    assert movie.genres == [
        Genre('Action'), Genre('Adventure'),
        Genre('Sci-Fi')
    ]
def test_repo_can_add_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    number_of_movies = repo.get_number_of_movies()

    new_movie_id = number_of_movies + 1

    movie = Movie("WOW", 2020)
    movie.rank = new_movie_id
    movie.description = "This is the best movie in the world."
    movie.director = Director("Barraza")
    movie.runtime_minutes = 100
    movie.rating = 100
    movie.votes = 100
    movie.revenue = 100
    movie.metascore = 100
    repo.add_movie(movie)

    assert repo.get_movie(new_movie_id) == movie
def test_repo_does_not_retrieve_non_existent_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie = repo.get_movie(1001)
    assert movie is None