def test_remove(): watchlist = WatchList() watchlist.remove_movie(Movie("Moana", 2016)) assert watchlist.size() == 0 watchlist.add_movie(Movie("Moana", 2016)) watchlist.remove_movie(Movie("Moana", 2016)) assert watchlist.size() == 0
def test_add(): watchlist = WatchList() watchlist.add_movie("hello world") assert watchlist.size() == 0 watchlist = WatchList() watchlist.add_movie(Movie("Moana", 2016)) assert watchlist.size() == 1
class MemoryRepository(AbstractRepository): def __init__(self): self._movies = WatchList() self._users = list() self._actors = list() self._directors = list() self._genres = list() self._reviews = list() self._i = iter(self._movies) def add_user(self, user: User): self._users.append(user) def get_user(self, username) -> User: user = None for u in self._users: if u.user_name == username: user = u return user def add_movie(self, movie: Movie): self._movies.add_movie(movie) def get_movie(self, index: int) -> Movie: return self._movies.select_movie_to_watch(index) def get_movie_by_page(self, page: int): return self._movies.select_movie_by_page(page) def get_page_of_previous_movie(self, movie: Movie): pre_page = movie.page - 1 if pre_page < 0: return 0 else: return pre_page def get_page_of_next_movie(self, movie: Movie): return (movie.page + 1) def get_number_of_movies(self): return self._movies.size() def get_first_movie(self) -> Movie: return self._movies.first_movie_in_watchlist() def get_last_movie(self) -> Movie: return self._movies.last_movie_in_watchlist() def get_next_movie(self): return next(self._i) def add_actor(self, actor: Actor): self._actors.append(actor) def get_actor(self) -> List[Actor]: return self._actors def add_director(self, director: Director): self._directors.append(director) def get_director(self) -> List[Director]: return self._directors def add_genre(self, genre: Genre): self._genres.append(genre) def get_genre(self) -> List[Genre]: return self._genres
def test_repeated_add(): watchlist = WatchList() watchlist.add_movie(Movie("Moana", 2016)) watchlist.add_movie(Movie("Moana", 2016)) assert watchlist.size() == 1