def test_revenue_in_millions(): movie = Movie("Sharknado", 2020) movie.revenue_in_millions = 10 assert movie.revenue_in_millions == 10 movie.revenue_in_millions = -1 assert movie.revenue_in_millions == -1 movie.revenue_in_millions = "N/A" assert movie.revenue_in_millions == None
def test_eq(): movie1 = Movie("Sharknado", 2020) movie2 = Movie("Sharknado", 2020) assert movie1 == movie2 movie3 = Movie("Sharknado", 2019) assert movie1 != movie3 movie4 = Movie("Sharknadooo", 2020) assert movie1 != movie4
def test_hash(): movie1_hash = Movie("Sharknado", 2020).__hash__() movie2_hash = Movie("Sharknado", 2020).__hash__() movie3_hash = Movie(2, "2020").__hash__() movie4_hash = Movie(4, "1").__hash__() assert movie1_hash == movie2_hash assert movie3_hash == movie4_hash assert movie1_hash != movie3_hash assert movie1_hash != movie4_hash
def test_votes(): movie = Movie("Sharknado", 2020) movie.votes = 10 assert movie.votes == 10 with pytest.raises(ValueError): movie.votes = -1 movie.votes = "10" assert movie.votes == None
def test_lt(): movie1 = Movie("Sharknado", 2020) movie2 = Movie("Sharknado", 2019) assert movie2 < movie1 movie3 = Movie("Aaaaaaaaa", 2019) assert movie3 < movie2 movie4 = Movie("aaaaaaaaa", 2019) assert movie2 < movie4
def test_remove_actor(): movie1 = Movie("Sharknado", 2020) actors = [ Actor("Auli'i Cravalho"), Actor("Dwayne Johnson"), Actor("Rachel House"), Actor("Temuera Morrison") ] movie1.actors = actors movie1.remove_actor(Actor("Dwayne Johnson")) assert movie1.actors == [ Actor("Auli'i Cravalho"), Actor("Rachel House"), Actor("Temuera Morrison") ] movie1.remove_actor("Rachel House") assert movie1.actors == [ Actor("Auli'i Cravalho"), Actor("Rachel House"), Actor("Temuera Morrison") ] movie1.remove_actor(Actor("Jeff")) assert movie1.actors == [ Actor("Auli'i Cravalho"), Actor("Rachel House"), Actor("Temuera Morrison") ]
def test_size(watchlist): # Check empty watchlist assert watchlist.size() == 0 # Add three movies to the watchlist watchlist.watchlist = [ Movie("Moana", 2016), Movie("Ice Age", 2002), Movie("Guardians of the Galaxy", 2012) ] assert watchlist.size() == 3
def test_init(): movie1 = Movie("Sharknado", 2020) assert repr(movie1) == "<Movie Sharknado, 2020>" movie2 = Movie(2, 2020) assert repr(movie2) == "<Movie None, 2020>" movie3 = Movie("Sharknado", 1899) assert repr(movie3) == "<Movie Sharknado, None>" movie4 = Movie("Sharknado", "2020") assert repr(movie4) == "<Movie Sharknado, None>"
def test_description(): movie = Movie("Sharknado", 2020) movie.description = " This was great!" assert movie.description == "This was great!" movie = Movie("Sharknado", 2020) movie.description = " This was great! " assert movie.description == "This was great!" movie = Movie("Sharknado", 2020) movie.description = 42 assert movie.description == None
def test_runtime(): movie = Movie("Sharknado", 2020) movie.runtime_minutes = 20 assert movie.runtime_minutes == 20 movie = Movie("Sharknado", 2020) with pytest.raises(ValueError): movie.runtime_minutes = 0 movie = Movie("Sharknado", 2020) movie.runtime_minutes = "20" assert movie.runtime_minutes == None
def test_timestamp(): user = User('Test', 'Test') movie = Movie("Moana", 2016) review_text = "This movie was very enjoyable." rating = 8 review = Review(user, movie, review_text, rating) assert type(review.timestamp) == datetime.datetime
def test_user(): user = User('Test', 'Test') movie = Movie("Moana", 2016) review_text = "This movie was very enjoyable." rating = 8 review = Review(user, movie, review_text, rating) assert review.user == user
def test_add_movie(watchlist): # Test adding a movie object movie = Movie("Test", 2020) watchlist.add_movie(movie) assert watchlist.watchlist == [movie] # Test for adding same movie again watchlist.add_movie(movie) assert watchlist.watchlist == [movie] # Test adding a non-movie object watchlist.add_movie("Test") assert watchlist.watchlist == [movie] # Test adding another movie object movie2 = Movie("Test2", 2020) watchlist.add_movie(movie2) assert watchlist.watchlist == [movie, movie2]
def test_make_review(): user = User('Test', 'Test') movie = Movie("Moana", 2016) review_text = "This movie was very enjoyable." rating = 8 review = make_review(user, movie, review_text,rating) assert user.reviews == [review] assert review.user == user assert movie.reviews == [review]
def test_init(): # Create instance movie = Movie("Test", 2020) movie.runtime_minutes = 120 user = User("Host", "password123") watch_simulation = MovieWatchingSimulation(movie, user) # Uses the properties to check valid init assert watch_simulation.movie == movie assert watch_simulation.reviews == [] assert watch_simulation.users_watching == {user} # Check movie was added to users watch list assert movie in user.watched_movies # create bad instances movie2 = "Test" user2 = "Host" with pytest.raises(TypeError): watch_simulation2 = MovieWatchingSimulation(movie2, user) watch_simulation3 = MovieWatchingSimulation(movie, user2)
def test_runtime_string(): movie = Movie("Sharknado", 2020) assert movie.get_runtime_string() == '' movie.runtime_minutes = 61 assert movie.get_runtime_string() == '1h 1m' movie.runtime_minutes = 59 assert movie.get_runtime_string() == '59m'
def test_populate_repo(empty_memory_repo, test_movie_file, test_user_file, test_review_file): populate_repo(empty_memory_repo, test_movie_file, test_user_file, test_review_file) # Check that movies we expect have been added to the private __movies list variable assert Movie("Guardians of the Galaxy", 2014) in empty_memory_repo._MemoryRepository__movies assert Movie("17 Again", 2009) in empty_memory_repo._MemoryRepository__movies assert Movie("Nine Lives", 2016) in empty_memory_repo._MemoryRepository__movies # Check that the movies have the expected attributes assert empty_memory_repo._MemoryRepository__movies[1].description == "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe." assert empty_memory_repo._MemoryRepository__movies[1].director == Director("James Gunn") assert sorted(empty_memory_repo._MemoryRepository__movies[1].actors) == sorted([Actor("Chris Pratt"), Actor("Vin Diesel"), Actor("Bradley Cooper"), Actor("Zoe Saldana")]) assert sorted(empty_memory_repo._MemoryRepository__movies[1].genres) == sorted([Genre("Action"), Genre("Adventure"), Genre("Sci-Fi")]) assert empty_memory_repo._MemoryRepository__movies[1].runtime_minutes == 121 assert empty_memory_repo._MemoryRepository__movies[1].rating == 8.1 assert empty_memory_repo._MemoryRepository__movies[1].revenue_in_millions == 333.13 assert empty_memory_repo._MemoryRepository__movies[1].metascore == 76 assert empty_memory_repo._MemoryRepository__movies[1].image_link == 'https://m.media-amazon.com/images/M/MV5BMTAwMjU5OTgxNjZeQTJeQWpwZ15BbWU4MDUxNDYxODEx._V1_SX300.jpg' assert len(empty_memory_repo._MemoryRepository__users) == 2 assert len(empty_memory_repo._MemoryRepository__reviews) == 2 assert len(empty_memory_repo._MemoryRepository__movies[0].reviews) == 2
def test_remove_review(): movie = Movie("Sharknado", 2020) review = Review(User('Test', 'Test'), movie, "Wow!", 10) movie.add_review(review) assert movie.reviews == [review] movie.remove_review(review) assert movie.reviews == []
def test_rating(): movie = Movie("Sharknado", 2020) movie.rating = 10 assert movie.rating == 10 with pytest.raises(ValueError): movie.rating = 11 movie.rating = -1 movie.rating = "10" assert movie.rating == None
def test_metascore(): movie = Movie("Sharknado", 2020) movie.metascore = 10 assert movie.metascore == 10 with pytest.raises(ValueError): movie.metascore = 105 movie.metascore = -1 movie.metascore = "N/A" assert movie.metascore == None
def test_director(): movie = Movie("Sharknado", 2020) director = Director("Anthony Ferrante") movie.director = director assert movie.director == director assert repr(movie.director) == "<Director Anthony Ferrante>" movie = Movie("Sharknado", 2020) director = "Anthony Ferrante" movie.director = director assert movie.director == None
def movie_to_dict(movie: Movie): movie_dict = { 'title': movie.title, 'release_year': movie.release_year, 'description': movie.description, 'director': movie.director.director_full_name, 'runtime_minutes': movie.runtime_minutes, 'actors': [actor.actor_full_name for actor in movie.actors], 'genres': [genre.genre_name for genre in movie.genres], 'reviews': reviews_to_dict(movie.reviews), 'rating': movie.rating, 'votes': movie.votes, 'revenue_in_millions': movie.revenue_in_millions, 'metascore': movie.metascore, 'image_link': movie.image_link, 'runtime_string': movie.get_runtime_string() } return movie_dict
def test_add_actor(): movie1 = Movie("Sharknado", 2020) actors = [ Actor("Auli'i Cravalho"), Actor("Dwayne Johnson"), Actor("Rachel House"), Actor("Temuera Morrison") ] for actor in actors: movie1.add_actor(actor) assert movie1.actors == actors movie1.add_actor("Jeff") assert movie1.actors == actors
def test_select_movie_to_watch(watchlist): # Add several movies to the watchlist watchlist.watchlist = [ Movie("Moana", 2016), Movie("Ice Age", 2002), Movie("Guardians of the Galaxy", 2012) ] # Test that selection works assert watchlist.select_movie_to_watch(0) == Movie("Moana", 2016) assert watchlist.select_movie_to_watch(1) == Movie("Ice Age", 2002) assert watchlist.select_movie_to_watch(2) == Movie( "Guardians of the Galaxy", 2012) # Test out of bounds checking assert watchlist.select_movie_to_watch(-1) == None assert watchlist.select_movie_to_watch(3) == None assert watchlist.select_movie_to_watch(4) == None
def test_make_movie_actor_association(): movie = Movie("Test", 2020) actor = Actor("Test") make_movie_actor_association(movie, actor) assert actor in movie.actors assert movie in actor.movies
def test_make_movie_genre_association(): movie = Movie("Test", 2020) genre = Genre("Test") make_movie_genre_association(movie, genre) assert genre in movie.genres assert movie in genre.movies
def test_make_movie_director_association(): movie = Movie("Test", 2020) director = Director("Test") make_movie_director_association(movie, director) assert director == movie.director assert movie in director.directed_movies
assert (director3 < director1) director4 = Director("aaaaa") assert (director3 < director4) director5 = "aaaaa" with pytest.raises(TypeError): assert not (director5 < director3) def test_hash(): director1_hash = Director("Taika Waititi").__hash__() director2_hash = Director("Taika Waititi").__hash__() director3_hash = Director("David").__hash__() assert director1_hash == director2_hash assert director1_hash != director3_hash @pytest.mark.parametrize("movie", [Movie("Test", 2020), Movie("Test2", 2020)]) def test_add_movie(movie): director = Director("Taika Waititi") director.add_movie(movie) assert director.directed_movies == [movie] @pytest.mark.parametrize("movie", [Movie("Test", 2020), Movie("Test2", 2020)]) def test_has_directed_movie(movie): director = Director("Taika Waititi") director.add_movie(movie) assert director.has_directed_movie(movie)
def test_get_movies_by_release_year_multiple(populated_memory_repo): movies = populated_memory_repo.get_movies_by_release_year(2014) assert movies == [Movie("Guardians of the Galaxy", 2014), Movie("Test", 2014)]
def test_get_movies_by_title_with_same_title(populated_memory_repo): movies = populated_memory_repo.get_movies_by_title("Test") assert movies == [Movie("Test", 2014), Movie("Test", 2020)]