def test_watching_sim_add_review(self): a = MovieWatchingSimulation() movie1 = Movie("Moana", 2016) movie2 = Movie("Ice Age", 2002) movie3 = Movie("Guardians of the Galaxy", 2012) user1 = User('Jack', 'pw12345') user2 = User('James', 'pw67890') user3 = User('Janice', 'pw87465') review1 = Review(movie1, "Was good", 6) review2 = Review(movie1, "Average", 5) review3 = Review(movie1, "Very Great", 8) review4 = Review(movie2, "Great", 7) review5 = Review(movie2, "Excellent", 9) review6 = Review(movie3, "Boring", 3) a.add_movie_review(review1.movie, user1, review1.rating) a.add_movie_review(review2.movie, user2, review2.rating) a.add_movie_review(review3.movie, user3, review3.rating) a.add_movie_review(review4.movie, user1, review4.rating) a.add_movie_review(review5.movie, user2, review5.rating) a.add_movie_review(review6.movie, user1, review6.rating) a.add_movie_review(review4.movie, user1, review4.rating) assert a.movie_dict == { movie1: [[user1, 6], [user2, 5], [user3, 8]], movie2: [[user1, 7], [user2, 9], [user1, 7]], movie3: [[user1, 3]] }
def test_add_user(movie, user1, user2): set1 = set() watch_together = MovieWatchingSimulation(movie) watch_together.add_user(user1) watch_together.add_user(user2) set1.add(user1) set1.add(user2) assert watch_together.user_set == set1
def test_add_review(self): movie = Movie('Moana', 2016) review_text = "This movie was very enjoyable." rating = 8 user2 = User('Ian', 'pw67890') user3 = User('Daniel', 'pw87465') user4 = User('Martin', 'pw12345') user_list = [user2, user3, user4] watch = MovieWatchingSimulation(user_list, movie) watch.add_review(review_text, rating) assert (watch.review != None) == True
def test_play_next_movie_at_end_playlist(): movie1 = Movie("a", 2020) movie2 = Movie("b", 2020) movie3 = Movie("c", 2020) user = User("ydia530", '123') watching_simulation = MovieWatchingSimulation(user) watching_simulation.add_movie_to_playlist(movie1) watching_simulation.add_movie_to_playlist(movie2) watching_simulation.add_movie_to_playlist(movie3) watching_simulation.play_next_movie() watching_simulation.play_next_movie() assert watching_simulation.now_playing == movie3 assert watching_simulation.next_playing is None watching_simulation.play_next_movie() assert watching_simulation.now_playing is None assert watching_simulation.next_playing is None
def test_init_watching_simulation(): user = User("ydia530", '123') watching_simulation = MovieWatchingSimulation(user) assert watching_simulation.watch_list.size() == 0 assert watching_simulation.next_playing is None assert watching_simulation.now_playing is None assert watching_simulation.user == user
def test_remove_from_watchlist(self): # initialise the different movies movies = [ Movie("Moana", 2016), Movie("Guardians of the Galaxy", 2014), Movie("Ice Age", 2002), Movie("Transformers", 2007) ] movies[0].runtime_minutes = 107 movies[1].runtime_minutes = 121 movies[2].runtime_minutes = 103 movies[3].runtime_minutes = 144 movie = Movie("Us", 2019) movie.runtime_minutes = 121 random_movie1 = Movie("Black Panther", 2018) random_movie1.runtime_minutes = 135 random_movie2 = Movie("Night School", 2018) random_movie2.runtime_minutes = 112 # user 1 user1 = User("Martin", "pw12345") for mov in movies: user1.watch_movie(mov) user1.watchlist.add_movie(movie) user1.watchlist.add_movie(random_movie1) # user 2 user2 = User("Alfie", "pw23456") user2.watch_movie(movies[0]) user2.watchlist.add_movie(random_movie1) user2.watchlist.add_movie(random_movie2) # user 3 will be added in after the movie is watchingsimulation user3 = User("Yara", "pw34567") user3.watch_movie(movies[0]) user3.watch_movie(movies[2]) user3.watch_movie(movies[3]) user3.watchlist.add_movie(movie) # user 4 user4 = User("Danny", "pw45678") user4.watch_movie(movies[0]) user4.watch_movie(movies[2]) user4.watch_movie(movie) user4.watchlist.add_movie(random_movie2) user_list = [user1, user2, user4] simulation = MovieWatchingSimulation(movie, user_list) assert repr(simulation.movie) == "<Movie Us, 2019>" assert repr(simulation.user_list ) == "[<User martin>, <User alfie>, <User danny>]" assert user1.watchlist.size == 1 assert user2.watchlist.size == 2 assert user3.watchlist.size == 1 assert user4.watchlist.size == 1
def test_init(self): movie = Movie("Moana", 2016) user2 = User('Ian', 'pw67890') user3 = User('Daniel', 'pw87465') user4 = User('Martin', 'pw12345') user_list = [user2, user3, user4] watch = MovieWatchingSimulation(user_list, movie) assert repr( watch ) == "Movie watching : <Movie Moana, 2016>\nUser(s) watching : [<User ian>, <User daniel>, <User martin>]\nReview : None"
def test_play_previous_at_start(): movie1 = Movie("a", 2020) movie2 = Movie("b", 2020) movie3 = Movie("c", 2020) user = User("ydia530", '123') watching_simulation = MovieWatchingSimulation(user) watching_simulation.add_movie_to_playlist(movie1) watching_simulation.add_movie_to_playlist(movie2) watching_simulation.add_movie_to_playlist(movie3) watching_simulation.play_previous_movie() assert watching_simulation.now_playing == movie1 assert watching_simulation.next_playing == movie2
def test_remove_movie(): movie1 = Movie("a", 2020) movie2 = Movie("b", 2020) movie3 = Movie("c", 2020) user = User("ydia530", '123') watching_simulation = MovieWatchingSimulation(user) watching_simulation.add_movie_to_playlist(movie1) watching_simulation.add_movie_to_playlist(movie2) watching_simulation.add_movie_to_playlist(movie3) assert watching_simulation.watch_list.size() == 3 watching_simulation.remove_movie_from_play_list(movie3) assert watching_simulation.watch_list.size() == 2 assert watching_simulation.now_playing == movie1 assert watching_simulation.next_playing == movie2
def test_write_review_with_no_movie(simulation): sim2 = MovieWatchingSimulation(42) assert sim2.movie is None user1 = User("Myles Kennedy", "abcde") sim2.add_user(user1) sim2.write_review(user1, "Great movie", 7) assert len(user1.reviews) == 0
def test_write_review(movie, user1, user2): review_text = "This movie was very enjoyable." rating = 8 review = Review(movie, review_text, rating) review_text3 = "This movie was very enjoyable." rating3 = 8 review3 = Review(movie, review_text3, rating3) watch_together = MovieWatchingSimulation(movie) watch_together.add_user(user1) watch_together.add_user(user2) watch_together.write_review(user1, review_text, rating) watch_together.write_review(user2, review_text3, rating3) assert (watch_together.review_dict[user1] == review) == True assert (watch_together.review_dict[user2] == review3) == True
def main(): filename = 'datafiles/Data1000Movies.csv' movie_file_reader = MovieFileCSVReader(filename) movie_file_reader.read_csv_file() the_sim = MovieWatchingSimulation(movie_file_reader) ##the_sim.go() the_sim.add_user(User("Paul", "wellington")) if the_sim.user_login("paul", "wellington"): print("User Paul logged in") print('look at genre, Adventure.') viewed_list = the_sim.look_at_genre("paul", 'Adventure') print("pick some movies") user_picks = create_movie_list(len(viewed_list), 15) print(user_picks) print(viewed_list[user_picks[1]]) for i in user_picks: the_sim.add_to_watchlist("paul", viewed_list[i]) print("paul views his watchlist") new_watchlist = the_sim.get_watchlist("paul") assert new_watchlist[1]== viewed_list[user_picks[1]] if the_sim.user_logout("Paul"): print("Paul logged out")
def the_sim(): filename = 'datafiles/Data1000Movies.csv' movie_file_reader = MovieFileCSVReader(filename) movie_file_reader.read_csv_file() sim = MovieWatchingSimulation(movie_file_reader) sim.add_user(User("Paul", "wellington")) sim.add_user(User('jessica', 'piano')) return sim
def test_start_watching_with_no_movie(simulation): sim2 = MovieWatchingSimulation(42) assert sim2.movie is None user1 = User("Myles Kennedy", "abcde") user2 = User("Mark Tremonti", "fghij") sim2.add_user(user1) sim2.add_user(user2) assert len(user1.watched_movies) == 0 assert user1.time_spent_watching_movies_minutes == 0 assert len(user2.watched_movies) == 0 assert user2.time_spent_watching_movies_minutes == 0 sim2.start_watching() assert len(user1.watched_movies) == 0 assert user1.time_spent_watching_movies_minutes == 0 assert len(user2.watched_movies) == 0 assert user2.time_spent_watching_movies_minutes == 0
def test_constructor(simulation): assert simulation.movie == Movie("Moana", 2016) sim2 = MovieWatchingSimulation(42) assert sim2.movie is None
def test_watching_sim_review_average(self): a = MovieWatchingSimulation() movie1 = Movie("Moana", 2016) movie2 = Movie("Ice Age", 2002) movie3 = Movie("Guardians of the Galaxy", 2012) user1 = User('Jack', 'pw12345') user2 = User('James', 'pw67890') user3 = User('Janice', 'pw87465') review1 = Review(movie1, "Was good", 6) review2 = Review(movie1, "Average", 5) review3 = Review(movie1, "Very Great", 8) review4 = Review(movie2, "Great", 7) review5 = Review(movie2, "Excellent", 9) review6 = Review(movie3, "Boring", 3) a.add_movie_review(review1.movie, user1, review1.rating) a.add_movie_review(review2.movie, user2, review2.rating) a.add_movie_review(review3.movie, user3, review3.rating) a.add_movie_review(review4.movie, user1, review4.rating) a.add_movie_review(review5.movie, user2, review5.rating) a.add_movie_review(review6.movie, user1, review6.rating) a.add_movie_review(review4.movie, user1, review4.rating) assert a.get_movie_rating_average(movie1) == "Average Rating: 6.33" assert a.get_movie_rating_average(Movie("Ice Age", 2003)) == "Unrated: No Reviews"
def test_add_review(self): # initialise the different movies movies = [ Movie("Moana", 2016), Movie("Guardians of the Galaxy", 2014), Movie("Ice Age", 2002), Movie("Transformers", 2007) ] movies[0].runtime_minutes = 107 movies[1].runtime_minutes = 121 movies[2].runtime_minutes = 103 movies[3].runtime_minutes = 144 movie = Movie("Us", 2019) movie.runtime_minutes = 121 random_movie1 = Movie("Black Panther", 2018) random_movie1.runtime_minutes = 135 random_movie2 = Movie("Night School", 2018) random_movie2.runtime_minutes = 112 # user 1 user1 = User("Martin", "pw12345") for mov in movies: user1.watch_movie(mov) user1.watchlist.add_movie(movie) user1.watchlist.add_movie(random_movie1) # user 2 user2 = User("Alfie", "pw23456") user2.watch_movie(movies[0]) user2.watchlist.add_movie(random_movie1) user2.watchlist.add_movie(random_movie2) # user 3 will be added in after the movie is watchingsimulation user3 = User("Yara", "pw34567") user3.watch_movie(movies[0]) user3.watch_movie(movies[2]) user3.watch_movie(movies[3]) user3.watchlist.add_movie(movie) # user 4 user4 = User("Danny", "pw45678") user4.watch_movie(movies[0]) user4.watch_movie(movies[2]) user4.watch_movie(movie) user4.watchlist.add_movie(random_movie2) user_list = [user1, user2, user4] simulation = MovieWatchingSimulation(movie, user_list) user1.add_review(Review(movies[0], "Daughter loved it", 8)) user1.add_review(Review(movies[1], "Good laugh", 9)) user1.add_review(Review(movies[2], "Good for the kids", 9)) user1.add_review(Review(movies[3], "Great action sequences", 7)) user2.add_review(Review(movies[0], "It was awesome!!", 10)) user3.add_review( Review(movies[0], "Little siblings absolutely enjoyed it.", 9)) user3.add_review( Review(movies[2], "Brings back all the good memories", 10)) user3.add_review(Review(movies[3], "I'm a fan of giant robots now", 9)) user4.add_review(Review(movies[0], "Watched it too many times now", 6)) user4.add_review(Review(movies[2], "Take me back", 7)) user4.add_review(Review(movie, "Greatly thrilling", 9)) assert len(user1.reviews) == 4 assert len(user2.reviews) == 1 assert len(user3.reviews) == 3 assert len(user4.reviews) == 3 simulation.add_user(user3) simulation.add_review(user1, "Very entertaining and suspenseful", 9) simulation.add_review(user2, "Definitely not for kids my age", 4) simulation.add_review(user3, "Oh that was scary", 9) simulation.add_review(user4, "Full of wonderful twists and turns", 10) assert len(user1.reviews) == 5 assert len(user2.reviews) == 2 assert len(user3.reviews) == 4 assert len(user4.reviews) == 4
def test_add_watch_statistics(self): # initialise the different movies movies = [ Movie("Moana", 2016), Movie("Guardians of the Galaxy", 2014), Movie("Ice Age", 2002), Movie("Transformers", 2007) ] movies[0].runtime_minutes = 107 movies[1].runtime_minutes = 121 movies[2].runtime_minutes = 103 movies[3].runtime_minutes = 144 movie = Movie("Us", 2019) movie.runtime_minutes = 121 random_movie1 = Movie("Black Panther", 2018) random_movie1.runtime_minutes = 135 random_movie2 = Movie("Night School", 2018) random_movie2.runtime_minutes = 112 # user 1 user1 = User("Martin", "pw12345") for mov in movies: user1.watch_movie(mov) user1.watchlist.add_movie(movie) user1.watchlist.add_movie(random_movie1) # user 2 user2 = User("Alfie", "pw23456") user2.watch_movie(movies[0]) user2.watchlist.add_movie(random_movie1) user2.watchlist.add_movie(random_movie2) # user 3 will be added in after the movie is watchingsimulation user3 = User("Yara", "pw34567") user3.watch_movie(movies[0]) user3.watch_movie(movies[2]) user3.watch_movie(movies[3]) user3.watchlist.add_movie(movie) # user 4 user4 = User("Danny", "pw45678") user4.watch_movie(movies[0]) user4.watch_movie(movies[2]) user4.watch_movie(movie) user4.watchlist.add_movie(random_movie2) user_list = [user1, user2, user4] simulation = MovieWatchingSimulation(movie, user_list) assert user1.time_spent_watching_movies_minutes == 596 assert repr( user1.watched_movies ) == "[<Movie Moana, 2016>, <Movie Guardians of the Galaxy, 2014>, <Movie Ice Age, 2002>, <Movie Transformers, 2007>, <Movie Us, 2019>]" assert user2.time_spent_watching_movies_minutes == 228 assert repr( user2.watched_movies) == "[<Movie Moana, 2016>, <Movie Us, 2019>]" assert user3.time_spent_watching_movies_minutes == 354 assert repr( user3.watched_movies ) == "[<Movie Moana, 2016>, <Movie Ice Age, 2002>, <Movie Transformers, 2007>]" assert user4.time_spent_watching_movies_minutes == 452 assert repr( user4.watched_movies ) == "[<Movie Moana, 2016>, <Movie Ice Age, 2002>, <Movie Us, 2019>, <Movie Us, 2019>]"
def test_review_simulation(): movie1 = Movie("a", 2020) movie2 = Movie("b", 2020) movie3 = Movie("c", 2020) user = User("ydia530", '123') watching_simulation = MovieWatchingSimulation(user) watching_simulation.add_movie_to_playlist(movie1) watching_simulation.add_movie_to_playlist(movie2) watching_simulation.add_movie_to_playlist(movie3) watching_simulation.review_to_current_playing_movie() assert len(watching_simulation.review) == 1 watching_simulation.play_next_movie() watching_simulation.review_to_current_playing_movie() assert len(watching_simulation.review) == 2 print(watching_simulation.review)
def test_search_movie_to_watch(): movie1 = Movie("a", 2020) movie2 = Movie("b", 2020) movie3 = Movie("c", 2020) user = User("ydia530", '123') watching_simulation = MovieWatchingSimulation(user) watching_simulation.add_movie_to_playlist(movie1) watching_simulation.add_movie_to_playlist(movie2) watching_simulation.add_movie_to_playlist(movie3) watching_simulation.search_movie_from_playlist_to_watch(movie2) # test fot searching movie inside watchlist assert watching_simulation.now_playing == movie2 assert watching_simulation.next_playing == movie3 watching_simulation.search_movie_from_playlist_to_watch(movie3) # test for searching movie at end watchlist assert watching_simulation.now_playing == movie3 assert watching_simulation.next_playing is None watching_simulation.search_movie_from_playlist_to_watch(Movie("d",2020)) #test for searching movie not in watchlist assert watching_simulation.now_playing == movie3 assert watching_simulation.next_playing is None
def simulation(): return MovieWatchingSimulation(Movie("Moana", 2016))