Пример #1
0
def test_movie_file_csv_reader():
    filename = "tests/data/database/Data1000Movies.csv"
    movie_file_reader = MovieFileCSVReader(filename)
    movie_file_reader.read_csv_file()

    assert len(movie_file_reader.dataset_of_movies) == 1000
    assert len(movie_file_reader.dataset_of_actors) == 1985
    assert len(movie_file_reader.dataset_of_directors) == 644
    assert len(movie_file_reader.dataset_of_genres) == 20

    all_movies_sorted = sorted(movie_file_reader.dataset_of_movies)
    #print(f'first 3 unique movies of sorted dataset: {all_movies_sorted[0:3]}')
    assert all_movies_sorted[0:3] == [Movie("(500) Days of Summer", 2009), Movie("10 Cloverfield Lane", 2016), Movie("10 Years", 2011)]

    all_actors_sorted = sorted(movie_file_reader.dataset_of_actors)
    #print(f'first 3 unique actors of sorted dataset: {all_actors_sorted[0:3]}')
    assert all_actors_sorted[0:3] == [Actor("50 Cent"), Actor("A.C. Peterson"), Actor("AJ Michalka")]

    all_directors_sorted = sorted(movie_file_reader.dataset_of_directors)
    #print(f'first 3 unique directors of sorted dataset: {all_directors_sorted[0:3]}')
    assert all_directors_sorted[0:3] == [Director("Aamir Khan"), Director("Abdellatif Kechiche"), Director("Adam Leon")]

    all_genres_sorted = sorted(movie_file_reader.dataset_of_genres)
    #print(f'first 3 unique genres of sorted dataset: {all_genres_sorted[0:3]}')
    assert all_genres_sorted[0:3] == [Genre("Action"), Genre("Adventure"), Genre("Animation")]
Пример #2
0
def test_director_eq():
    director1 = Director("Taika Waititi")
    director2 = Director("Taika Waititi")
    director3 = Director("Peter Jackson")

    assert (director1 == director2) is True
    assert (director2 == director3) is False
Пример #3
0
def test_director_hash():
    director1 = Director("Taika Waititi")
    director2 = Director("Peter Jackson")
    director_set = set()

    director_set.add(director1)
    director_set.add(director2)
Пример #4
0
def test_director_init():
    director1 = Director("Taika Waititi")
    assert repr(director1) == "<Director Taika Waititi>"
    assert director1.director_full_name is "Taika Waititi"
    director2 = Director("")
    assert director2.director_full_name is None
    director3 = Director(42)
    assert director3.director_full_name is None
 def read_csv_file(self):
     with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
         movie_file_reader = csv.DictReader(csvfile)
         #index = 0
         genre_dict = {}
         director_dict = {}
         actor_dict = {}
         for row in movie_file_reader:
             movie_id = int(row['id'])
             movie_title = row['Title']
             release_year = int(row['Year'])
             movie = Movie(movie_id, movie_title, release_year)
             self.__movies.add(movie)
             genre = row["Genre"]
             genres_list = genre.split(",")
             for genre_name in genres_list:
                 if genre_name not in genre_dict:
                     genre_dict[genre_name] = [movie]
                 else:
                     genre_dict[genre_name] = genre_dict[genre_name] + [movie]
             des = row['Description']
             movie.set_des(des)
             the_director = row["Director"]
             if the_director not in director_dict:
                 director_dict[the_director] = [movie]
             else:
                 director_dict[the_director] = director_dict[the_director] + [movie]
             actor_list = row["Actors"]
             for actor in actor_list.split(","):
                 actor = actor.strip()
                 if actor not in actor_dict:
                     actor_dict[actor] = [movie]
                 else:
                     actor_dict[actor] = actor_dict[actor] + [movie]
         for genre_name in genre_dict:
             genre = Genre(genre_name)
             for movie in genre_dict[genre_name]:
                 genre.add_movie(movie)
                 movie.add_genre(genre)
             self.__genres.add(genre)
         for director_name in director_dict:
             director = Director(director_name)
             for movie in director_dict[director_name]:
                 director.add_dir_movie(movie)
                 movie.director = director
             self.__directors.add(director)
         for actor_name in actor_dict:
             actor = Actor(actor_name)
             for movie in actor_dict[actor_name]:
                 actor.add_joined_movie(movie)
                 movie.add_actor(actor)
             self.__actors.add(actor)
Пример #6
0
def test_movie_set_director():
    movie = Movie("Moana", 2016)
    movie.description = "   This is a movie   "
    assert movie.description == "This is a movie"
    movie.director = Director("Ron Clements")
    assert movie.director.director_full_name is "Ron Clements"
    assert repr(movie.director) == "<Director Ron Clements>"
