Exemple #1
0
    def read_csv_file(self, file_name):
        with open(file_name, mode='r', encoding='utf-8-sig') as csvfile:
            movie_file_reader = csv.DictReader(csvfile)

            for row in movie_file_reader:
                id = int(row['Rank'])
                title = row['Title']
                release_year = int(row['Year'])
                movie = Movie(title, release_year, id)
                self.add_movie(movie)
                actors = row["Actors"]
                actors = actors.split(",")
                for actor in actors:
                    actor = Actor(actor)
                    self.add_actor(actor)
                    actor = self.get_actor(actor.actor_full_name)
                    movie.add_actor(actor)
                    actor.add_movie(movie)

                director = Director(row["Director"])
                self.add_director(director)
                director = self.get_director(director.director_full_name)
                movie.director = director
                director.add_movie(movie)

                genres = row["Genre"]
                genres = genres.split(",")
                for genre in genres:
                    genre = Genre(genre)
                    movie.add_genre(genre)
                    self.add_genre(genre)

                movie.description = row["Description"]
                movie.runtime_minutes = int(row["Runtime (Minutes)"])
def test_init():
    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
def test_equal():
    director1 = Director("Taika Waititi")
    director2 = Director("Peter Jackson")
    director3 = Director("Taika Waititi")

    assert (director1 == director2) == False
    assert (director1 == director3) == True
    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"])
                movie = Movie(title, release_year)

                movie.description = row["Description"]

                director = row["Director"]
                movie.add_director(Director(director))
                if Director(director) not in self.__dataset_of_directors:
                    self.__dataset_of_directors.append(Director(director))

                actors = row["Actors"].split(",")
                for actor in actors:
                    movie.add_actor(Actor(actor))
                    if Actor(actor) not in self.__dataset_of_actors:
                        self.__dataset_of_actors.append(Actor(actor))

                genres = row["Genre"].split(",")
                for genre in genres:
                    movie.add_genre(Genre(genre))
                    if Genre(genre) not in self.__dataset_of_genres:
                        self.__dataset_of_genres.append(Genre(genre))

                movie.runtime_minutes = int(row["Runtime (Minutes)"])

                try:
                    movie.external_rating = float(row["Rating"])
                except ValueError:
                    pass

                try:
                    movie.rating_votes = int(row["Votes"])
                except ValueError:
                    pass

                try:
                    movie.revenue_in_millions = float(
                        row["Revenue (Millions)"])
                except ValueError:
                    pass

                try:
                    movie.metascore = int(row["Metascore"])
                except ValueError:
                    pass

                self.__dataset_of_movies.append(movie)
                # title = row['Title']
                # release_year = int(row['Year'])
                # print(f"Movie {index} with title: {title}, release year {release_year}")
                index += 1
Exemple #5
0
def test_director_construction():
    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

    for movie in director1.movies:
        assert False
def test_director():
    movie = Movie("Moana", 2016)
    director = Director("Ron Clements")
    movie.director = director
    assert repr(movie.director) == "<Director Ron Clements>"

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

    movie.director = Director("fake imposter director")
    assert repr(movie.director) == "<Director Ron Clements>"
def test_init():
    movie = Movie("Moana", 2016)
    assert repr(movie) == "<Movie Moana, 2016>"

    assert movie.title == "Moana"

    movie1 = Movie("", "1")
    assert repr(movie1) == "<Movie None, None>"

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

    movie.description = "Moana, daughter of chief Tui, embarks on a journey to return the heart of goddess Te Fitti from Maui, a demigod, after the plants and the fish on her island start dying due to a blight."
    assert movie.description == "Moana, daughter of chief Tui, embarks on a journey to return the heart of goddess Te Fitti from Maui, a demigod, after the plants and the fish on her island start dying due to a blight."

    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 repr(movie.runtime_minutes) == "107"
