def test_repository_get_n_movies(memory_repo):
    movie_1 = Movie("Movie1", 2000)
    movie_2 = Movie("Movie2", 2001)
    movies = memory_repo.get_n_movies(2, 0)
    assert len(movies) == 2
    assert movie_1 in movies
    assert movie_2 in movies
Ejemplo n.º 2
0
def test_get_movie_by_genre(memory_repo):
    movie = Movie('Test Movie', 2020)
    movie.add_genre(Genre('Genre1'))
    movie.add_genre(Genre('Genre2'))
    memory_repo.add_movie(movie)
    assert movie in memory_repo.get_movies_by_genre('Genre1')
    assert movie in memory_repo.get_movies_by_genre('Genre2')
Ejemplo n.º 3
0
def test_repository_can_add_movie(in_memory_repo):
    movie = Movie('Finding Potato', 2020)
    movie.rank = 6
    in_memory_repo.add_movie(movie)

    assert in_memory_repo.get_movie(6) is movie
    assert in_memory_repo.get_movie(6).rank == 6
Ejemplo n.º 4
0
def test_get_movie_by_actor(memory_repo):
    movie = Movie('Test Movie', 2020)
    movie.add_actor(Actor('Actor1'))
    movie.add_actor(Actor('Actor2'))
    memory_repo.add_movie(movie)
    assert movie in memory_repo.get_movies_by_actor('Actor1')
    assert movie in memory_repo.get_movies_by_actor('Actor2')
def test_repository_get_n_movies_with_offset(memory_repo):
    movie_3 = Movie("Movie3", 2002)
    movie_4 = Movie("Movie4", 2003)
    movies = memory_repo.get_n_movies(2, 2)
    assert len(movies) == 2
    assert movie_3 in movies
    assert movie_4 in movies
Ejemplo n.º 6
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 = Movie(row["Title"], int(row["Year"]))
                movie.rank = int(row["Rank"])
                movie.description = str(row["Description"])

                director = Director(row["Director"])
                actors = row["Actors"].split(",")
                genres = row["Genre"].split(",")

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

                if director not in self.__dataset_of_directors:
                    self.__dataset_of_directors.append(director)

                for i in actors:
                    actor = Actor(i)
                    if actor not in self.__dataset_of_actors:
                        self.__dataset_of_actors.append(actor)

                for i in genres:
                    genre = Genre(i)
                    if genre not in self.__dataset_of_genres:
                        self.__dataset_of_genres.append(genre)
Ejemplo n.º 7
0
    def read_csv_file(self):
        with open(self._data_path, mode='r', encoding='utf-8-sig') as f:
            records = csv.DictReader(f)
            for record in records:
                movie = Movie(record.get('Title'), int(record.get('Year', 0)))

                for actor in self._read_field(record, 'Actors', ','):
                    actor = Actor(actor)
                    movie.add_actor(actor)
                    self._dataset_of_actors.add(actor)

                for genre in self._read_field(record, 'Genre', ','):
                    genre = Genre(genre)
                    movie.add_genre(genre)
                    self._dataset_of_genres.add(genre)

                for director in self._read_field(record, 'Director', ','):
                    director = Director(director)
                    movie.set_director(director)
                    self._dataset_of_directors.add(director)

                movie.description = record.get('Description')
                movie.runtime_minutes = int(record.get('Runtime (Minutes)'))

                self._dataset_of_movies.add(movie)
Ejemplo n.º 8
0
def test_add_movie(watch_list):
    assert watch_list.size() == 0
    watch_list.add_movie(Movie("Moana", 2016))
    watch_list.add_movie(Movie("Ice Age", 2002))
    watch_list.add_movie(Movie("Guardians of the Galaxy", 2012))
    assert watch_list.size() == 3
    watch_list.add_movie(Movie("Ice Age", 2002))
    assert watch_list.size() == 3