Пример #7
0
def test_movie_runtime():
    movie = Movie("Moana", 2016)
    movie.description = "   This is a movie   "
    assert movie.description == "This is a movie"
    movie.director = Director("Ron Clements")
    assert movie.director.director_full_name is "Ron Clements"
    assert repr(movie.director) == "<Director Ron Clements>"

    actors = [
        Actor("Auli'i Cravalho"),
        Actor("Dwayne Johnson"),
        Actor("Rachel House"),
        Actor("Temuera Morrison")
    ]
    for actor in actors:
        movie.add_actor(actor)
    assert repr(
        movie.actors
    ) == "[<Actor Auli\'i Cravalho>, <Actor Dwayne Johnson>, <Actor Rachel House>, <Actor Temuera Morrison>]"
    movie.remove_actor(Actor("Dwayne Johnson"))
    assert repr(
        movie.actors
    ) == "[<Actor Auli\'i Cravalho>, <Actor Rachel House>, <Actor Temuera Morrison>]"

    genres = [Genre("Animated"), Genre("Comedy")]
    for genre in genres:
        movie.add_genre(genre)
    assert repr(movie.genres) == "[<Genre Animated>, <Genre Comedy>]"
    movie.remove_genre(Genre("Comedy"))
    assert repr(movie.genres) == "[<Genre Animated>]"

    movie.runtime_minutes = 100
    assert movie.runtime_minutes is 100
Пример #8
0
def test_repository_can_add_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    movie = Movie('Guardians of the Galaxy', 2014)
    movie.runtime_minutes = 121
    movie.actors = [
        Actor('Chris Pratt'),
        Actor('Vin Diesel'),
        Actor('Bradley Cooper'),
        Actor('Zoe Saldana')
    ]
    movie.genres = [Genre('Action'), Genre('Adventure'), Genre('Sci-Fi')]
    movie.description = "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe."
    movie.director = [Director('James Gunn')]
    movie.rating = 8.1
    movie.meta = 76
    movie.revenue = 333.13
    movie.vote = 757074

    repo.add_movie(1, 'Guardians of the Galaxy', 2014, movie.description,
                   'James Gunn',
                   'Chris Pratt, Vin Diesel, Bradley Cooper, Zoe Saldana',
                   'Action,Adventure,Sci-Fi', movie.runtime_minutes,
                   movie.rating, movie.revenue, movie.meta, movie.vote)

    assert repo.get_movie("Guardians of the Galaxy") == movie
    def read_csv_file(self):
        with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
            movie_file_reader = csv.DictReader(csvfile)

            index = 0
            for row in movie_file_reader:
                rank = row['Rank']
                title = row['Title']
                release_year = int(row['Year'])
                self.__dataset_of_movies.append(Movie(title, release_year))
                self.__rank_of_movies[rank] = Movie(title, release_year)

                # add movie with same year into movies_with_given_year
                if release_year not in self.__movies_with_given_year.keys():
                    self.__movies_with_given_year[release_year] = [Movie(title, release_year)]
                else:
                    movie = Movie(title, release_year)
                    self.__movies_with_given_year[release_year].append(movie)

                actors = row['Actors']
                actors_list = actors.split(',')
                for actor in actors_list:
                    if actor not in self.__dataset_of_actors:
                        self.__dataset_of_actors.add(Actor(actor))

                # add movie with same actor into movies_with_given_actor
                for actor in actors_list:
                    if actor not in self.__movies_with_given_actor:
                        self.__movies_with_given_actor[actor] = [Movie(title, release_year)]
                    else:
                        self.__movies_with_given_actor[actor].append(Movie(title, release_year))

                director = row['Director']
                if director not in self.__dataset_of_directors:
                    self.__dataset_of_directors.add(Director(director))

                #add movie with same director into movies_with_given_director
                if director not in self.__movies_with_given_director:
                    self.__movies_with_given_director[director] = [Movie(title, release_year)]
                else:
                    self.__movies_with_given_director[director].append(Movie(title, release_year))

                genres = row['Genre']
                genres_list = genres.split(',')
                for genre in genres_list:
                    if genre not in self.__dataset_of_genres:
                        self.__dataset_of_genres.add(Genre(genre))

                #add movie with same genre into movies_with_given_genre
                for genre in genres_list:
                    if genre not in self.__movies_with_given_genre:
                        self.__movies_with_given_genre[genre] = [Movie(title, release_year)]
                    else:
                        self.__movies_with_given_genre[genre].append(Movie(title, release_year))

                if index > 1000:
                    break

                index += 1
