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_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_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