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_tv_show_actor_property(): tv_show1 = TV_Show("Sailor Moon: Crystal", 2014) actor1 = Actor("Anika Noni Rose") actor2 = Actor("Keith David") tv_show1.actors = actor1 tv_show1.actors = actor2 assert tv_show1.actors == [actor1, actor2]
def test_movie_actor_property(): movie1 = Movie("Princess and The Frog", 2009) actor1 = Actor("Anika Noni Rose") actor2 = Actor("Keith David") movie1.actors = actor1 movie1.actors = actor2 assert movie1.actors == [actor1, actor2]
def test_actor_init(): actor1 = Actor("Steve Carell") assert repr(actor1) == "<Actor Steve Carell>" actor2 = Actor("") assert actor2.actor_full_name is None actor3 = Actor(42) assert actor3.actor_full_name is None
def test_movie_remove_actor(): movie1 = Movie("Princess and The Frog", 2009) actor1 = Actor("Anika Noni Rose") actor2 = Actor("Keith David") movie1.add_actor(actor1) movie1.add_actor(actor2) movie1.remove_actor(actor1) assert movie1.return_actor() == [actor2]
def test_tv_show_remove_actor(): tv_show1 = TV_Show("Sailor Moon: Crystal", 2014) actor1 = Actor("Kotono Mitsuishi") actor2 = Actor("Amanda Celine Miller") tv_show1.add_actor(actor1) tv_show1.add_actor(actor2) tv_show1.remove_actor(actor1) assert tv_show1.return_actor() == [actor2]
def test_get_actors_by_name(repository): repository.add_actor(Actor("Chris Pratt")) repository.add_actor(Actor("Emma Watson")) assert repository.get_actors_by_name("chri") == [Actor("Chris Pratt")] assert repository.get_actors_by_name("xyz") == [] assert repository.get_actors_by_name("t") == [ Actor("Chris Pratt"), Actor("Emma Watson") ] assert repository.get_actors_by_name(1) == []
def test_get_actors_by_name(session_factory): repository = SqlAlchemyRepository(session_factory) repository.add_actor(Actor("Ikue Ootani")) repository.add_actor(Actor("Ikue Arai")) assert repository.get_actors_by_name("ikue ootani") == [ Actor("Ikue Ootani") ] assert repository.get_actors_by_name("xyz") == [] assert repository.get_actors_by_name("ikue ") == [ Actor("Ikue Arai"), Actor("Ikue Ootani") ] assert repository.get_actors_by_name(1) == []
def test_get_movies_by_actor(repository): movie1 = Movie("Moana", 2016) movie1.add_actor(Actor("Chris Pratt")) movie1.add_actor(Actor("Emma Watson")) movie2 = Movie("Ice Age", 2002) movie2.add_actor(Actor("Emma Watson")) repository.add_movie(movie1) repository.add_movie(movie2) assert repository.get_movies_by_actor("Chris Pratt") == [movie1] assert repository.get_movies_by_actor("xyz") == [] assert repository.get_movies_by_actor("Emma Watson") == [movie2, movie1] assert repository.get_movies_by_actor(1) == []
def test_actor_methods(): actor1 = Actor("Angelina Jolie") assert actor1.__repr__() == "<Actor Angelina Jolie>" actor2 = Actor("") assert actor2.actor_full_name == None actor3 = Actor(324) assert actor3.actor_full_name == None actor4 = Actor("Dylan Yates") assert actor4.__eq__(actor1) == False assert actor4.__eq__(actor4) == True assert actor1.__lt__(actor4) == True assert actor1.__lt__(actor1) == False assert actor4.__lt__(actor1) == False assert hash(actor4) == hash(actor4) assert hash(actor1) != hash(actor4)
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 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 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)
def test_add_and_get_actor(session_factory): repository = SqlAlchemyRepository(session_factory) repository.add_actor(Actor("Ikue Ootani")) assert repository.get_actor("Ikue Ootani") == Actor("Ikue Ootani") assert repository.get_actor("Satomi Arai") is None
def test_tv_show_add_actor(): tv_show1 = TV_Show("Sailor Moon: Crystal", 2014) actor1 = Actor("Kotono Mitsuishi") tv_show1.add_actor(actor1) assert tv_show1.return_actor() == [actor1]
def test_repository_can_add_an_actor(in_memory_repo): actor = Actor("Dylan Yates") in_memory_repo.add_actor(actor) assert actor in in_memory_repo.get_actors()
def test_movie_add_actor(): movie1 = Movie("Princess and The Frog", 2009) actor1 = Actor("Anika Noni Rose") movie1.add_actor(actor1) assert movie1.return_actor() == [actor1]
def test_false_2_check_if_this_actor_worked_with(): actor1 = Actor("Steve Carell") actor2 = Actor("Amy Adams") actor3 = Actor("Jack Black") actor1.add_actor_colleague(actor2) assert actor1.check_if_this_actor_worked_with(actor3) is False
def test_false_check_if_this_actor_worked_with(): actor1 = Actor("Steve Carell") actor2 = Actor("Amy Adams") assert actor1.check_if_this_actor_worked_with(actor2) is False
def test_check_if_this_actor_worked_with(): actor1 = Actor("Steve Carell") actor2 = Actor("Amy Adams") actor1.add_actor_colleague(actor2) assert actor1.check_if_this_actor_worked_with(actor2) is True
def test_add_actor_colleague(): actor1 = Actor("Steve Carell") actor2 = Actor("Amy Adams") actor1.add_actor_colleague(actor2) assert actor1.return_actor_colleague() == [actor2]
def test_actor_false_lt_function(): actor1 = Actor("Steve Carell") actor2 = Actor("Amy Adams") assert actor1.__lt__(actor2) is False
def test_add_and_get_actor(repository): repository.add_actor(Actor("Chris Pratt")) assert repository.get_actor("Chris Pratt") == Actor("Chris Pratt") assert repository.get_actor("Emma Watson") is None
def test_actor_eq_function(): actor1 = Actor("Steve Carell") actor2 = Actor("Steve Carell") assert actor1.__eq__(actor2) is True
def test_actor_lt_function(): actor1 = Actor("Steve Carell") actor2 = Actor("Amy Adams") assert actor2.__lt__(actor1) is True