Пример #10
0
def test_movie_set_actors():
    movie = Movie("Moana", 2016)
    movie.description = "   This is a movie   "
    assert movie.description == "This is a movie"
    movie.director = Director("Ron Clements")
    assert movie.director.director_full_name is "Ron Clements"
    assert repr(movie.director) == "<Director Ron Clements>"
    actors = [Actor("Auli'i Cravalho"), Actor("Dwayne Johnson"), Actor("Rachel House"), Actor("Temuera Morrison")]
    for actor in actors:
        movie.add_actor(actor)
    assert repr(movie.actors) == "[<Actor Auli\'i Cravalho>, <Actor Dwayne Johnson>, <Actor Rachel House>, <Actor Temuera Morrison>]"
Пример #11
0
    def read_csv_file(self):
        with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
            movie_file_reader = csv.DictReader(csvfile)
            index = 0
            for row in movie_file_reader:
                title = row['Title']
                release_year = int(row['Year'])
                #print(f"Movie {index} with title: {title}, release year {release_year}")
                movie = Movie(title, release_year)

                if movie not in self.dataset_of_movies:
                    self.dataset_of_movies.append(movie)

                actors = row['Actors'].split(",")
                #print("~~~~~")
                for actor in range(len(actors)):
                    actors[actor] = Actor(actors[actor].strip())
                    #added
                    movie.actors.append(actors[actor].actor_full_name)
                    #print(actors[actor].actor_full_name)
                    #end added
                    if actors[actor] not in self.dataset_of_actors:
                        self.dataset_of_actors.add(actors[actor])
                    #if row['Title'] == "Fury":
                    #print("de", actors[actor])
                #print(actors)

                director = Director(row['Director'])
                if director not in self.dataset_of_directors:
                    self.dataset_of_directors.add(director)
                #self.subset_of_movie_directors[str(title)] = []

                genres = row['Genre'].split(",")
                for genre in range(len(genres)):
                    genres[genre] = Genre(genres[genre].strip())
                    # added
                    movie.genres.append(genres[genre].genre_name)
                    # end added
                    if genres[genre] not in self.dataset_of_genres:
                        self.dataset_of_genres.add(genres[genre])
                        #self.dataset_of_genres.append( Genre(genres[genre]) )
                #print(genres)

            # added
                movie.director = row['Director']
                movie.description = row['Description']
                movie.runtime_minutes = int(row['Runtime (Minutes)'])
                # end added

                index += 1
Пример #12
0
def test_movie_init_full():
    movie = Movie("Moana", 2016)
    assert repr(movie) == "<Movie Moana, 2016>"

    director = Director("Ron Clements")
    movie.director = director
    assert repr(movie.director) == "<Director Ron Clements>"

    actors = [Actor("Auli'i Cravalho"), Actor("Dwayne Johnson"), Actor("Rachel House"), Actor("Temuera Morrison")]
    for actor in actors:
        movie.add_actor(actor)
    assert repr(
        movie.actors) == "[<Actor Auli\'i Cravalho>, <Actor Dwayne Johnson>, <Actor Rachel House>, <Actor Temuera Morrison>]"

    movie.runtime_minutes = 107
    assert ("Movie runtime: {} minutes".format(movie.runtime_minutes)) == "Movie runtime: 107 minutes"
Пример #13
0
def movie():
    movie = Movie('Guardians of the Galaxy', 2014)
    movie.runtime_minutes = 121
    movie.actors = [
        Actor('Chris Pratt'),
        Actor('Vin Diesel'),
        Actor('Bradley Cooper'),
        Actor('Zoe Saldana')
    ]
    movie.genres = [Genre('Action'), Genre('Adventure'), Genre('Sci-Fi')]
    movie.description = "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe."
    movie.director = Director('James Gunn')
    movie.rating = 8.1
    movie.meta = 76
    movie.revenue = 333.13
    movie.vote = 757074
    return movie
Пример #14
0
 def add_movie(self, title, year, description, director, actor, genre,
               runtime, rating, revenue, meta, vote):
     movie = Movie(title, year)
     movie.description = description
     movie.director = Director(director)
     actors = actor.split(",")
     for a in actors:
         movie.add_actor(Actor(a.strip()))
     genres = genre.split(",")
     for g in genres:
         movie.add_genre(Genre(g))
     movie.runtime = runtime
     movie.rating = rating
     if revenue != "N/A":
         movie.revenue = float(revenue)
     if meta != "N/A":
         movie.meta = int(meta)
     movie.vote = vote
     self.dataset_of_movies.append(movie)
