Exemplo n.º 1
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)

            for row in movie_file_reader:

                movie_class = Movie(row['Title'], int(row['Year']))
                if movie_class not in self.dataset_of_movies:
                    movie_class.id = int(row['Rank'])
                    director = Director(row['Director'])
                    movie_class.director = director
                    movie_class.description = row['Description']
                    for actor in row['Actors'].split(","):
                        actor_movie = Actor(actor)
                        movie_class.add_actor(actor_movie)
                    for genre in row['Genre'].split(","):
                        genre_movie = Genre(genre)
                        movie_class.add_genre(genre_movie)
                    movie_class.runtime_minutes = int(row['Runtime (Minutes)'])
                    self.dataset_of_movies.append(movie_class)

                for actor in row['Actors'].split(","):
                    actor_class = Actor(actor)
                    if actor_class not in self.dataset_of_actors:
                        self.dataset_of_actors.add(actor_class)

                director_class = Director(row['Director'])
                if director_class not in self.dataset_of_directors:
                    self.dataset_of_directors.add(director_class)

                for genre in row['Genre'].split(","):
                    genre_class = Genre(genre)
                    if genre_class not in self.dataset_of_genres:
                        self.dataset_of_genres.add(genre_class)
Exemplo n.º 2
0
def test_domain_init():
    movie = Movie("Moana", 2018)
    movie.director = Director("Hans Zimmerman")
    movie.id = 4
    movie.description = "hello world"
    assert movie.actors == []
    actor1 = Actor("Jennifer Lawrence")
    actor2 = Actor("James McAvoy")
    movie.add_actor(actor1)
    movie.add_actor(actor2)
    assert movie.actors == [actor1, actor2]
    assert movie.genres == []
    genre1 = Genre('Comedy')
    genre2 = Genre('Romance')
    movie.add_genre(genre1)
    movie.add_genre(genre2)
    assert movie.genres == [genre1, genre2]