示例#1
0
 def test_init(self):
     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
     director4 = Director("Timothy Chalet")
     assert director1 < director4
示例#2
0
def load_directors(director: str):
    """
    """
    temp_director = Director(director)
    if temp_director not in directors:
        directors.add(temp_director)
    return temp_director
示例#3
0
def test_repo_can_add_movie(in_memory_repo):
    movie = Movie('Tom', 2001)
    movie.director = Director('Tom')
    movie.actors = [Actor('Tom')]
    movie.runtime_minutes = 20
    in_memory_repo.add_movie(movie)
    assert in_memory_repo.get_movie('Tom', 2001) == movie
示例#4
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:
                add_rank = row['Rank']
                add_title = row['Title']
                add_year = int(row['Year'])
                add_description = row['Description']
                add_actors = []
                add_genres = []
                add_director = ""

                actors_list = row['Actors'].split(",")
                for a in actors_list:
                    actor = a.strip()
                    add_actor = Actor(actor)
                    if add_actor not in self._dataset_of_actors:
                        self._dataset_of_actors.append(add_actor)
                    add_actors.append(add_actor)

                directors_list = row['Director'].split(",")
                for d in directors_list:
                    add_director = Director(d)
                    if add_director not in self._dataset_of_directors:
                        self._dataset_of_directors.append(add_director)
                    add_director = d

                genre_list = row['Genre'].split(",")
                for g in genre_list:
                    add_genre = Genre(g)
                    if add_genre not in self._dataset_of_genres:
                        self._dataset_of_genres.append(add_genre)
                    add_genres.append(add_genre)

                add_movie = Movie(add_title, add_year, add_rank,
                                  add_description, add_director, add_actors,
                                  add_genres)
                self._dataset_of_movies.append(add_movie)

                index += 1
    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'])
                description = row['Description']
                time = int(row['Runtime (Minutes)'])
                movie = Movie(title, release_year)

                actors1 = row['Actors'].split(",")
                actors2 = []
                for i in actors1:
                    actors2.append(Actor(i))

                director = Director(row['Director'])

                genres1 = row['Genre'].split(",")
                genres2 = []
                for i in genres1:
                    genres2.append(Genre(i))

                movie.director = director
                movie.description = description
                movie.actors = actors2
                movie.genres = genres2
                movie.runtime_minutes = time

                #Adding to datasets
                self.__dataset_of_movies.append(movie)

                for actor in actors2:
                    self.__dataset_of_actors.add(actor)

                self.__dataset_of_directors.add(director)

                for genre in genres2:
                    self.__dataset_of_genres.add(genre)
示例#6
0
def get_movies_for_director(director, repo):
    """
    """
    if director is None:
        return []
    return [utils.movie_to_dict(movie) for movie in repo.get_movies_by_director(Director(director))]
示例#7
0
def test_repo_wont_add_invalid_director(in_memory_repo):
    with pytest.raises(RepositoryException):
        in_memory_repo.add_director(Director(1))
示例#8
0
def test_repo_can_add_director(in_memory_repo):
    director = Director('Tom')
    in_memory_repo.add_director(director)
    assert in_memory_repo.get_director_by_name('Tom') == director
示例#9
0
 def test_director(self, movie):
     movie.director = Director("Taika")
     assert movie.director == Director("Taika")