Пример #15
0
def read_csv_file(filename: str, repo: MemoryRepository):
    with open(filename, mode='r', encoding='utf-8-sig') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            if row == 0:
                continue
            repo.add_movie(row["Title"], int(row["Year"]), row["Description"],
                           row["Director"], row["Actors"], row["Genre"],
                           row["Runtime (Minutes)"], row["Rating"],
                           row["Revenue (Millions)"], row["Metascore"],
                           row["Votes"])

            actors = row["Actors"].split(",")
            for a in actors:
                repo.add_actor(Actor(a.strip()))

            director = row["Director"]
            repo.add_director(Director(director))

            genres = row["Genre"].split(",")
            for g in genres:
                repo.add_genre(Genre(g))
Пример #16
0
def test_article_construction(movie):
    assert movie.title == 'Guardians of the Galaxy'
    assert movie.time == 2014
    assert movie.runtime_minutes == 121
    assert movie.description == "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe."
    assert movie.genres == [
        Genre('Action'), Genre('Adventure'),
        Genre('Sci-Fi')
    ]
    assert movie.actors == [
        Actor('Chris Pratt'),
        Actor('Vin Diesel'),
        Actor('Bradley Cooper'),
        Actor('Zoe Saldana')
    ]
    assert movie.director == Director('James Gunn')
    assert movie.rating == 8.1
    assert movie.meta == 76
    assert movie.revenue == 333.13
    assert movie.vote == 757074

    assert repr(movie) == '<Movie Guardians of the Galaxy, 2014>'
Пример #17
0
    def add_movie(self, id, title, year, description, director, actor, genre,
                  runtime, rating, revenue, meta, vote):
        movie = Movie(title, year)
        movie.description = description
        movie.director = [Director(director)]
        actors = actor.split(",")
        for a in actors:
            movie.add_actor(Actor(a.strip()))
        genres = genre.split(",")
        for g in genres:
            movie.add_genre(Genre(g))
        movie.runtime = runtime
        movie.rating = rating
        if revenue != "N/A":
            movie.revenue = float(revenue)
        if meta != "N/A":
            movie.meta = int(meta)
        movie.vote = vote
        movie.id = id

        with self._session_cm as scm:
            scm.session.add(movie)
            scm.commit()
Пример #18
0
def test_repository_can_add_a_director(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    director = Director('Aoba')
    repo.add_director(director)
    director1 = repo.get_director('Aoba')[0]
    assert director1 == director and director1 is director
Пример #19
0
def test_movie_director_handling():
    movie1 = Movie("Moana", 1916)
    movie1.director = Director("as")
    movie1.director = Director("asb")
    assert repr(movie1.director) == "<Director asb>"
Пример #20
0
def director():
    return Director("Ron Clements")
Пример #21
0
def load_movies_and_genres(data_path: str, repo: MemoryRepository):
    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)
        genres = dict()
        actors = dict()
        directors = dict()
        for row in movie_file_reader:
            movie_id = int(row['id'])
            movie_title = row['Title']
            release_year = int(row['Year'])

            genre = row["Genre"]
            genres_list = genre.split(",")
            for i in genres_list:
                if i not in genres.keys():
                    genres[i] = list()
                genres[i].append(movie_id)

            movie = Movie(movie_id, movie_title, release_year)
            des = row['Description']
            movie.set_des(des)
            repo.add_movie(movie)
            the_director = row["Director"]
            if the_director not in directors:
                directors[the_director] = [movie_id]
            else:
                directors[the_director] = directors[the_director] + [movie_id]
            actor_list = row["Actors"]
            for actor in actor_list.split(","):
                actor = actor.strip()
                if actor not in actors:
                    actors[actor] = [movie_id]
                else:
                    actors[actor] = actors[actor] + [movie_id]

        for director_name in directors:
            director_obj = Director(director_name)
            all_movie = directors[director_name]
            for movie_id in all_movie:
                movie = repo.get_movie_by_id(movie_id)
                movie.director = director_obj
                director_obj.add_dir_movie(movie)
            repo.add_director(director_obj)

        for actor_name in actors:
            actor_obj = Actor(actor_name)
            all_movie = actors[actor_name]
            for movie_id in all_movie:
                movie = repo.get_movie_by_id(movie_id)
                movie.actors.append(actor_obj)
                actor_obj.add_joined_movie(movie)
            repo.add_actor(actor_obj)

        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)
                # movie.add_genre(genre)
                # genre.add_movie(movie)
            repo.add_genre(genre)
Пример #22
0
def director():
    return Director('Maho Hiyajo')
