Exemplo n.º 1
0
def dict_to_movie(dict):
    movie = Movie(dict.title, dict.year)
    movie.id=dict.id
    movie.description = dict.description
    movie.hyperlink = dict.hyperlink
    # Note there's no reviews or genres.
    return movie
Exemplo n.º 2
0
def test_genre_construction(genre):
    assert genre.genre_full_name == 'NewGenre'

    for movie in genre.tagged_movies:
        assert False

    assert not genre.is_applied_to(Movie('TESTER', 2020))
Exemplo n.º 3
0
def test_repository_can_add_or_remove_movie_to_or_from_watch_list(
        in_memory_repo):
    user = in_memory_repo.get_user('fmercury')
    movie = Movie("Hello")
    in_memory_repo.add_to_watch_list(user, movie)
    assert len(user.watch_list.watch_list) == 1
    assert user.watch_list.watch_list[0].title == "Hello"
    in_memory_repo.remove_from_watch_list(user, movie)
    assert len(user.watch_list.watch_list) == 0
Exemplo n.º 4
0
def movie():
    movie = Movie('Moana', 2016)
    movie.id = int(14)
    movie_genres = "Animation,Adventure,Comedy".split(",")
    movie.description = "A terrible curse incurred by the demigod Maui ignites a young girls destiny"
    movie.director = 'Ron Clements'
    movie_actors = "Auli'i Cravalho, Dwayne Johnson, Rachel House, Temuera Morrison".split(",")
    movie.runtime_minutes = 107
    movie.rating = float(7.7)
    movie.votes = 118151
    movie.revenue = 248.75
    movie.metascore = 81

    for actor_name in movie_actors:
        actor = Actor(actor_name)
        make_actor_association(movie, actor)

    for genre_name in movie_genres:
        genre = Genre(genre_name)
        make_genre_association(movie, genre)
def test_repository_can_search_by_actor(in_movie_repo):
    movies = in_movie_repo.get_result("Chris Pratt")

    # Check that can search by title.
    assert movies == [
        Movie("Guardians of the Galaxy", 2014),
        Movie("Passengers", 2016),
        Movie("The Magnificent Seven", 2016),
        Movie("Jurassic World", 2015),
        Movie("The Lego Movie", 2014),
        Movie("Zero Dark Thirty", 2012),
        Movie("10 Years", 2011)
    ]
Exemplo n.º 6
0
def new_load_movie_actor_and_genre(data_path, repo: MovieRepo):
    filename = os.path.join(data_path, "Data1000Movies.csv")
    with open(filename, mode='r', encoding='utf-8-sig') as csvfile:
        movie_file_reader = csv.DictReader(csvfile)
        for row in movie_file_reader:
            title = row['Title']
            release_year = int(row['Year'])
            run_time = int(row['Runtime (Minutes)'])
            director = Director(row["Director"])
            actor_list = row["Actors"].split(',')
            description = row['Description']
            genre_list = row['Genre'].split(",")
            rating = row['Rating']
            votes = row['Votes']
            rank = int(row['Rank'])

            movie = Movie(title, release_year, new_id=rank)
            movie.description = description
            movie.actors = actor_list
            movie.genres = genre_list
            movie.runtime_minutes = run_time
            movie.rating = rating
            movie.votes = votes

            repo.add_movie(movie)
            repo.add_movie_to_year_dict(movie, release_year)
            for genre in genre_list:
                new_g = Genre(genre)
                new_g.add_movie(movie)
                repo.add_genre(new_g)
                repo.add_movie_to_genre_dict(movie, new_g)

            for actor in actor_list:
                new_a = Actor(actor)
                new_a.movies = movie
                repo.add_actor(new_a)
                repo.add_movie_to_actor_dict(movie, new_a)
            repo.add_movie_to_director_dict(movie, director)
            repo.add_director(director)
 def dataset_of_movies(self) -> list:
     with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
         movie_file_reader = csv.DictReader(csvfile)
         index = 0
         movies=[]
         for row in movie_file_reader:
             new_movie = Movie(row['Title'],int(row['Year']))
             new_movie.director = Director(row['Director'])
             gn=[]
             for a in row['Genre'].split(","):
                 temp=Genre(a.strip())
                 gn.append(temp)
             new_movie.genres = gn
             ac=[]
             for a in row['Actors'].split(","):
                 temp=Actor(a.strip())
                 ac.append(temp)
             new_movie.actors = ac
             new_movie.id = int(row['Rank'])
             new_movie.runtime_minutes = int(row['Runtime (Minutes)'])
             new_movie.description = row['Description']
             movies.append(new_movie)
             index += 1
         return list(movies)
    def read_csv_file(self):
        with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
            movie_file_reader = csv.DictReader(csvfile)
            for row in movie_file_reader:
                title = row['Title']
                release_year = int(row['Year'])
                movie = Movie(title, release_year)
                movie.director = Director(row["Director"])
                actor_list = row["Actors"].split(',')
                movie.actors = actor_list
                self._dataset_of_movies.append(movie)
                genre_list = row['Genre'].split(",")
                description = row['Description']
                movie.description = description
                for genre in genre_list:
                    new_g = Genre(genre)
                    new_g.add_movie(movie)
                    self._dataset_of_genres.add(new_g)
                    if new_g in self._genre_dict:
                        if movie not in self._genre_dict[new_g]:
                            self._genre_dict[new_g] += [movie]
                    else:
                        self._genre_dict[new_g] = [movie]
                movie.genres = genre_list
                self._actor_list += actor_list
                for actor in actor_list:
                    new_a = Actor(actor)
                    if new_a not in self._actor_dict:
                        self._actor_dict[new_a] = [movie]
                    else:
                        if movie not in self._actor_dict[new_a]:
                            self._actor_dict[new_a] += [movie]
                    self._dataset_of_actors.add(new_a)
                    new_a.movies = movie

                director_list = row["Director"].split(',')
                for director in director_list:
                    new_d = Director(director)
                    if new_d not in self._director_dict:
                        self._director_dict[new_d] = [movie]
                    else:
                        if movie not in self._director_dict:
                            self._director_dict[new_d] += [movie]
                    self._dataset_of_directors.add(new_d)
                    new_d.movies = movie
