def test_can_retrieve_an_movie_and_add_a_review_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 Review, connecting it to the Movie and User. review = make_review('First death in Australia', author, movie) movie_fetched = repo.get_movie(5) author_fetched = repo.get_user('thorke') assert review in movie_fetched.reviews assert review in author_fetched.reviews
def test_repository_returns_date_of_next_movie(session_factory): repo = SqlAlchemyRepository(session_factory) movie = repo.get_movie(3) next_date = repo.get_date_of_next_movie(movie) assert next_date.isoformat() == '2017-01-01'
def test_repository_returns_date_of_previous_movie(session_factory): repo = SqlAlchemyRepository(session_factory) movie = repo.get_movie(6) previous_date = repo.get_date_of_previous_movie(movie) assert previous_date.isoformat() == '2015-01-01'
def test_repository_does_not_add_a_review_without_a_user(session_factory): repo = SqlAlchemyRepository(session_factory) movie = repo.get_movie(2) review = Review(None, movie, "Trump's onto it!", datetime.today()) with pytest.raises(RepositoryException): repo.add_review(review)
def test_repository_returns_none_when_there_are_no_subsequent_movies( session_factory): repo = SqlAlchemyRepository(session_factory) movie = repo.get_movie(177) next_date = repo.get_date_of_next_movie(movie) assert next_date is not 0
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_date_of_previous_movie(movie) assert previous_date is not 0
def test_repository_can_add_a_review(session_factory): repo = SqlAlchemyRepository(session_factory) user = repo.get_user('thorke') movie = repo.get_movie(2) review = make_review("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_movies() new_movie_id = number_of_movies + 1 movie = Movie(date.fromisoformat('2020-03-09'), "wa", "ga", "", "img", 5000, "as,df", 124, "asdf", 44, new_movie_id) repo.add_movie(movie) assert repo.get_movie(new_movie_id) == 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 reviewed as expected. review_one = [ review for review in movie.reviews if review.review == 'Oh no, COVID-19 has hit New Zealand' ][0] review_two = [ review for review in movie.reviews if review.review == 'Yeah Freddie, bad news' ][0] assert review_one.user.username == 'fmercury' assert review_two.user.username == "thorke" # Check that the Movie is genreged as expected. assert movie.is_genreged_by(Genre('Adventure')) assert movie.is_genreged_by(Genre('Adventure'))
def test_repository_does_not_retrieve_a_non_existent_movie(session_factory): repo = SqlAlchemyRepository(session_factory) movie = repo.get_movie(9999) assert movie is None