Пример #23
0
def test_repository_can_add_director(in_memory_repo):
    director = Director("Rumiho Akiha")
    in_memory_repo.add_director(director)

    assert in_memory_repo.get_director("Rumiho Akiha") is director
Пример #24
0
def display_movies():
    movie_list = []
    movie_title = request.args.get('movie_title')
    name1 = request.args.get('name1')
    name2 = request.args.get('name2')
    name3 = request.args.get('name3')

    title = request.args.get('title')
    if title is None:
        title = 'Movies'

    if title == 'Movies':
        movie_list = repo.repo_instance.dataset_of_movies

    if title == 'Genre':
        try:
            name1 = Genre(name1.strip().strip('<').strip('>'))
        except:
            pass
        try:
            name2 = Genre(name2.strip().strip('<').strip('>'))
        except:
            pass
        try:
            name3 = Genre(name3.strip().strip('<').strip('>'))
        except:
            pass

        for movie in repo.repo_instance.dataset_of_movies:
            if name1 is None and name2 is None and name3 is None:
                return render_template(
                    'search_movie/lost.html',
                    title='genres',
                    redirect_url=url_for('search_bp.search_by_genre'))
            if name1 in movie.genres and name2 in movie.genres and name3 in movie.genres:
                movie_list.append(movie)

    if title == 'Actor':
        try:
            name1 = Actor(name1.strip().strip('<').strip('>'))
        except:
            pass
        try:
            name2 = Actor(name2.strip().strip('<').strip('>'))
        except:
            pass
        try:
            name3 = Actor(name3.strip().strip('<').strip('>'))
        except:
            pass

        for movie in repo.repo_instance.dataset_of_movies:
            if name1 is None and name2 is None and name3 is None:
                return render_template(
                    'search_movie/lost.html',
                    title='actors',
                    redirect_url=url_for('search_bp.search_by_actor'))
            if name1 in movie.actors and name2 in movie.actors and name3 in movie.actors:
                movie_list.append(movie)

    if title == 'Review':
        movie_list.append(repo.repo_instance.get_movie(movie_title))

    if title == 'Director':
        try:
            name1 = Director(name1.strip().strip('<').strip('>'))
        except:
            pass
        for movie in repo.repo_instance.dataset_of_movies:
            if movie.director == name1:
                movie_list.append(movie)

    per_page = 6
    cursor = request.args.get('cursor')
    if cursor is None:
        cursor = 0
    else:
        cursor = int(cursor)

    movie_ids = []
    for i in range(cursor, cursor + per_page):
        movie_ids += [i]
    movies = []
    for id in movie_ids:
        try:
            movies += [movie_list[id]]
        except:
            pass
    first_movie_url = None
    last_movie_url = None
    prev_movie_url = None
    next_movie_url = None
    if cursor > 0:
        prev_movie_url = url_for('movies_bp.display_movies',
                                 cursor=cursor - per_page,
                                 title=title,
                                 name1=name1,
                                 name2=name2,
                                 name3=name3)
        first_movie_url = url_for('movies_bp.display_movies',
                                  movie_list=movie_list,
                                  title=title,
                                  name1=name1,
                                  name2=name2,
                                  name3=name3)

    if cursor + per_page < len(movie_list):
        next_movie_url = url_for('movies_bp.display_movies',
                                 cursor=cursor + per_page,
                                 title=title,
                                 name1=name1,
                                 name2=name2,
                                 name3=name3)

        last_cursor = per_page * int(len(movie_list) / per_page)
        if len(movie_list) % per_page == 0:
            last_cursor -= per_page
        last_movie_url = url_for('movies_bp.display_movies',
                                 cursor=last_cursor,
                                 title=title,
                                 name1=name1,
                                 name2=name2,
                                 name3=name3)

    for movie in movie_list:
        movie.add_comment_url = url_for('search_bp.comment_on_movie',
                                        title=movie.title)
        for actor in movie.actors:
            actor.add_comment_url = url_for('search_bp.comment_on_actor',
                                            title=actor.actor_full_name)
        for genre in movie.genres:
            genre.add_comment_url = url_for('search_bp.comment_on_genre',
                                            title=genre.genre_name)
        movie.director.add_comment_url = url_for(
            'search_bp.comment_on_director',
            title=movie.director.director_full_name)
    return render_template('movies/display_movies.html',
                           title=title,
                           movies=movies,
                           space1=name1,
                           space2=name2,
                           space3=name3,
                           first_movie_url=first_movie_url,
                           last_movie_url=last_movie_url,
                           prev_movie_url=prev_movie_url,
                           next_movie_url=next_movie_url)