def test_add_and_get_reviews(session_factory):
    repository = SqlAlchemyRepository(session_factory)
    movie1 = repository.get_movie("Moana", 2016)
    movie2 = repository.get_movie("Inception", 2010)
    review1 = Review(movie1, "Very good", 8)
    review2 = Review(movie2, "Excellent", 10)
    repository.add_review(review1)
    repository.add_review(review2)
    assert repository.get_reviews() == [review1, review2]
def test_can_retrieve_an_movie_and_add_a_comment_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 Comment, connecting it to the Movie and User.
    comment = make_comment('First death in Australia', author, movie)

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

    assert comment in movie_fetched.comments
    assert comment in author_fetched.comments
def test_repository_returns_date_of_next_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie = repo.get_movie(3)
    next_date = repo.get_year_of_next_movie(movie)

    assert next_date == 2016
def test_repository_returns_date_of_previous_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie = repo.get_movie(6)
    previous_date = repo.get_year_of_previous_movie(movie)

    assert previous_date == 2016
def test_repository_does_not_add_a_comment_without_a_user(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie = repo.get_movie(2)
    comment = Comment(None, movie, "Trump's onto it!", datetime.today())

    with pytest.raises(RepositoryException):
        repo.add_comment(comment)
def test_repository_returns_none_when_there_are_no_subsequent_movies(
        session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie = repo.get_movie(10)
    next_date = repo.get_year_of_next_movie(movie)

    assert next_date is None
def test_repository_returns_none_when_there_are_no_previous_movies(
        session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie = repo.get_movie(1)
    previous_date = repo.get_year_of_previous_movie(movie)

    assert previous_date is None
Ejemplo n.º 8
0
def test_repository_can_retrieve_a_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie = repo.get_movie(1)

    assert movie.title == "Guardians of the Galaxy"
    assert movie.year == 2014
    assert movie.runtime_minutes == 121
    assert movie.description == "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe."
def test_repository_can_add_a_comment(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    user = repo.get_user('thorke')
    movie = repo.get_movie(2)
    comment = make_comment("Trump's onto it!", user, movie)

    repo.add_comment(comment)

    assert comment in repo.get_comments()
Ejemplo n.º 10
0
def test_repository_can_add_a_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie1 = Movie("Sam I am", 2000)
    movie1.description = "Sam is sam he is"
    movie1.director = Director('James')
    movie1.runtime_minutes = 140
    repo.add_movie(movie1)
    movie = repo.get_movie(1001)

    assert movie == Movie('Sam I am', 2000)
Ejemplo n.º 11
0
def test_add_and_get_movies(session_factory):
    repository = SqlAlchemyRepository(session_factory)
    maquia = Movie("Maquia", 2018)
    iceage = Movie("Ice Age", 2002)
    maquia.description = "The Iorph people live far away from the world of humans, spending their days weaving " \
                         "Hibiol, a special cloth serving as a written chronicle every time. They age more slowly " \
                         "than humans and have the capacity to live for hundreds of years."
    maquia.runtime_minutes = 115
    iceage.description = "A Cronopio known as Scrat attempts to find a place to store his acorn for the winter. " \
                         "Eventually, as he tries to stomp it into the ground, he inadvertently causes a large " \
                         "crack to form in the ice that extends for miles before setting off a large avalanche " \
                         "which nearly crushes him."
    iceage.runtime_minutes = 81
    repository.add_movie(maquia)
    repository.add_movie(iceage)
    repository.add_movie(iceage)
    assert repository.get_movie("Maquia", 2018) == Movie("Maquia", 2018)
    assert repository.get_movie("A Silent Voice", 2016) is None
    movies = repository.get_movies()
    assert Movie("Ice Age", 2002) in movies and Movie("Maquia", 2018) in movies
def test_repository_can_add_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    number_of_movies = repo.get_number_of_movies()

    new_movie_rank = number_of_movies + 1

    movie = Movie('Wild Goose Lake', 2019, new_movie_rank)
    movie.genres = None
    movie.actors = None
    repo.add_movie(movie)

    assert repo.get_movie(new_movie_rank) == movie
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 == 'Guardians of the Galaxy'

    # Check that the Movie is commented as expected.
    comment_one = [
        comment for comment in movie.comments
        if comment.comment == 'This movie is okay.'
    ][0]
    comment_two = [
        comment for comment in movie.comments
        if comment.comment == 'Yeah Freddie, it is good.'
    ][0]

    assert comment_one.user.username == 'fmercury'
    assert comment_two.user.username == "thorke"

    # Check that the Movie is tagged as expected.
    assert movie.genres == 'Action,Adventure,Sci-Fi'
def test_repository_does_not_retrieve_a_non_existent_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

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