def test_movie_actor_colleagues(actor_from_file, movie_from_file): actor1 = Actor("Bradley Cooper") actor2 = Actor("Christian Bale") assert actor_from_file in movie_from_file.actors assert actor1 in movie_from_file.actors actors = [actor for actor in movie_from_file.actors] assert actors[0].check_if_this_actor_worked_with(actor_from_file) is False assert actors[0].check_if_this_actor_worked_with(actor1) is True assert actors[0].check_if_this_actor_worked_with(actor2) is False assert actors[1].check_if_this_actor_worked_with(actor_from_file) is True assert actors[1].check_if_this_actor_worked_with(actor1) is True
def test_repository_can_get_actors_with_colleagues(in_memory_repo): colleague_names = 'Vin Diesel, Bradley Cooper, Zoe Saldana, Jennifer Lawrence' colleagues = [Actor(name) for name in colleague_names.split(',')] actor_with_colleagues = in_memory_repo.get_actors_by_colleagues(colleagues) assert Actor('Chris Pratt') in actor_with_colleagues assert len(actor_with_colleagues) == 1 colleague_names = 'Margot Robbie, Viola Davis, Sam Smith' colleagues = [Actor(name) for name in colleague_names.split(',')] actor_with_colleagues = in_memory_repo.get_actors_by_colleagues(colleagues) assert Actor('Will Smith') in actor_with_colleagues assert Actor('Jared Leto') in actor_with_colleagues assert len(actor_with_colleagues) == 2
def test_repository_can_get_movies_with_actors(in_memory_repo): actor_names = 'Vin Diesel, Bradley Cooper, Zoe Saldana' actors = [Actor(name) for name in actor_names.split(',')] movie_ranks = in_memory_repo.get_movie_ranks_by_actors(actors) movies_with_actors = in_memory_repo.get_movies_by_rank(movie_ranks) assert Movie('Guardians of the Galaxy', 2014) in movies_with_actors assert len(movies_with_actors) == 1 actors = [Actor('Chris Pratt')] movie_ranks = in_memory_repo.get_movie_ranks_by_actors(actors) movies_with_actors = in_memory_repo.get_movies_by_rank(movie_ranks) assert Movie('Guardians of the Galaxy', 2014) in movies_with_actors assert Movie('Passengers', 2016) in movies_with_actors assert len(movies_with_actors) == 2
def test_actor_colleagues(director, actor, actor_invalid): actors = [ actor, actor_invalid, Actor(42), Actor("Angelina Jolie"), Actor("Brad Pitt"), director ] for actor_x in actors: actor.add_actor_colleague(actor_x) assert actor.check_if_this_actor_worked_with(actor) is False assert actor.check_if_this_actor_worked_with(actor_invalid) is False assert actor.check_if_this_actor_worked_with(actors[2]) is False assert actor.check_if_this_actor_worked_with(actors[3]) is True assert actor.check_if_this_actor_worked_with(actors[4]) is False assert actor.check_if_this_actor_worked_with(director) is False
def test_movie_add_actors(director, actor, movie, actor_invalid, movie_invalid): actors = [ Actor("Auli'i Cravalho"), Actor("Dwayne Johnson"), Actor("Rachel House"), Actor("Temuera Morrison") ] for actor_x in actors: movie.add_actor(actor_x) assert [actor for actor in movie.actors] == actors actors = [actor, actor_invalid, director, actor] for actor_x in actors: movie_invalid.add_actor(actor_x) assert actor_invalid not in movie_invalid.actors assert director not in movie_invalid.actors assert sum(1 for _ in movie_invalid.actors) == 1
def test_movie_remove_actors(director, actor, movie, actor_invalid): actors = [ Actor("Auli'i Cravalho"), Actor("Dwayne Johnson"), Actor("Rachel House"), Actor("Temuera Morrison") ] for actor_x in actors: movie.add_actor(actor_x) assert [actor for actor in movie.actors] == actors movie.remove_actor(actor) assert [actor for actor in movie.actors] == actors movie.remove_actor(actor_invalid) assert [actor for actor in movie.actors] == actors movie.remove_actor(actors[0]) assert actors[0] not in movie.actors and [actor for actor in movie.actors ] != actors movie.remove_actor(director) assert sum(1 for _ in movie.actors) == 3
def test_movie_file_reader_movies(movie_from_file): movie = Movie("Guardians of the Galaxy", 2014) director = Director("James Gunn") actor = Actor("Chris Pratt") genre = Genre("Action") assert repr(movie_from_file) == repr(movie) assert repr(movie_from_file.director) == repr(director) assert actor in movie_from_file.actors assert genre in movie_from_file.genres assert movie_from_file.runtime_minutes == 121
def test_repository_can_get_most_common_actors(in_memory_repo): with pytest.raises(RepositoryException): in_memory_repo.get_most_common_actors(0) with pytest.raises(RepositoryException): in_memory_repo.get_most_common_actors('') most_common_actors = in_memory_repo.get_most_common_actors(1) assert Actor('Chris Pratt') in most_common_actors most_common_actors = in_memory_repo.get_most_common_actors(50) assert len(most_common_actors) == sum( 1 for _ in in_memory_repo.get_movie_file_csv_reader().dataset_of_actors)
def test_repository_can_add_actor(in_memory_repo): actor = Actor("Bob Jones") in_memory_repo.add_actor(actor) assert in_memory_repo.get_actor(actor.actor_full_name) is actor
def test_repository_can_get_actor(in_memory_repo): actor = in_memory_repo.get_actor('Chris Pratt') assert actor == Actor('Chris Pratt') assert actor.check_if_this_actor_worked_with(Actor('Vin Diesel')) is True assert actor.check_if_this_actor_worked_with( Actor('Jennifer Lawrence')) is True
def test_repository_cannot_get_movies_with_no_genres(in_memory_repo): genres = [0, Actor('Bob'), 'hello'] movie_ranks = in_memory_repo.get_movie_ranks_by_genres(genres) movies_with_genres = in_memory_repo.get_movies_by_rank(movie_ranks) assert len(movies_with_genres) == 0
def test_actor_eq(actor, actor_invalid): actors = [Actor(42), Actor("Angelina Jolie"), Actor("Brad Pitt")] assert actor_invalid == actors[0] assert actor != actors[1] assert actor == actors[2]
def actor_invalid(): return Actor(" ")
def actor(): return Actor("Brad Pitt")
def test_actor_hash(actor, actor_invalid): actors = [Actor(42), Actor("Angelina Jolie"), Actor("Brad Pitt")] assert hash(actor) == hash(actors[2]) assert hash(actor) != hash(actors[1]) assert hash(actor_invalid) == hash(actors[0])
def test_actor_lt(actor, actor_invalid): actors = [Actor(42), Actor("Angelina Jolie"), Actor("Brad Pitt")] assert actors[1] < actors[2] assert not actor < actors[2] assert actor_invalid < actor assert not actor_invalid < actors[0]
def test_repository_cannot_add_invalid_actor(in_memory_repo): with pytest.raises(RepositoryException): in_memory_repo.add_actor(0) with pytest.raises(RepositoryException): in_memory_repo.add_actor(Actor(''))
def test_actor_constructor(actor, actor_invalid): assert repr(actor) == "<Actor Brad Pitt>" assert repr(actor_invalid) == "<Actor None>" assert actor_invalid.actor_full_name is None actor3 = Actor(42) assert actor3.actor_full_name is None