def user(): movie = Movie('Up', 2009) movie.add_actor(Actor("Will Smith")) movie.add_actor(Actor("Daniel Radcliff")) movie.add_genre(Genre("Comedy")) movie.add_genre(Genre("Drama")) director = Director("Peter Jackson") movie.director = director movie1 = Movie('Down', 2013) movie1.add_actor(Actor("Tom Cruise")) movie1.add_actor(Actor("Selena Gomez")) movie1.add_genre(Genre("Comedy")) movie1.add_genre(Genre("Romance")) director = Director("Peter Jackson") movie1.director = director movie2 = Movie('Boom', 1999) movie2.add_actor(Actor("Will Smith")) movie2.add_actor(Actor("Tom Cruise")) movie2.add_genre(Genre("Comedy")) movie2.add_genre(Genre("Action")) director = Director("Taika Waititi") movie2.director = director user = User("aram", "one1") user.watch_movie(movie) user.watch_movie(movie1) user.watch_movie(movie2) return user
def test_get_movies_for_director(in_memory_repo): movie = Movie("Lion", 2018) movie.director = Director("Taika Waititi") in_memory_repo.add_movie(movie) assert Movie( "Lion", 2018) in in_memory_repo.get_movies_for_director("Taika Waititi") assert len(in_memory_repo.get_movies_for_director("Taika Waititi")) == 1 assert in_memory_repo.get_movies_for_director("Katy Perry") == []
def load_movies(data_path: str, repo: MemoryRepository, data_file): print("DATA: ", data_file) for row in read_csv_file(os.path.join(data_path, data_file)): try: movie = Movie(row['Title'], int(row['Year'])) except ValueError: print("Invalid release year") else: director = Director(row['Director'].strip()) actors = row['Actors'].split(",") genres = row['Genre'].split(",") movie.director = director repo.add_director(director) movie.description = row['Description'].strip() for actor_name in actors: actor_name = actor_name.strip() actor = Actor(actor_name) if actor in repo.get_actors(): i = repo.get_actors().index(actor) actor = repo.get_actors()[i] else: repo.add_actor(actor) for actor1_name in actors: actor1_name = actor1_name.strip() if not actor.check_if_this_actor_worked_with( Actor(actor1_name)) and (actor_name != actor1_name): actor.add_actor_colleague(Actor(actor1_name)) movie.add_actor(actor) for genre_name in genres: genre = Genre(genre_name.strip()) movie.add_genre(genre) if genre not in repo.get_genres(): repo.add_genre(genre) try: movie.runtime_minutes = int(row['Runtime (Minutes)']) except ValueError: movie.runtime_minutes = None try: movie.votes = int(row['Votes']) except ValueError: movie.votes = None try: movie.rating = float(row['Rating']) except ValueError: movie.rating = None if movie not in repo.get_movies(): movie.image = get_image(movie) if movie.image == "": movie.image = "../static/none.jpg" repo.add_movie(movie)
def test_update(stats): movie2 = Movie('Brain', 2002) movie2.add_actor(Actor("Julia Roberts")) movie2.add_actor(Actor("Tom Cruise")) movie2.add_genre(Genre("Sci-Fi")) movie2.add_genre(Genre("Action")) director = Director("Christopher Nolan") movie2.director = director stats.user.watch_movie(movie2) stats.update_watched_lists() assert stats.user == User("aram", "one1", [], [], 0) assert stats.watched_movies == [ Movie("Up", 2009), Movie("Down", 2013), Movie("Boom", 1999), Movie("Brain", 2002) ] assert stats.watched_actors == { Actor("Will Smith"): 2, Actor("Daniel Radcliff"): 1, Actor("Selena Gomez"): 1, Actor("Tom Cruise"): 3, Actor("Julia Roberts"): 1 } assert stats.watched_directors == { Director("Peter Jackson"): 2, Director("Taika Waititi"): 1, Director("Christopher Nolan"): 1 } assert stats.watched_genres == { Genre("Comedy"): 3, Genre("Romance"): 1, Genre("Drama"): 1, Genre("Action"): 2, Genre("Sci-Fi"): 1 }