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]
Exemplo n.º 2
0
def test_repository_does_not_add_a_review_without_a_movie_properly_attached(
        session_factory):
    repo = SqlAlchemyRepository(session_factory)
    user = User('aidan', 'hi1234')

    review = Review(user, None, "Wow good movie", 9, datetime.today())
    user.add_review(review)
    repo.add_user(user)
    with pytest.raises(RepositoryException):
        repo.add_review(review)
Exemplo n.º 3
0
def test_repository_does_not_add_a_review_without_a_user(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    movie = Movie("Asdsa", 2014)
    movie.description = "Sam is sam he is"
    movie.director = Director('James')
    movie.runtime_minutes = 140
    repo.add_movie(movie)
    review = Review(None, movie, "Wow", 8, datetime.today())
    with pytest.raises(RepositoryException):
        repo.add_review(review)
Exemplo n.º 4
0
def test_repository_can_add_a_review(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    user = User('aidan', 'hi1234')
    movie = Movie("Asdsa", 2014)
    movie.description = "Sam is sam he is"
    movie.director = Director('James')
    movie.runtime_minutes = 140
    review = make_review("Wow good movie", user, movie, 9)

    repo.add_user(user)
    repo.add_movie(movie)
    repo.add_review(review)

    reviews = repo.get_reviews()
    assert len(reviews) == 1
    assert review in reviews