def test_can_retrieve_a_movie_and_add_a_review_to_it(session_factory): repo = SqlAlchemyRepository(session_factory) # Fetch Article and User. movie = repo.get_movie(2) author = repo.get_user('thorke') # Create a new Comment, connecting it to the Article and User. review = make_comment('First death in Australia', author, movie) movie_fetched = repo.get_movie(2) author_fetched = repo.get_user('thorke') assert review in movie_fetched.review assert review in author_fetched.reviews
def test_repository_does_not_add_a_review_without_a_user(session_factory): repo = SqlAlchemyRepository(session_factory) movie = repo.get_movie(2) user = repo.get_user('thorke') review = Review(user, movie, "Trump's onto it!", 5) with pytest.raises(RepositoryException): repo.add_review(review)
def test_repository_can_add_a_reviews(session_factory): repo = SqlAlchemyRepository(session_factory) user = repo.get_user('thorke') movie = repo.get_movie(2) review = make_comment("Trump's onto it!", user, movie) repo.add_review(review) assert review in repo.get_reviews()
def test_repository_can_add_movie(session_factory): repo = SqlAlchemyRepository(session_factory) number_of_movies = repo.get_number_of_movie() new_movie_rank = number_of_movies + 1 desc = "" movie = Movie("Cool World", 2015) repo.add_movie(movie, new_movie_rank, desc) 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 Article has the expected title. assert movie.title == 'Guardians of the Galaxy' # Check that the Article is commented as expected. review_one = [ review for review in movie.review if review.review_text == 'Oh no, COVID-19 has hit New Zealand' ][0] review_two = [ review for review in movie.review if review.review_text == 'Yeah Freddie, bad news' ][0] assert review_one.user.username == 'fmercury' assert review_two.user.username == "thorke" # Check that the Article is tagged as expected. assert movie.is_genred_by(Genre('Health')) assert movie.is_genred_by(Genre('New Zealand'))
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