Ejemplo n.º 9
0
def test_remove_movie(watch_list):
    watch_list.add_movie(Movie("Moana", 2016))
    watch_list.add_movie(Movie("Ice Age", 2002))
    watch_list.add_movie(Movie("Guardians of the Galaxy", 2012))
    watch_list.remove_movie(Movie("Moana", 2016))
    assert watch_list.size() == 2
    watch_list.remove_movie(Movie("Moana", 2017))
    assert watch_list.size() == 2
Ejemplo n.º 10
0
def test_set_director():
    movie1 = Movie("Moana", 2016)
    director = Director("Director")
    movie1.director = director
    assert movie1.director == director
    director_invalid = "Director"
    movie1.director = director_invalid
    assert movie1.director == director
Ejemplo n.º 11
0
def test_equal():
    movie1 = Movie("Moana", 2016)
    movie2 = Movie("Moana", 2016)
    movie3 = Movie("Moana", 2015)
    movie4 = Movie("Moana1", 2016)
    assert movie1 == movie2
    assert movie1 != movie3
    assert movie1 != movie4
Ejemplo n.º 12
0
def test_iteration(watch_list):
    watch_list.add_movie(Movie("Moana", 2016))
    watch_list.add_movie(Movie("Ice Age", 2002))
    watch_list.add_movie(Movie("Guardians of the Galaxy", 2012))
    res = []
    for movie in watch_list:
        res.append(movie)
    for i in range(len(res)):
        assert res[i] == watch_list.select_movie_to_watch(i)
Ejemplo n.º 13
0
def test_select_movie_to_watch(watch_list):
    watch_list.add_movie(Movie("Moana", 2016))
    watch_list.add_movie(Movie("Ice Age", 2002))
    watch_list.add_movie(Movie("Guardians of the Galaxy", 2012))
    movie_to_watch = watch_list.select_movie_to_watch(1)
    assert movie_to_watch == Movie("Ice Age", 2002)
    movie_to_watch = watch_list.select_movie_to_watch(-3)
    assert movie_to_watch == Movie("Moana", 2016)
    movie_to_watch = watch_list.select_movie_to_watch(3)
    assert movie_to_watch is None
Ejemplo n.º 14
0
def test_size(watch_list):
    assert watch_list.size() == 0
    watch_list.remove_movie(Movie("Moana", 2016))
    assert watch_list.size() == 0
    watch_list.add_movie(Movie("Moana", 2016))
    assert watch_list.size() == 1
    watch_list.remove_movie(Movie("Moana", 2017))
    assert watch_list.size() == 1
    watch_list.remove_movie(Movie("Moana", 2016))
    assert watch_list.size() == 0
Ejemplo n.º 15
0
def memory_repo():
    repo = memory_repository.MemoryRepository()
    movie_1 = Movie("Movie1", 2000)
    movie_2 = Movie("Movie2", 2001)
    movie_3 = Movie("Movie3", 2002)
    movie_4 = Movie("Movie4", 2003)
    movie_5 = Movie("Movie5", 2004)
    repo.add_movie(movie_1)
    repo.add_movie(movie_2)
    repo.add_movie(movie_3)
    repo.add_movie(movie_4)
    repo.add_movie(movie_5)
    return repo
Ejemplo n.º 16
0
def test_get_director():
    movie1 = Movie("Moana", 2016)
    assert movie1.director is None
def test_repository_get_first_movie(memory_repo):
    movie_1 = Movie("Movie1", 2000)
    assert memory_repo.get_first_movie() == movie_1
Ejemplo n.º 18
0
def test_set_runtime_minutes():
    movie1 = Movie("Moana", 2016)
    with pytest.raises(ValueError):
        movie1.runtime_minutes = 0
Ejemplo n.º 19
0
def test_get_runtime_minutes():
    movie1 = Movie("Moana", 2016)
    movie1.runtime_minutes = 100
    assert movie1.runtime_minutes == 100