def test_watchlist(user, movie):
    user.watch_movie(movie)
    assert user.watched_movies == [Movie("Molly", 2018)]
def test_movie_less_than_operator():
    movie_1 = Movie(None, 2010)

    movie_2 = Movie(None, 2012)

    assert movie_1 < movie_2
def movie():
    return Movie("Molly", 2018)
Exemplo n.º 12
0
def test_repository_can_add_movie(in_memory_repo):
    movie = Movie("Moana", 1900, 7)
    in_memory_repo.add_movie(movie)

    assert in_memory_repo.get_movie(7) is movie
def test_repository_can_get_first_movie(in_movie_repo):
    movie = in_movie_repo.get_first_movie()
    assert movie == Movie("Guardians of the Galaxy", 2014)
Exemplo n.º 14
0
def dict_to_movie(dict):
    movie = Movie(dict['title'], dict['release_year'])
    return movie
Exemplo n.º 15
0
def load_movies(data_path: str, repo: MemoryRepository):
    genres = dict()
    directors = dict()
    actors = dict()

    for data_row in read_csv_file(os.path.join(data_path,
                                               'Data1000Movies.csv')):
        movie = Movie(data_row[1], int(data_row[6]))
        movie.id = int(data_row[0])
        movie_genres = data_row[2].split(",")
        movie.description = data_row[3]
        movie.director = data_row[4]
        movie_actors = data_row[5].split(",")
        movie.runtime_minutes = int(data_row[7])
        movie.rating = float(data_row[8])
        movie.votes = int(data_row[9])
        revenue = data_row[10]
        metascore = data_row[11]

        for genre in movie_genres:
            if genre not in genres.keys():
                genres[genre] = list()
            genres[genre].append(movie.id)

        for actor in movie_actors:
            if actor not in actors.keys():
                actors[actor] = list()
            actors[actor].append(movie.id)

        if movie.director not in directors.keys():
            directors[movie.director] = list()
        directors[movie.director].append(movie.id)

        if revenue[0].isdigit():
            movie.revenue = float(revenue)
        else:
            movie.revenue = 'Not Available'

        if metascore[0].isdigit():
            movie.metascore = float(metascore)
        else:
            movie.metascore = 'Not Available'

        repo.add_movie(movie)

    for actor_name in actors.keys():
        actor = Actor(actor_name)
        for movie_id in actors[actor_name]:
            movie = repo.get_movie_by_id(movie_id)
            make_actor_association(movie, actor)
        repo.add_actor(actor)

    for genre_name in genres.keys():
        genre = Genre(genre_name)
        for movie_id in genres[genre_name]:
            movie = repo.get_movie_by_id(movie_id)
            make_genre_association(movie, genre)
        repo.add_genre(genre)

    for director_name in directors.keys():
        director = Director(director_name)
        for movie_id in directors[director_name]:
            movie = repo.get_movie_by_id(movie_id)
            make_director_association(movie, director)
        repo.add_director(director)
def test_repository_can_add_movie(in_movie_repo):
    movie = Movie("Snow White", 2020)
    in_movie_repo.add_movie(movie)

    assert in_movie_repo.get_movie(1001) is movie
def test_repository_can_add_movies(in_movie_repo):
    movies = [Movie("abc", 2020), Movie("def", 2021)]
    in_movie_repo.add_movies(movies)

    assert in_movie_repo.get_number_of_movies() == 1002
def test_repository_can_search_by_director(in_movie_repo):
    directors = in_movie_repo.get_result("James Ward Byrkit")

    assert directors == [Movie("Coherence", 2013)]
Exemplo n.º 19
0
def test_article_less_than_operator():
    article_1 = Movie('No Game No Life', 2014)

    article_2 = Movie('No Game No Life: 2', 2021)

    assert article_1 < article_2
 def add_movie(self, movie:Movie):
     movie.id = len(self._movies)+1
     if movie.year not in self._years:
         self._years.append(movie.year)
     insort_left(self._movies, movie)
     self._movies_index[movie.id] = movie
Exemplo n.º 21
0
def dict_to_movies(dict):
    movie = Movie(dict.id, dict.year, dict.title)
    movie.description = dict.description
    movie.hyperlink = dict.hyperlink
    # Note there's no comments or tags.
    return movie