def read_csv_file(self): with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile: movie_file_reader = csv.DictReader(csvfile) for row in movie_file_reader: movie_class = Movie(row['Title'], int(row['Year'])) if movie_class not in self.dataset_of_movies: movie_class.id = int(row['Rank']) director = Director(row['Director']) movie_class.director = director movie_class.description = row['Description'] for actor in row['Actors'].split(","): actor_movie = Actor(actor) movie_class.add_actor(actor_movie) for genre in row['Genre'].split(","): genre_movie = Genre(genre) movie_class.add_genre(genre_movie) movie_class.runtime_minutes = int(row['Runtime (Minutes)']) self.dataset_of_movies.append(movie_class) for actor in row['Actors'].split(","): actor_class = Actor(actor) if actor_class not in self.dataset_of_actors: self.dataset_of_actors.add(actor_class) director_class = Director(row['Director']) if director_class not in self.dataset_of_directors: self.dataset_of_directors.add(director_class) for genre in row['Genre'].split(","): genre_class = Genre(genre) if genre_class not in self.dataset_of_genres: self.dataset_of_genres.add(genre_class)
def test_size(): watchlist = WatchList() assert watchlist.size() == 0 movie1 = Movie("Moana", 2016) movie2 = Movie("Booksmart", 2019) movie3 = Movie("School of Rock", 2003) movie4 = Movie("Roma", 2018) watchlist.add_movie(movie1) watchlist.add_movie(movie2) watchlist.add_movie(movie3) watchlist.add_movie(movie4) assert watchlist.size() == 4
def test_get_movies_for_browse(populated_repo): movie = Movie('Picnic', 2016) movie.id = 1001 populated_repo.add_movie(movie) movie2 = Movie('Panadol', 2011) movie2.id = 1002 populated_repo.add_movie(movie2) movie3 = Movie('Banana', 2009) movie3.id = 1003 populated_repo.add_movie(movie3) assert populated_repo.get_movies_for_browse([1001, 1002, 1003]) == [movie, movie2, movie3]
def test_adding_and_removing(): watchlist = WatchList() movie1 = Movie("Moana", 2016) movie2 = Movie("Booksmart", 2019) movie3 = Movie("School of Rock", 2003) movie4 = Movie("Roma", 2018) watchlist.add_movie(movie1) watchlist.add_movie(movie2) watchlist.add_movie(movie3) watchlist.add_movie(movie4) watchlist.add_movie(movie4) assert watchlist.size() == 4 watchlist.remove_movie(movie1) assert watchlist.size() == 3 watchlist.remove_movie(Movie("Juno", 2007)) assert watchlist.size() == 3
def test_comment_init(): movie = Movie("Her", 2013) comment = Comment(movie, "What year was this movie set in?") assert comment.movie == movie assert comment.comment == "What year was this movie set in?" assert comment.timestamp == datetime.now() assert comment.parent is None
def test_user_comments(): user = User("Hazel", "1234") movie = Movie("Her", 2013) comment = Comment(movie, "What are some similar movies to this?") user.add_comment(comment) assert comment in user.comments user.add_comment(comment) assert len(user.comments) == 1
def test_get_movies_by_x(populated_repo): movie = Movie('Picnic', 2016) movie.id = 1001 movie.add_genre(Genre('Blarg')) movie.add_actor(Actor('Glue Stick')) movie.director = Director('George Smith') populated_repo.add_movie(movie) lis = [movie] assert populated_repo.get_movies_by_title([1001]) == lis assert populated_repo.get_movies_by_actor([1001]) == lis assert populated_repo.get_movies_by_genre([1001]) == lis assert populated_repo.get_movies_by_director([1001]) == lis
def test_domain_init(): movie = Movie("Moana", 2018) movie.director = Director("Hans Zimmerman") movie.id = 4 movie.description = "hello world" assert movie.actors == [] actor1 = Actor("Jennifer Lawrence") actor2 = Actor("James McAvoy") movie.add_actor(actor1) movie.add_actor(actor2) assert movie.actors == [actor1, actor2] assert movie.genres == [] genre1 = Genre('Comedy') genre2 = Genre('Romance') movie.add_genre(genre1) movie.add_genre(genre2) assert movie.genres == [genre1, genre2]
def test_replies(): movie = Movie("Her", 2013) comment = Comment(movie, "What year was this movie set in?") reply = Comment(movie, "Wait nevermind I just Googled it") comment.add_reply(reply) assert reply in comment.replies assert reply.parent == comment reply2 = Comment(movie, "haha wow") reply.add_reply(reply2) assert reply2.parent is comment reply3 = Comment(movie, "oh my god") reply2.add_reply(reply3) assert reply3.parent is comment reply4 = Comment(Movie("Kill Bill: Volume 1", 2003), "I hope they make a sequel") comment.add_reply(reply4) assert reply4.parent is None comment.remove_reply(reply) assert reply not in comment.replies comment.remove_reply(reply4) assert reply4 not in comment.replies
def test_iterator(): movie1 = Movie("Moana", 2016) movie2 = Movie("Booksmart", 2019) movie3 = Movie("School of Rock", 2003) movie4 = Movie("Roma", 2018) watchlist = WatchList() watchlist.add_movie(movie1) watchlist.add_movie(movie2) watchlist.add_movie(movie3) watchlist.add_movie(movie4) it1 = iter(watchlist) assert next(it1) == Movie("Moana", 2016) assert next(it1) == Movie("Booksmart", 2019) assert next(it1) == Movie("School of Rock", 2003) assert next(it1) == Movie("Roma", 2018) with pytest.raises(StopIteration): next(it1)
def test_get_movie_ids_by_x(populated_repo): movie = Movie('Picnic', 2016) movie.id = 1001 movie.add_genre(Genre('Blarg')) movie.add_actor(Actor('Glue Stick')) movie.director = Director('George Smith') populated_repo.add_movie(movie) lis = [1001] assert search_serv.get_movies_ids_by_title('Picnic', populated_repo) == lis assert search_serv.get_movies_ids_by_actor('Glue Stick', populated_repo) == lis assert search_serv.get_movies_ids_by_genre('Blarg', populated_repo) == lis assert search_serv.get_movies_ids_by_director('George Smith', populated_repo) == lis assert search_serv.get_movies_ids_by_title('LOL', populated_repo) is None assert search_serv.get_movies_ids_by_actor('LOL', populated_repo) is None assert search_serv.get_movies_ids_by_genre('LOL', populated_repo) is None assert search_serv.get_movies_ids_by_director('LOL', populated_repo) is None
def test_select_and_first(): movie1 = Movie("Moana", 2016) movie2 = Movie("Booksmart", 2019) movie3 = Movie("School of Rock", 2003) movie4 = Movie("Roma", 2018) watchlist = WatchList() watchlist.add_movie(movie1) watchlist.add_movie(movie2) watchlist.add_movie(movie3) watchlist.add_movie(movie4) assert watchlist.select_movie_to_watch(0) == Movie("Moana", 2016) assert watchlist.select_movie_to_watch(5) is None assert watchlist.first_movie_in_watchlist() == Movie("Moana", 2016) watchlist2 = WatchList() assert watchlist2.first_movie_in_watchlist() is None
def test_get_movie(populated_repo): movie = Movie('Picnic', 2016) movie.id = 1001 populated_repo.add_movie(movie) assert populated_repo.get_movie(1001) is movie