Exemple #8
0
def test_repository_can_add_a_director(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    director = Director("Fred")

    repo.add_director(director)

    assert director in repo.get_directors()
Exemple #9
0
def browse_by_director():
    directorMovies = movieByDirector()
    random_movies = repo.repo_instance.get_random_movies(4)
    random_directors = repo.repo_instance.get_random_directors(9)

    if directorMovies.validate_on_submit():
        post_director = Director(directorMovies.director_name.data)
        movies = repo.repo_instance.get_movies_directed_by(post_director)

        if movies != []:
            return render_template(
                'movies/directors_movies.html',
                movies = movies,
                director = post_director,
                movieSearch = movieByTitle(),
            )
        else:
            return render_template(
                'movies/directors_movies.html',
                movies = movies,
                director = None,
                movieSearch = movieByTitle(),
            )
    
    return render_template(
        'movies/get_director.html',
        form = directorMovies,
        random_movies = random_movies,
        random_directors = random_directors,
        movieSearch = movieByTitle(),
        directorSearch = directorMovies,
    )
Exemple #10
0
def test_repository_does_not_add_a_review_without_a_user(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    movie = Movie("Asdsa", 2014)
    movie.description = "Sam is sam he is"
    movie.director = Director('James')
    movie.runtime_minutes = 140
    repo.add_movie(movie)
    review = Review(None, movie, "Wow", 8, datetime.today())
    with pytest.raises(RepositoryException):
        repo.add_review(review)
def test_movie_director():
    # correct input
    movie1 = Movie("Moana", 2016)
    director1 = Director("Ron Clements")
    movie1.director = director1
    assert movie1.director == director1

    # incorrect input
    movie2 = Movie("Frozen", 2014)
    movie2.director = "Chris Buck"
    assert movie2.director is None
Exemple #12
0
def test_repository_can_add_a_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie1 = Movie("Sam I am", 2000)
    movie1.description = "Sam is sam he is"
    movie1.director = Director('James')
    movie1.runtime_minutes = 140
    repo.add_movie(movie1)
    movie = repo.get_movie(1001)

    assert movie == Movie('Sam I am', 2000)
Exemple #13
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'])
                movie = Movie(title, release_year)

                movie.description = row['Description']

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

                for actor in row['Actors'].split(','):
                    movie.add_actor(Actor(actor))
                    if Actor(actor) not in self.dataset_of_actors:
                        self.dataset_of_actors.append(Actor(actor))

                for genre in row['Genre'].split(','):
                    movie.add_genre(Genre(genre))
                    if Genre(genre) not in self.dataset_of_genres:
                        self.dataset_of_genres.append(Genre(genre))

                movie.runtime_minutes = int(row['Runtime (Minutes)'])

                try:
                    movie.revenue = float(row['Revenue (Millions)'])
                except:
                    pass

                self.__dataset_of_movies.append(movie)
def test_movie_remove_actor():
    movie1 = Movie("Moana", 2016)
    movie1.add_actor(Actor("Dwayne Johnson"))

    # correct input
    movie1.remove_actor(Actor("Dwayne Johnson"))
    assert movie1.actors == []

    # incorrect input
    movie1.add_actor(Actor("Dwayne Johnson"))
    movie1.remove_actor(Director("Dwayne Johnson"))
    assert movie1.actors == [Actor("Dwayne Johnson")]

    # removing an actor not in list
    movie1.remove_actor(Actor("Rachel House"))
    assert movie1.actors == [Actor("Dwayne Johnson")]
Exemple #15
0
def test_repository_can_add_a_review(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    user = User('aidan', 'hi1234')
    movie = Movie("Asdsa", 2014)
    movie.description = "Sam is sam he is"
    movie.director = Director('James')
    movie.runtime_minutes = 140
    review = make_review("Wow good movie", user, movie, 9)

    repo.add_user(user)
    repo.add_movie(movie)
    repo.add_review(review)

    reviews = repo.get_reviews()
    assert len(reviews) == 1
    assert review in reviews
def test_movie_remove_genre():
    movie1 = Movie("Moana", 2016)
    movie1.add_genre(Genre("Animation"))

    # correct input
    movie1.remove_genre(Genre("Animation"))
    assert movie1.genres == []

    # incorrect input
    movie1.add_genre(Genre("Animation"))
    movie1.remove_genre(Director("Animation"))
    assert movie1.genres == [Genre("Animation")]

    # removing a genre not in list
    movie1.remove_genre(Genre("Comedy"))
    assert movie1.genres == [Genre("Animation")]
def test_movie_add_genre():
    # correct input
    movie1 = Movie("Moana", 2016)
    movie1.add_genre(Genre("Animation"))
    assert movie1.genres == [Genre("Animation")]

    # incorrect input
    movie1.add_actor(Director("Ron Clements"))
    assert movie1.genres == [Genre("Animation")]

    # adding a genre twice
    movie1.add_genre(Genre("Animation"))
    assert movie1.genres == [Genre("Animation")]

    # adding a second genre
    movie1.add_genre(Genre("Comedy"))
    assert movie1.genres == [Genre("Animation"), Genre("Comedy")]
def test_movie_add_actor():
    # correct input
    movie1 = Movie("Moana", 2016)
    movie1.add_actor(Actor("Dwayne Johnson"))
    assert movie1.actors == [Actor("Dwayne Johnson")]

    # incorrect input
    movie1.add_actor(Director("Ron Clements"))
    assert movie1.actors == [Actor("Dwayne Johnson")]

    # adding an actor twice
    movie1.add_actor(Actor("Dwayne Johnson"))
    assert movie1.actors == [Actor("Dwayne Johnson")]

    # adding a second actor
    movie1.add_actor(Actor("Rachel House"))
    assert movie1.actors == [Actor("Dwayne Johnson"), Actor("Rachel House")]
Exemple #19
0
def movie_to_dict(movie: Movie, repo: AbstractRepository):
    '''actors = movie.actors[0]
    for i in movie.actors[1:]:
        actors += ","
        actors += str(i)'''
    actors = movie.actors

    movie_detail = requests.get(
        f"http://omdbapi.com?t={movie.title}&apikey=47f211b2").text
    #print(movie_detail)
    try:
        img_link = movie_detail.split('","')[13].split('":"')[1]
    except:
        img_link = "static/movie.png"
    movie.image_hyperlink = img_link
    try:
        d = movie.director.director_full_name
        director = movie.director
    except:
        director = Director(movie.director)
    try:
        genres = movie.genres.split(',')
    except:
        genres = movie.genres

    movie_dict = {
        'rank': movie.rank,
        'date': movie.date,
        'title': movie.title,
        'first_para': movie.description,
        'hyperlink': movie.hyperlink,
        'image_hyperlink': movie.image_hyperlink,
        'comments': comments_to_dict(movie.comments),
        'genres': genres_to_dict(genres, repo),
        'rating': movie.rating,
        'votes': movie.votes,
        'metascore': movie.metascore,
        'director': director,
        'actors': actors,
        'runtime_minutes': movie.runtime_minutes,
        'revenue': movie.revenue
    }
    return movie_dict
Exemple #20
0
def test_repository_can_retrieve_directors(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    directors = repo.get_directors()
    assert len(directors) == 644
    assert Director("James Gunn") in directors
Exemple #21
0
def test_get_movies_directed_by(in_memory_repo):
    ron_clements_movies = in_memory_repo.get_movies_directed_by(
        Director("Ron Clements"))
    assert len(ron_clements_movies) == 1
    assert len(in_memory_repo.get_movies_directed_by(
        Director("fake director"))) == 0
Exemple #22
0
def load_movies_and_genres(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_key = int(data_row[0])
        movie_genres = data_row[2].lower().split(",")
        movie_directors = data_row[4].lower().split(",")
        movie_actors = data_row[5].lower().split(",")

        # Add any new genres; associate the current movie with genres.
        for genre in movie_genres:
            if genre not in genres.keys():
                genres[genre] = list()
            genres[genre].append(movie_key)
        for director in movie_directors:
            if director not in directors.keys():
                directors[director] = list()
            directors[director].append(movie_key)
        for actor in movie_actors:
            if actor not in actors.keys():
                actors[actor] = list()
            actors[actor].append(movie_key)

        # Create Movie object.
        movie = Movie(title=data_row[1].lower(),
                      year=int(data_row[6]),
                      movie_id=int(data_row[0]))
        movie.description = data_row[3]
        movie.runtime_minutes = int(data_row[7])
        movie.rating = float(data_row[8])
        movie.votes = float(data_row[9])
        if data_row[10] != 'N/A':
            movie.revenue = f"{data_row[10]}Millions"
        if data_row[11] != 'N/A':
            movie.metascore = data_row[11]

        # Add the Movie to the repository.
        repo.add_movie(movie)

    # Create Genre objects, associate them with Movies and add them to the repository.
    for genre_name in genres.keys():
        genre = Genre(genre_name)
        for movie_id in genres[genre_name]:
            movie = repo.get_movie(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(movie_id)
            make_director_association(movie, director)
        repo.add_director(director)

    for actor_name in actors.keys():
        actor = Actor(actor_name)
        for movie_id in actors[actor_name]:
            movie = repo.get_movie(movie_id)
            make_actor_association(movie, actor)
        repo.add_actor(actor)
def test_hash():
    director1 = Director("Taika Waititi")
    assert hash(director1) == hash("Taika Waititi")
    director2 = Director("Peter Jackson")
    assert hash(director2) == hash("Peter Jackson")
Exemple #24
0
def director():
    return Director("Chris Wedge")
Exemple #25
0
def director2():
    return Director("Michael Bay")
Exemple #26
0
def test_repository_can_add_a_director(in_memory_repo):
    director = Director("Fred")
    in_memory_repo.add_director(director)
    assert director in in_memory_repo.get_directors()
Exemple #27
0
def test_repository_can_retrieve_directors(in_memory_repo):
    directors = in_memory_repo.get_directors()
    assert len(directors) == 5
    assert Director("James Gunn") in directors
Exemple #28
0
def test_repository_add_director(in_memory_repo):
    director = Director("Cames Jameron")
    in_memory_repo.add_director(director)

    assert director in in_memory_repo.get_directors()
def make_director():
    director = Director("Henry Selick")
    return director
Exemple #30
0
def test_add_and_get_director(in_memory_repo):
    in_memory_repo.add_director(Director("new director"))
    assert Director("new director") in in_memory_repo.get_directors()

    assert Director("fake director") not in in_memory_repo.get_directors()