def repository(): repo = MemoryRepository() user1 = User("Myles Kennedy", "123") user2 = User("Mark Tremonti", "456") director1 = Director("Taika Waititi") director2 = Director("Steven Speilberg") actor1 = Actor("Chris Pratt") actor2 = Actor("Emma Watson") genre1 = Genre("Comedy") genre2 = Genre("Animation") movie1 = Movie("Moana", 2016) movie2 = Movie("Ice Age", 2002) movie1.director = director1 movie2.director = director2 movie1.add_actor(actor1) movie2.add_actor(actor2) movie1.add_genre(genre1) movie2.add_genre(genre2) review1 = Review(movie1, "very nice", 9) review2 = Review(movie2, "incredible", 10) user1.add_review(review1) user2.add_review(review2) repo.add_movie(movie1) repo.add_movie(movie2) repo.add_director(director1) repo.add_director(director2) repo.add_actor(actor1) repo.add_actor(actor2) repo.add_genre(genre1) repo.add_genre(genre2) repo.add_review(review1) repo.add_review(review2) repo.add_user(user1) repo.add_user(user2) return repo
def test_movie_replace_director_property(): movie1 = Movie("Princess and The Frog", 2009) director1 = Director("John Musker") director2 = Director("Ron Clements") movie1.director = director1 movie1.director = director2 assert movie1.director is director2
def test_director_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_tv_show_replace_director_property(): tv_show1 = TV_Show("Sailor Moon: Crystal", 2014) director1 = Director("John Musker") director2 = Director("Ron Clements") tv_show1.director = director1 tv_show1.director = director2 assert tv_show1.director is director2
def test_get_directors_by_name(session_factory): repository = SqlAlchemyRepository(session_factory) repository.add_director(Director("Mari Okada")) repository.add_director(Director("Mari Omada")) assert repository.get_directors_by_name("mari ok") == [ Director("Mari Okada") ] assert repository.get_directors_by_name("xyz") == [] assert repository.get_directors_by_name("mari o") == [ Director("Mari Okada"), Director("Mari Omada") ] assert repository.get_directors_by_name(1) == []
def test_get_directors_by_name(repository): repository.add_director(Director("Taika Waititi")) repository.add_director(Director("Steven Speilberg")) assert repository.get_directors_by_name("taik") == [ Director("Taika Waititi") ] assert repository.get_directors_by_name("xyz") == [] assert repository.get_directors_by_name("t") == [ Director("Taika Waititi"), Director("Steven Speilberg") ] assert repository.get_directors_by_name(1) == []
def read_csv_file(self): with open(self.__file_name, newline="", encoding="utf-8-sig") as csv_file: csv_reader = csv.DictReader(csv_file) for row in csv_reader: movie = Movie(row["Title"], int(row["Year"])) movie.description = row["Description"] movie.runtime_minutes = int(row["Runtime (Minutes)"]) if movie not in self.__dataset_of_movies: self.__dataset_of_movies.append(movie) actors = row["Actors"].split(",") for actor in actors: actor_true = Actor(actor.strip()) if actor_true not in self.__dataset_of_actors: self.__dataset_of_actors.append(actor_true) movie.add_actor(actor_true) director = Director(row["Director"]) movie.director = director if director not in self.__dataset_of_directors: self.__dataset_of_directors.append(director) genres = row["Genre"].split(",") for genre in genres: genre_true = Genre(genre.strip()) if genre_true not in self.__dataset_of_genres: self.__dataset_of_genres.append(genre_true) movie.add_genre(genre_true)
def test_get_movies_by_director(repository): movie1 = Movie("Moana", 2016) movie1.director = Director("Taika Waititi") movie2 = Movie("Ice Age", 2002) movie2.director = Director("Steven Speilberg") movie3 = Movie("A Silent Voice", 2016) movie3.director = Director("Steven Speilberg") repository.add_movie(movie1) repository.add_movie(movie2) repository.add_movie(movie3) assert repository.get_movies_by_director("Taika Waititi") == [movie1] assert repository.get_movies_by_director("xyz") == [] assert repository.get_movies_by_director("Steven Speilberg") == [ movie3, movie2 ] assert repository.get_movies_by_director(1) == []
def test_director_methods(): director1 = Director("Taika Waititi") assert repr(director1) == "<Director Taika Waititi>" director2 = Director("Cameron Lee") director3 = Director(42) assert director3.director_full_name is None director5 = Director("") assert director5.director_full_name is None director4 = Director("Taika Waititi") assert director4.__eq__(director1) == True assert director4.__lt__(director1) == False assert director4.__lt__(director2) == False assert director2.__lt__(director4) == True assert hash(director4) == hash(director1)
def load_movies_and_genres_and_directors_and_actors(data_path, repo): for row in read_csv_file(os.path.join(data_path, 'Data1000Movies.csv')): title = row[1] release_year = int(row[6]) runtime = int(row[7]) description = row[3] genre_list = row[2].split(',') for i in range(len(genre_list)): genre_list[i] = Genre(genre_list[i]) director = Director(row[4]) actor_list = row[5].split(',') for i in range(len(actor_list)): actor_list[i] = Actor(actor_list[i]) for actor_obj in actor_list: for colleague in actor_list: if colleague not in actor_obj.actor_colleagues: actor_obj.add_actor_colleague(colleague) rating = float(row[8]) votes = int(row[9]) if row[10] == "N/A": revenue = "N/A" else: revenue = float(row[10]) if row[11] == "N/A": metascore = "N/A" else: metascore = int(row[11]) id = int(row[0]) # create movie object and assign everything movie = Movie(title, release_year) movie.actors = actor_list movie.genres = genre_list movie.director = director movie.description = description movie.runtime_minutes = runtime movie.rating = rating movie.votes = votes movie.revenue = revenue movie.metascore = metascore movie.id = id repo.add_movie(movie) for genre in movie.genres: repo.add_genre(genre) for actor in movie.actors: repo.add_actor(actor) repo.add_director(movie.director)
def test_can_get_movie(in_memory_repo): movie_id = 1 movie_as_dict = movies_services.get_movie(movie_id, in_memory_repo) assert movie_id == movie_as_dict['id'] assert movie_as_dict['title'] == "Guardians of the Galaxy" assert movie_as_dict[ 'description'] == 'A group of intergalactic criminals are forced to work together to stop a fanatical ' \ 'warrior from taking control of the universe. ' assert movie_as_dict['director'] == Director("James Gunn") actors = movie_as_dict['actors'] assert Actor("Chris Pratt") in actors assert Actor("Vin Diesel") in actors genres = movie_as_dict['genres'] assert Genre('Action') in genres assert Genre('Adventure') in genres assert movie_as_dict['release_year'] == 2014 assert movie_as_dict["runtime_minutes"] == 121 assert movie_as_dict["rating"] == 8.1 assert movie_as_dict["votes"] == 757074 assert movie_as_dict["revenue"] == 333.13 assert movie_as_dict["metascore"] == 76
def test_repository_can_retrieve_movie(in_memory_repo): movie = in_memory_repo.get_movie_by_id(1) assert movie.title == "Guardians of the Galaxy" assert movie.genres == [ Genre("Action"), Genre("Adventure"), Genre("Sci-Fi") ] assert movie.description == "A group of intergalactic criminals are forced to work together to stop a fanatical " \ "warrior from taking control of the universe. " assert movie.director == Director("James Gunn") assert movie.actors == [ Actor("Chris Pratt"), Actor("Vin Diesel"), Actor("Bradley Cooper"), Actor("Zoe Saldana") ] assert movie.release_year == 2014 assert movie.runtime_minutes == 121 assert movie.rating == 8.1 assert movie.votes == 757074 assert movie.revenue == 333.13 assert movie.metascore == 76 assert movie.reviews == []
def test_director_false_lt_function(): director1 = Director("Taika Waititi") director2 = Director("Hayao Miyazaki") assert director1.__lt__(director2) is False
def test_add_and_get_director(repository): repository.add_director(Director("Taika Waititi")) assert repository.get_director("Taika Waititi") == Director( "Taika Waititi") assert repository.get_director("Steven Speilberg") is None
def test_tv_show_director_property(): tv_show1 = TV_Show("Sailor Moon: Crystal", 2014) director1 = Director("Munehisa Sakai") tv_show1.director = director1 assert tv_show1.director is director1
def test_director_lt_function(): director1 = Director("Taika Waititi") director2 = Director("Hayao Miyazaki") assert director2.__lt__(director1) is True
def test_director_false_eq_function(): director1 = Director("Taika Waititi") director2 = Director(" ") assert director1.__eq__(director2) is False
def test_add_and_get_director(session_factory): repository = SqlAlchemyRepository(session_factory) repository.add_director(Director("Mari Okada")) assert repository.get_director( "Mari Okada").director_full_name == "Mari Okada" assert repository.get_director("Mari Omada") is None
def test_movie_director_property(): movie1 = Movie("Princess and The Frog", 2009) director1 = Director("John Musker") movie1.director = director1 assert movie1.director is director1
def test_repository_can_add_a_director(in_memory_repo): director = Director("Toyota Curren") in_memory_repo.add_director(director) assert director in in_memory_repo.get_directors()
def load_movies_and_other_info(data_path: str, repo: MemoryRepository): actors = dict() directors = dict() genres = dict() for data_row in read_csv_file(os.path.join(data_path, 'Data1000Movies.csv')): movie_rank = int(data_row['Rank']) movie_genres = data_row['Genres'].split(", ") movie_actors = data_row['Actors'].split(", ") movie_directors = data_row['Director'].split(", ") # Add any new tags; associate the current article with tags. for actor in movie_actors: if actor not in actors.keys(): actors[actor] = list() actors[actor].append(movie_key) del data_row[-number_of_actors:] for genre in movie_genres: if genre not in genres.keys(): genres[genre] = list() genres[genre].append(movie_key) del data_row[-number_of_genres:] for director in movie_directors: if director not in directors.keys(): directors[director] = list() directors[director].append(movie_key) del data_row[-number_of_directors:] # Create Movie object. print(data_row) movie = Movie(title=data_row[2], date=date.fromisoformat(data_row[1]), id=movie_key) # Add the Article to the repository. repo.add_movie(movie) # Create Tag objects, associate them with Articles and add them to the repository. for actor_name in actors.keys(): actor = Actor(actor_name) for movie_id in actors[actor_name]: movie = repo.get_movie(movie_id) make_actor_association(movie, actor) repo.add_actor(actor) for director_name in directors.keys(): director = Director(director_name) for movie_id in Directors[Director_name]: movie = repo.get_movie(movie_id) make_director_association(movie, director) repo.add_director(director) for genre_name in genres.keys(): genre = Genre(genre_name) for movie_id in genres[genre_name]: movie = repo.get_movie(movie_id) make_genre_association(movie, genre) repo.add_genre(genre)