Esempio n. 1
0
def test_top_directors(stats):
    assert stats.top_directors(1) == [Director("Peter Jackson")]
    assert stats.top_directors(6) == []
    assert stats.top_directors(-1) == [
        Director("Peter Jackson"),
        Director("Taika Waititi")
    ]
Esempio n. 2
0
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
Esempio n. 3
0
def test_compare():
    director1 = Director("Taika Waititi")
    director2 = Director("Taika Waititi")
    assert director1 == director2
    director2 = 4
    assert director1 != director2
    director1 = Director("")
    director2 = Director(45)
    assert director1 == director2
Esempio n. 4
0
def test_init(director):
    assert director.director_full_name == 'Taika Waititi'
    director1 = Director("Taika Waititi")
    assert repr(director1) == "<Director Taika Waititi>"
    director2 = Director("")
    assert director2.director_full_name is None
    director3 = Director(42)
    assert director3.director_full_name is None
    assert repr(director2) == "<Director None>"
    assert repr(director3) == "<Director None>"
Esempio n. 5
0
def test_hash():
    director1 = Director("Taika Waititi")
    director2 = Director("Taika Waititi")
    assert hash(director1) == hash(director2)
    director2 = Director("Taika Waititj")
    assert hash(director1) != hash(director2)
    dict1 = dict()
    dict1[director1] = director2
    assert dict1[director1] == director2
    assert repr(dict1[director1]) == "<Director Taika Waititj>"
    director1 = Director("")
    director2 = Director(9)
    dict1[director1] = director2
    assert dict1[director1] == director2
    assert repr(dict1[director1]) == "<Director None>"
Esempio n. 6
0
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") == []
Esempio n. 7
0
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)
Esempio n. 8
0
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
    }
Esempio n. 9
0
def test_init(stats):
    assert stats.user == User("aram", "one1", [], [], None, 0)
    assert stats.watched_movies == [
        Movie("Up", 2009),
        Movie("Down", 2013),
        Movie("Boom", 1999)
    ]
    assert stats.watched_actors == {
        Actor("Will Smith"): 2,
        Actor("Daniel Radcliff"): 1,
        Actor("Selena Gomez"): 1,
        Actor("Tom Cruise"): 2
    }
    assert stats.watched_directors == {
        Director("Peter Jackson"): 2,
        Director("Taika Waititi"): 1
    }
    assert stats.watched_genres == {
        Genre("Comedy"): 3,
        Genre("Romance"): 1,
        Genre("Drama"): 1,
        Genre("Action"): 1
    }
Esempio n. 10
0
def test_add_genre(in_memory_repo):
    assert Director("Katy Perry") not in in_memory_repo.get_directors()
    in_memory_repo.add_director(Director("Katy Perry"))
    assert Director("Katy Perry") in in_memory_repo.get_directors()
Esempio n. 11
0
def director():
    return Director('Taika Waititi')
Esempio n. 12
0
def test_lt():
    director1 = Director("Taika Waititi")
    director2 = Director("Aika Waititi")
    assert director1 > director2
Esempio n. 13
0
def test_attribute_access(movie):
    # Checking Movie title
    movie.title = ""
    assert repr(movie) == "<Movie None, 2009>"
    movie.title = "Annabelle"
    assert repr(movie) == "<Movie Annabelle, 2009>"
    movie.title = 5
    assert repr(movie) == "<Movie None, 2009>"
    movie.title = "Annabelle"

    # Checking Movie release year
    movie.release_year = 0
    assert repr(movie) == "<Movie Annabelle, None>"
    movie.release_year = 2021
    assert repr(movie) == "<Movie Annabelle, None>"
    movie.release_year = 2016
    assert repr(movie) == "<Movie Annabelle, 2016>"
    movie.release_year = 'a'
    assert repr(movie) == "<Movie Annabelle, None>"

    # Checking Movie description
    movie.description = 0
    assert movie.description is None
    movie.description = ""
    assert movie.description is None
    movie.description = "Test-description"
    assert movie.description == "Test-description"

    # Checking Movie runtime
    movie.runtime_minutes = "a"
    assert movie.runtime_minutes is None
    with pytest.raises(ValueError):
        movie.runtime_minutes = -14
    movie.runtime_minutes = 130
    assert movie.runtime_minutes == 130

    # Checking Movie Director
    movie.director = 3
    assert repr(movie.director) == "None"
    movie.director = Director(3)
    assert repr(movie.director) == "<Director None>"
    director = Director("Peter Jackson")
    movie.director = director
    assert movie.director == Director("Peter Jackson")
    movie.director = Director("")
    assert repr(movie.director) == "<Director None>"

    # Checking Movie Votes
    movie.votes = "a"
    assert movie.votes is None
    with pytest.raises(ValueError):
        movie.votes = -1
    movie.votes = 10
    assert movie.votes == 10

    # Checking Movie Rating
    movie.rating = "a"
    assert movie.rating is None
    with pytest.raises(ValueError):
        movie.rating = 11
    with pytest.raises(ValueError):
        movie.rating = -1
    movie.rating = 10
    assert movie.rating == 10

    # Checking Movie Rating after changing to 0 votes
    movie.votes = 0
    print(movie.rating)
    assert movie.rating is None
    movie.rating = 10
    assert movie.rating is None