def test_create_watch_list(): watchlist = WatchList() assert (f"Size of watchlist: {watchlist.size()}") == f"Size of watchlist: 0" watchlist.add_movie(Movie("Moana", 2016)) watchlist.add_movie(Movie("Ice Age", 2002)) watchlist.add_movie(Movie("Guardians of the Galaxy", 2012)) assert str(watchlist.first_movie_in_watchlist()) == '<Movie Moana, 2016>'
def test_check_size(): watchlist = WatchList() assert (f"Size of watchlist: {watchlist.size()}") == f"Size of watchlist: 0" watchlist.add_movie(Movie("Moana", 2016)) watchlist.add_movie(Movie("Ice Age", 2002)) watchlist.add_movie(Movie("Guardians of the Galaxy", 2012)) assert (f"Size of watchlist: {watchlist.size()}") == f"Size of watchlist: 3"
def test_select_movie(): watchlist = WatchList() watchlist.add_movie(Movie("Moana", 2016)) watchlist.add_movie(Movie("Ice Age", 2002)) watchlist.add_movie(Movie("Guardians of the Galaxy", 2012)) assert watchlist.select_movie_to_watch(1) == Movie("Ice Age", 2002) assert watchlist.select_movie_to_watch(2) == Movie("Guardians of the Galaxy", 2012) assert watchlist.select_movie_to_watch(3) == None
def test_change_release_year(): movie = Movie("Moana", 2016) movie.release_year = 1902 assert movie.release_year == 1902 with pytest.raises(ValueError): movie.release_year = 1830 with pytest.raises(TypeError): movie.release_year = '1830'
def test_remove_movie(): watchlist = WatchList() assert (f"Size of watchlist: {watchlist.size()}") == f"Size of watchlist: 0" watchlist.add_movie(Movie("Moana", 2016)) watchlist.add_movie(Movie("Ice Age", 2002)) assert str(watchlist.first_movie_in_watchlist()) == '<Movie Moana, 2016>' watchlist.remove_movie(Movie("Moana", 2016)) assert (f"Size of watchlist: {watchlist.size()}") == f"Size of watchlist: 1" assert str(watchlist.first_movie_in_watchlist()) == '<Movie Ice Age, 2002>'
def test_compare_Movie(): movie = Movie("Moana", 2016) movie2 = Movie("Moana", 2016) movie3 = Movie("Lethal Weapon", 1985) movie4 = Movie("Lethal Bandanna", 1985) movie5 = Movie("Moanb", 2016) assert (movie == movie2) == True assert (movie == movie3) == False assert (movie3 == movie4) == False assert (movie5 == movie2) == False
def test_database_repository_can_add_movie(session_factory): repo = SqlAlchemyRepository(session_factory) new_movie = Movie('Guardians of Goatboy', 1914) new_movie.genres = [Genre('Action'), Genre('Sci-Fi')] new_movie.description = 'Adventures of Space soldiers sworn to protect a boy that is also a goat.' new_movie.director = Director("Ben Span") new_movie.actors = [Actor('Chris Pratt'), Actor("Bill Clinton")] new_movie.runtime_minutes = 400 the_repos_movie_list = repo.get_movies() count = 0 for movie in the_repos_movie_list: if movie == Movie('Guardians of Goatboy', 1914): count += 1 assert count == 0 repo.add_movie(new_movie) the_repos_movie_list = repo.get_movies() count = 0 for movie in the_repos_movie_list: if movie == Movie('Guardians of Goatboy', 1914): b_movie = movie count += 1 assert count == 1 assert b_movie.description == new_movie.description assert b_movie.director == new_movie.director assert b_movie.runtime_minutes == new_movie.runtime_minutes assert len(b_movie.genres) == len(new_movie.genres) for genre in new_movie.genres: assert genre in b_movie.genres assert len(b_movie.actors) == len(new_movie.actors) for actor in new_movie.actors: assert actor in b_movie.actors
def test_database_repository_can_get_movies(session_factory): repo = SqlAlchemyRepository(session_factory) a_movie_list = repo.get_movies() a_movie = Movie("Moana", 2016) spiderman_movie = Movie("The Amazing Spider-Man", 2012) arrival_movie = Movie( 'Arrival', 2016, ) assert len(a_movie_list) == 1000 assert a_movie in a_movie_list assert spiderman_movie in a_movie_list assert arrival_movie in a_movie_list
def add_to_watchlist(name, movie_title, release_year, repo: AbstractRepository): user = search_for_user(name, repo) a_movie = Movie(movie_title, release_year) for movie in user.watchlist: if movie == a_movie: return user.watchlist.add_movie(a_movie)
def test_create_review(): movie = Movie("Moana", 2016) review = Review(movie, "was pretty good", 9) the_time = datetime.today() assert str(review.movie) == f'<Movie Moana, 2016>' assert review.rating == 9 assert review.review_text == 'was pretty good' assert str(review) == '<Review <Movie Moana, 2016>, was pretty good, 9, {}>'.format(the_time)
def test_load_movie(empty_session): movie_title = 'Passengers' genre_list = ['Adventure', 'Drama', 'Romance'] director = 'Morten Tyldum' description = 'A spacecraft traveling to a distant colony planet and transporting thousands of people has a malfunction in its sleep chambers. As a result, two passengers are awakened 90 years early.' actors = [ 'Jennifer Lawrence', 'Chris Pratt', 'Michael Sheen', 'Laurence Fishburne' ] run_time = 116 release_year = 2016 insert_movie(empty_session, movie_title, director, genre_list, actors, description, release_year, run_time) a_movie = Movie(movie_title, release_year) a_movie.actors = [Actor(name) for name in actors] a_movie.description = description a_movie.director = Director(director) a_movie.genres = [Genre(name) for name in genre_list] a_movie.runtime_minutes = run_time b_movie = empty_session.query(Movie).filter( Movie._title == 'Passengers').one() assert b_movie == a_movie assert b_movie.director == a_movie.director assert b_movie.runtime_minutes == a_movie.runtime_minutes assert a_movie.description == b_movie.description assert len(a_movie.actors) == len(b_movie.actors) assert len(a_movie.genres) == len(b_movie.genres) for genre in a_movie.genres: assert genre in b_movie.genres for actor in a_movie.actors: assert actor in b_movie.actors
def test_compare_reviews(): movie = Movie("Moana", 2016) review = Review(movie, "was pretty good", 9) review2 = Review(movie, "was pretty good", 9) assert review.timestamp == review2.timestamp assert review.movie == review2.movie assert review.review_text == review2.review_text assert review.rating == review2.rating assert (review == review2) == True
def test_review_ratings(): movie = Movie("Moana", 2016) review = Review(movie, "was pretty good", -2) assert review.rating == None review = Review(movie, "was pretty good", 11) assert review.rating == None review = Review(movie, "was pretty good", 2) assert review.rating == 2 review = Review(movie, "was pretty good", 0) assert review.rating == None
def add_review(user_name: str, movie_title: str, movie_release_date: int, review_text: str, rating_num: int, repo: 'AbstractRepository'): a_movie = Movie(movie_title, movie_release_date) a_user = search_for_user(user_name, repo) if a_user: for movie in repo.get_movies(): if movie == a_movie: a_movie = movie break new_review = Review(a_movie, review_text, rating_num) new_review.user = a_user a_user.add_review(new_review) repo.add_review(new_review)
def test_database_repository_wont_add_movie_that_exists(session_factory): repo = SqlAlchemyRepository(session_factory) the_ropos_movie_list = repo.get_movies() genre_str_list = 'Action,Adventure,Biography' actor_str_list = 'Charlie Hunnam, Robert Pattinson, Sienna Miller, Tom Holland' description = 'A true-life drama, centering on British explorer Col. Percival Fawcett, who disappeared while searching for a mysterious city in the Amazon in the 1920s.' director_str = 'James Gray' a_new_movie = Movie('The Lost City of Z', 2016) a_new_movie.director = Director('James Gray') a_new_movie.runtime_minutes = 141 count = 0 for gen in the_ropos_movie_list: if gen == a_new_movie: count += 1 assert count == 1 with pytest.raises(IntegrityError): repo.add_movie(Movie('The Lost City of Z', 2016)) the_ropos_movie_list = repo.get_movies() for gen in the_ropos_movie_list: if gen == Movie('The Lost City of Z', 2016): b_movie = gen genre_list = [Genre(x.strip()) for x in genre_str_list.split(',')] actors_list = [Actor(x.strip()) for x in actor_str_list.split(',')] assert b_movie.description == description assert b_movie.director == Director(director_str) assert len(b_movie.genres) == len(genre_list) for genre in genre_list: assert genre in b_movie.genres assert len(b_movie.actors) == len(actors_list) for actor in actors_list: assert actor in b_movie.actors
def test_add_watched_movies(): user = User('mike', 'nope') movie = Movie("Moana", 2016) movie.runtime_minutes = 88 movie2 = Movie("Total Recall", 1989) movie2.runtime_minutes = 90 total_time = movie2.runtime_minutes + movie.runtime_minutes user.watch_movie(movie) user.watch_movie(movie2) assert user.time_spent_watching_movies_minutes == total_time assert user.watched_movies == [movie, movie2]
def get_movie_info(movie_name: str, date: int, repo: 'AbstractRepository') -> dict or None: a_movie = Movie(movie_name, date) selected_movie = None for movie in repo.get_movies(): if a_movie == movie: selected_movie = movie break if selected_movie is None: return None else: return {'title': selected_movie.title, 'release_year': selected_movie.release_year, 'description': selected_movie.description, 'director': selected_movie.director.director_full_name, 'actors': [i.actor_full_name for i in selected_movie.actors], 'genres': [i.genre_name for i in selected_movie.genres], 'runtime': selected_movie.runtime_minutes}
def test_database_repository_can_add_review(session_factory): repo = SqlAlchemyRepository(session_factory) a_movie = Movie('The Lost City of Z', 2016) a_review = Review(a_movie, 'was alright', 7) a_review.user = User( 'mistamime', 'pbkdf2:sha256:150000$i0E7SvrW$3fcec13019d221b565cb40ddd09ec38db8dc73aa5cbda722cc9a1508bc4075cb' ) repo.add_review(a_review) users_from_repo = repo.get_users() review_found = None for user in users_from_repo: for review in user.reviews: if review.movie == a_movie: review_found = review break assert review_found.review_text == 'was alright' assert review_found.rating == 7
def test_compare_lt_Movie(): movie = Movie("Moana", 2016) movie2 = Movie("Moana", 2016) movie3 = Movie("Lethal Weapon", 1985) movie4 = Movie("Lethal Bandanna", 1985) movie5 = Movie("Moanb", 2016) movie6 = Movie("Moanb", 2018) assert (movie < movie2) == False assert (movie < movie3) == False assert (movie3 < movie) == True assert (movie3 < movie4) == False assert (movie5 < movie2) == False assert (movie2 < movie5) == True assert (movie5 < movie6) == True
def test_iterator(): watchlist = WatchList() watchlist.add_movie(Movie("Moana", 2016)) watchlist.add_movie(Movie("Ice Age", 2002)) watchlist.add_movie(Movie("Guardians of the Galaxy", 2012)) a_list = [Movie("Moana", 2016), Movie("Ice Age", 2002), Movie("Guardians of the Galaxy", 2012)] n = 0 for i in watchlist: assert i == a_list[n] n += 1 iter_obj = iter(watchlist) n = 0 while n != len(a_list): assert iter_obj.__next__() == a_list[n] n += 1
def test_load_review(empty_session): movie_title = 'Passengers' genre_list = ['Adventure', 'Drama', 'Romance'] director = 'Morten Tyldum' description = 'A spacecraft traveling to a distant colony planet and transporting thousands of people has a malfunction in its sleep chambers. As a result, two passengers are awakened 90 years early.' actors = [ 'Jennifer Lawrence', 'Chris Pratt', 'Michael Sheen', 'Laurence Fishburne' ] run_time = 116 release_year = 2016 insert_movie(empty_session, movie_title, director, genre_list, actors, description, release_year, run_time) a_movie = Movie(movie_title, release_year) a_movie.actors = [Actor(name) for name in actors] a_movie.description = description a_movie.director = Director(director) a_movie.genres = [Genre(name) for name in genre_list] a_movie.runtime_minutes = run_time users = [["jill", '98765432'], ['jim', 'mjydfefs']] insert_users(empty_session, users) review_text = 'was definitely a 5' rating = 5 result = empty_session.execute( f"SELECT id from users WHERE username = '******'").fetchone() insert_review(empty_session, movie_title, release_year, result[0], review_text, rating) users = empty_session.query(User).all() found_review = None for user in users: if user.username == 'jim': for review in user.reviews: if review.movie == Movie(movie_title, release_year): found_review = review break assert found_review.review_text == 'was definitely a 5' assert found_review.rating == 5
def read_csv_file(self) -> None: with open(self.__filename, encoding='utf-8-sig') as file_data: reader = csv.DictReader(file_data) self.__dataset_of_movies = list() for row in reader: new_movie = Movie(row['Title'], int(row['Year'])) new_movie.description = row['Description'] new_movie.genres = [ Genre(i.strip()) for i in row['Genre'].split(',') ] new_movie.actors = [ Actor(i.strip()) for i in row['Actors'].split(',') ] new_movie.director = Director(row['Director'].strip()) if row['Runtime (Minutes)'].isdigit(): new_movie.runtime_minutes = int(row['Runtime (Minutes)']) self.__dataset_of_movies.append(new_movie) for i in new_movie.genres: self.add_genre(i) for i in new_movie.actors: self.add_actor(i) self.add_director(new_movie.director)
def test_check_first_movie(): watchlist = WatchList() assert watchlist.first_movie_in_watchlist() == None watchlist.add_movie(Movie("Moana", 2016)) watchlist.add_movie(Movie("Ice Age", 2002)) assert watchlist.first_movie_in_watchlist() == Movie("Moana", 2016)
def test_create_Movie(): movie = Movie("Moana", 2016) assert movie.title == 'Moana' assert movie.release_year == 2016 assert movie.__repr__() == f'<Movie Moana, 2016>'
def test_repository_can_get_movies(a_memory_repo): a_movie_list = a_memory_repo.get_movies() a_movie = Movie("Moana", 2016) assert a_movie in a_movie_list
def test_add_genre(): movie = Movie("Moana", 2016) cartoon = Genre('Cartoon') movie.genres = [cartoon] assert movie.genres == [Genre('Cartoon')]
def test_remove_actor(): movie = Movie("Moana", 2016) actors = [Actor("Auli'i Cravalho"), Actor("Dwayne Johnson"), Actor("Rachel House"), Actor("Temuera Morrison")] movie.actors = actors movie.remove_actor(Actor("Dwayne Johnson")) assert movie.actors == [Actor("Auli'i Cravalho"), Actor("Rachel House"), Actor("Temuera Morrison")]
def test_add_actor(): actor1 = Actor("Angelina Jolie") movie = Movie("Moana", 2016) movie.add_actor(actor1) assert movie.actors == [Actor("Angelina Jolie")]
def test_change_title(): movie = Movie("Moana", 2016) movie.title = 'The Blob' assert movie.title == 'The Blob' with pytest.raises(TypeError): movie.title = 1830
def test_add_director(): direc = Director("John Candy") movie = Movie("Moana", 2016) movie.director = direc assert movie.director.__repr__() == f'<Director John Candy>'