Exemple #1
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
Exemple #2
0
def get_movies_for_actors(actors, repo):
    """
    """
    movies = set()
    to_remove = []
    for actor in actors:
        actor_obj = Actor(actor)
        for movie in repo.get_movies_by_actor(actor_obj):
            movies.add(movie)

    for actor in actors:
        actor_obj = Actor(actor)
        for movie in movies:
            if actor_obj not in movie.actors:
                to_remove.append(movie)
    for item in to_remove:
        if item in movies:
            movies.remove(item)
    return [utils.movie_to_dict(movie) for movie in movies]
Exemple #3
0
def load_actors(actors: str):
    """
    """
    names = actors.split(',')
    movie_actors = []
    for name in names:
        temp_actor = Actor(name)
        if temp_actor not in movie_actors:
            movie_actors.append(temp_actor)
        if temp_actor not in actors:
            actors.add(temp_actor)
    return movie_actors
Exemple #4
0
 def test_remove_actor(self, movie):
     movie.add_actor(Actor('Tom'))
     movie.add_actor(Actor('Jimmy'))
     movie.remove_actor(Actor('Tom'))
     assert movie.actors == [Actor('Jimmy')]
     movie.remove_actor(Actor("Tom Brittenden"))
     assert movie.actors == [Actor('Jimmy')]
    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)
Exemple #7
0
 def actor1(self):
     """
     """
     actor = Actor("Lindsay Lohan")
     return actor
Exemple #8
0
 def test_eq(self, actor1, actor2):
     assert actor1 != actor2
     assert actor1 == Actor("Lindsay Lohan")
Exemple #9
0
 def actor3(self):
     """
     """
     actor = Actor("")
     return actor
Exemple #10
0
 def actor2(self):
     """
     """
     actor = Actor("Brad Pitt")
     return actor
Exemple #11
0
def test_repo_wont_add_invalid_actor(in_memory_repo):
    with pytest.raises(RepositoryException):
        in_memory_repo.add_actor(Actor(1))
Exemple #12
0
def test_repo_can_add_actor(in_memory_repo):
    actor = Actor('Tom')
    in_memory_repo.add_actor(actor)
    assert in_memory_repo.get_actor('Tom') == actor
Exemple #13
0
 def test_add_actor(self, movie):
     movie.add_actor(Actor('Tom'))
Exemple #14
0
 def test_actors(self, movie):
     movie.add_actor(Actor("Tom"))
     assert movie.actors == [Actor("Tom")]