def test_init(): director1 = Director("Taika Waititi") assert repr(director1) == "<Director Taika Waititi>" director2 = Director("") assert director2.director_full_name is None director3 = Director(42) assert director3.director_full_name is None
def test_equality(): director1 = Director("Taika Waititi") director2 = Director("") director3 = Director("Taika Waititi") assert director1 != director2 assert director1 == director3
def test_sort(): director1 = Director("a") director2 = Director("aa") director3 = Director("b") assert director1 < director2 assert director1 < director3 assert director2 < director3
def test_hash(): director1 = Director("a") director2 = Director("a") director3 = Director("b") directors = set([director1, director2, director3]) assert len(directors) == 2 assert director1 in directors assert director2 in directors assert director3 in directors
def test_lt(self): director1 = Director("Taika Waititi") director4 = Director("Spielberg") director_list = [director1, director4] director_list.sort() assert director_list[0] == director4 and director_list[1] == director1 director5 = Director("Taika Zielberg") director_list2 = [director1, director5] director_list2.sort() assert director_list2[0] == director1 and director_list2[1] == director5 director6 = Director("Taika") director_list3 = [director1, director6] director_list3.sort() assert director_list3[0] == director6 and director_list3[1] == director1
def load_movies(data_path, repo): filename = os.path.join(data_path, "movies.csv") with open(filename, mode='r', encoding='utf-8-sig') as csvfile: movie_file_reader = csv.DictReader(csvfile) for row in movie_file_reader: media_id = row["Id"] title = row['Title'] release_year = int(row['Year']) description = row["Description"] runtime_minutes = row["Runtime (Minutes)"] director = Director(row["Director"]) genres = set([Genre(x) for x in row["Genre"].split(',')]) actors = set([Actor(x) for x in row["Actors"].split(',')]) movie = Movie(title, release_year) movie.description = description movie.runtime_minutes = runtime_minutes movie.director = director movie.media_id = media_id for genre in genres: movie.add_genre(genre) for actor in actors: movie.add_actor(actor) repo.add_media(movie)
def test_repository_does_not_retrieve_a_non_existent_director(): mem_repo = MemoryRepository() up_movie = Movie("Up", 2009, 1) inside_out_movie = Movie("Inside Out", 2015, 2) dolittle_movie = Movie("Dolittle", 2019, 3) up_movie.director = Director("Pete Docter") inside_out_movie.director = Director("Pete Docter") dolittle_movie.director = Director("Stephen Gaghan") mem_repo.add_movie(up_movie) mem_repo.add_movie(inside_out_movie) mem_repo.add_movie(dolittle_movie) movies_by_director = mem_repo.get_movies_by_director( Director("Sergio Pablos")) assert len(movies_by_director) == 0 assert movies_by_director == []
def test_repository_can_get_movies_by_director(): mem_repo = MemoryRepository() up_movie = Movie("Up", 2009, 1) inside_out_movie = Movie("Inside Out", 2015, 2) dolittle_movie = Movie("Dolittle", 2019, 3) up_movie.director = Director("Pete Docter") inside_out_movie.director = Director("Pete Docter") dolittle_movie.director = Director("Stephen Gaghan") mem_repo.add_movie(up_movie) mem_repo.add_movie(inside_out_movie) mem_repo.add_movie(dolittle_movie) movies_by_director = mem_repo.get_movies_by_director( Director("Pete Docter")) assert len(movies_by_director) == 2 assert movies_by_director == [inside_out_movie, up_movie]
def __init__(self, title, release_year): self.__title = title.strip() if title and type(title) is str else None self.__release_year = (release_year if release_year and type(release_year) is int and release_year >= 1900 else None) self.__id = None self.__description = "" self.__director = Director(None) self.__actors = set() self.__runtime_minutes = 0
def test_init(self): movie = Movie("Moana", 2016, 7) print(movie) director = Director("Ron Clements") movie.director = director print(movie.director) actors = [Actor("Auli'i Cravalho"), Actor("Dwayne Johnson"), Actor("Rachel House"), Actor("Temuera Morrison")] for actor in actors: movie.add_actor(actor) assert movie.actors == [Actor("Auli'i Cravalho"), Actor("Dwayne Johnson"), Actor("Rachel House"), Actor("Temuera Morrison")] assert len(movie.actors) == 4 movie.runtime_minutes = 107 print("Movie runtime: {} minutes".format(movie.runtime_minutes))
def read_csv_file(self): with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile: movie_file_reader = csv.DictReader(csvfile) index = 0 for row in movie_file_reader: title = row['Title'] release_year = int(row['Year']) actors = row['Actors'].split(",") genres = row['Genre'].split(",") director = Director(row['Director']) rating = row['Rating'] votes = row['Votes'] revenue = row['Revenue (Millions)'] metascore = row['Metascore'] movie = Movie(title, release_year, index + 1) movie.director = director # extension attribute application movie.external_rating = rating movie.rating_votes = votes movie.revenue = revenue movie.metascores = metascore # adding the actors, genres, director and the movie to the corresponding datasets for i in range(len(actors)): actor = Actor(actors[i]) movie.add_actor(actor) if actor not in self.__dataset_of_actors: # adding only unique actors to the dataset self.__dataset_of_actors.add(actor) for i in range(len(genres)): genre = Genre(genres[i]) movie.add_genre(genre) if genre not in self.__dataset_of_genres: # adding only unique genres to the dataset self.__dataset_of_genres.add(genre) if movie.director not in self.__dataset_of_directors: # adding only unique directors to the dataset self.__dataset_of_directors.add(movie.director) self.__dataset_of_movies.append(movie) index += 1
def test_hash(self): director1 = Director("Annabelle") hashed = hash(director1) assert director1.__hash__() == hashed
def test_eq(self): director1 = Director("Cheesus") director2 = Director("Jeebus") director3 = Director("Cheesus") assert director1 != director2 assert director1 == director3
def test_repo_get_media_by_fake_director(in_memory_repo): media = in_memory_repo.get_media_by_director(Director("fake")) assert media == []
def test_repo_get_media_by_different_director(in_memory_repo): media = in_memory_repo.get_media_by_director(Director("James Gunn")) assert media == [ Media("Guardians of the Galaxy", 2014), Media("Guardians of the Galaxy", 2011) ]
def test_repo_get_media_by_director(in_memory_repo): media = in_memory_repo.get_media_by_director(Director("Ridley Scott")) assert media == [Media("Prometheus", 2012)]