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

    movie = Movie('Avengers : End Game', 2019)
    repo.add_movie(movie)

    assert repo.get_movie("Avengers : End Game", 2019) == movie and repo.get_movie("Avengers : End Game", 2019) is movie
def test_repository_can_retrieve_movie_by_title_and_release_year(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie = repo.get_movie("Guardians of the Galaxy", 2014)

    # Check that the movie has expected attributes
    assert movie.description == "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe."
    assert movie.director == Director("James Gunn")
    assert movie.runtime_minutes == 121
    actors = iter(movie.actors)
    assert next(actors) == Actor("Chris Pratt")
    assert next(actors) == Actor("Vin Diesel")
    assert next(actors) == Actor("Bradley Cooper")
    assert next(actors) == Actor("Zoe Saldana")

    # Check that the movie has the expected genre(s)
    assert movie.is_classified_as(Genre("Action"))
    assert movie.is_classified_as(Genre("Adventure"))
    assert movie.is_classified_as(Genre("Sci-Fi"))

    # Check that the movie has the correct reviews
    assert movie.number_of_reviews == 3

    review_1 = [review for review in movie.reviews if review.review_text == "This movie is great!"][0]
    review_2 = [review for review in movie.reviews if review.review_text == "This movie is awesome"][0]
    assert review_1.review_author.username == "fmercury"
    assert review_2.review_author.username == "thorke"