Ejemplo n.º 20
0
def memory_repo():
    repo = memory_repository.MemoryRepository()
    movie_1 = Movie('Movie1', 2000)
    movie_2 = Movie('Movie2', 2001)
    movie_3 = Movie('Movie3', 2002)
    movie_4 = Movie('Movie4', 2003)
    movie_5 = Movie('Movie5', 2004)
    actor1 = Actor('Actor1')
    actor2 = Actor('Actor2')
    actor3 = Actor('Actor3')
    actor4 = Actor('Actor4')
    actor5 = Actor('Actor5')
    director1 = Director('Director1')
    director2 = Director('Director2')
    movie_1.add_actor(actor1)
    movie_1.add_actor(actor2)
    movie_1.add_actor(actor4)
    movie_1.add_actor(actor5)
    movie_2.add_actor(actor2)
    movie_2.add_actor(actor4)
    movie_2.add_actor(actor5)
    movie_3.add_actor(actor3)
    movie_3.add_actor(actor5)
    movie_4.add_actor(actor3)
    movie_4.add_actor(actor4)
    movie_4.add_actor(actor5)
    movie_5.add_actor(actor3)
    movie_5.add_actor(actor4)
    movie_5.add_actor(actor5)
    movie_1.director = director1
    movie_2.director = director1
    movie_3.director = director1
    movie_4.director = director2
    movie_5.director = director2
    genre1 = Genre('Genre1')
    genre2 = Genre('Genre2')
    movie_1.add_genre(genre1)
    movie_2.add_genre(genre2)
    movie_3.add_genre(genre1)
    movie_4.add_genre(genre2)
    movie_5.add_genre(genre1)
    repo.add_movie(movie_1)
    repo.add_movie(movie_2)
    repo.add_movie(movie_3)
    repo.add_movie(movie_4)
    repo.add_movie(movie_5)

    user = User(username='******', password='******')
    repo.add_user(user)
    return repo
Ejemplo n.º 21
0
def test_get_movie_by_id(memory_repo):
    movie = Movie('Test Movie', 2020)
    memory_repo.add_movie(movie)
    movie_id = movie.id
    assert memory_repo.get_movie_by_id(movie_id) is movie
def test_delete_not_exist_movie(memory_repo):
    movie_not_exist = Movie('Not Existing Movie', 9999)
    res = memory_repo.delete_movie(movie_not_exist)
    assert res is False
    assert memory_repo.get_total_number_of_movies() == 5
Ejemplo n.º 23
0
def dict_to_article(dict):
    movie = Movie(dict.title, dict.release_year)
    # Note there's no comments or tags.
    return movie
def test_delete_movie(memory_repo):
    movie_3 = Movie("Movie3", 2002)
    res = memory_repo.delete_movie(movie_3)
    assert res is True
    assert memory_repo.get_total_number_of_movies() == 4
Ejemplo n.º 25
0
def test_get_movie_by_director(memory_repo):
    movie = Movie('Test Movie', 2020)
    movie.director = Director('Director1')
    memory_repo.add_movie(movie)
    assert movie in memory_repo.get_movies_by_director('Director1')
def test_repository_can_add_movie(memory_repo):
    movie = Movie('Test Movie', 2020)
    memory_repo.add_movie(movie)
    assert memory_repo.get_movie('test movie', 2020) is movie
    assert memory_repo.get_total_number_of_movies() == 6
def test_repository_can_get_movie(memory_repo):
    movie = Movie('Test Movie', 2020)
    memory_repo.add_movie(movie)
    assert memory_repo.get_movie('test movie', 2020) is movie
Ejemplo n.º 28
0
def movie2():
    return Movie("Moana2", 2016)
Ejemplo n.º 29
0
def movie():
    return Movie("Moana1", 2016)
def test_repository_get_last_movie(memory_repo):
    movie_5 = Movie("Movie5", 2004)
    assert memory_repo.get_last_movie() == movie_5