Esempio n. 1
0
def test_le():
    genre1 = Genre("Comedy")
    genre2 = Genre("Drama")
    assert genre1 <= genre2
    assert genre2 >= genre1
    genre1 = Genre("Comedy")
    genre2 = Genre("Comedy")
    assert genre1 <= genre2
    assert genre2 >= genre1
Esempio n. 2
0
def test_init(genre):
    assert genre.genre_name == 'Drama'
    genre1 = Genre("Comedy")
    assert repr(genre1) == "<Genre Comedy>"
    genre2 = Genre("")
    assert genre2.genre_name is None
    genre3 = Genre(42)
    assert genre3.genre_name is None
    assert repr(genre2) == "<Genre None>"
    assert repr(genre3) == "<Genre None>"
Esempio n. 3
0
def test_hash():
    genre1 = Genre("Comedy")
    genre2 = Genre("Comedy")
    assert hash(genre1) == hash(genre2)
    genre2 = Genre("Comedz")
    assert hash(genre1) != hash(genre2)
    dict1 = dict()
    dict1[genre1] = genre2
    assert dict1[genre1] == genre2
    assert repr(dict1[genre1]) == "<Genre Comedz>"
    genre1 = Genre("")
    genre2 = Genre(7)
    dict1[genre1] = genre2
    assert dict1[genre1] == genre2
    assert repr(dict1[genre1]) == "<Genre None>"
Esempio n. 4
0
 def get_movies_for_genre(self, genre_name: str):
     list_of_movies = []
     for movie in self.__dataset_of_movies:
         if not len(movie.genres) == 0:
             if Genre(genre_name) in movie.genres:
                 list_of_movies.append(movie)
     return list_of_movies
Esempio n. 5
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. 6
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. 7
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. 8
0
def test_top_genres(stats):
    assert stats.top_genres(2) == [Genre("Comedy"), Genre("Action")]
    assert stats.top_genres(6) == []
    assert stats.top_genres(-1) == [
        Genre("Comedy"),
        Genre("Action"),
        Genre("Romance"),
        Genre("Drama")
    ]
Esempio n. 9
0
def test_compare():
    genre1 = Genre("Comedy")
    genre2 = Genre("Comedy")
    assert genre1 == genre2
    genre2 = 4
    assert genre1 != genre2
    genre1 = Genre("")
    genre2 = Genre(45)
    assert genre1 == genre2
    genre1 = Genre("Comedy")
    genre2 = Genre("comedy")
    assert genre1 != genre2
Esempio n. 10
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. 11
0
def test_add_genre(in_memory_repo):
    assert Genre("Anime") not in in_memory_repo.get_genres()
    in_memory_repo.add_genre(Genre("Anime"))
    assert Genre("Anime") in in_memory_repo.get_genres()
Esempio n. 12
0
def genre():
    return Genre('Drama')
Esempio n. 13
0
def test_lt():
    genre1 = Genre("Comedy")
    genre2 = Genre("Drama")
    assert genre1 < genre2
    assert genre2 > genre1
Esempio n. 14
0
def test_add_remove_genre(movie):
    movie.add_genre(Genre("Comedy"))
    movie.add_genre(Genre(""))
    movie.add_genre(Genre(3))
    movie.add_genre(4)
    movie.add_genre(Genre("Drama"))
    assert movie.genres == [Genre("Comedy"), Genre("Drama")]
    movie.remove_genre(Genre("Comedy"))
    assert movie.genres == [Genre("Drama")]
    movie.remove_genre(Genre("Comedy"))
    assert movie.genres == [Genre("Drama")]
    movie.remove_genre(Genre("Drama"))
    movie.remove_genre(Genre("Drama"))
    movie.remove_genre(4)
    movie.remove_genre(Genre(""))
    assert movie.genres == []
    movie.remove_genre(Genre("Drama"))
    assert movie.actors == []