def test_remove_movie_which_is_not_in_watchlist():
    movie1 = Movie("Moana", 2016)
    movie2 = Movie("Mulan", 2020)
    watchlist1 = WatchList()
    watchlist1.add_movie(movie1)
    watchlist1.remove_movie(movie2)
    assert watchlist1.size() == 1
示例#2
0
def test():
    watchlist = WatchList()
    assert watchlist.size() == 0
    watchlist.add_movie(Movie("Up", 2009))
    assert watchlist.size() == 1
    watchlist.add_movie(Movie("Down", 1999))
    assert watchlist.size() == 2
    watchlist.add_movie(Movie("XYZ", 2013))
    assert watchlist.size() == 3
    watchlist.add_movie(Movie("Anabelle", 2020))
    assert watchlist.size() == 4
    watchlist.add_movie(Movie("Anabelle", 2020))
    assert watchlist.size() == 4

    i = iter(watchlist)
    repr(next(i)) == "<Movie Up, 2009>"
    repr(next(i)) == "<Movie Down, 1999>"
    repr(next(i)) == "<Movie XYZ, 2013>"
    repr(next(i)) == "<Movie Anabelle, 2020>"
    with pytest.raises(StopIteration):
        next(i)

    watchlist.remove_movie(Movie("Up", 2009))
    assert watchlist.size() == 3
    watchlist.remove_movie(Movie("Left", 2009))
    assert watchlist.size() == 3
    assert repr(watchlist.select_movie_to_watch(0)) == "<Movie Down, 1999>"
    assert watchlist.select_movie_to_watch(4) == None
    assert repr(watchlist.first_movie_in_watchlist()) == "<Movie Down, 1999>"
    watchlist.remove_movie(Movie("Down", 1999))
    watchlist.remove_movie(Movie("XYZ", 2013))
    watchlist.remove_movie(Movie("Anabelle", 2020))
    assert watchlist.first_movie_in_watchlist() == None
示例#3
0
def constructor_test():
    watchlist = WatchList()
    print(watchlist.size())
    watchlist.add_movie(Movie("Up", 2009))
    print(watchlist.size())
    watchlist.add_movie(Movie("Down", 1999))
    print(watchlist.size())
    watchlist.add_movie(Movie("XYZ", 2013))
    print(watchlist.size())
    watchlist.add_movie(Movie("Anabelle", 2020))
    print(watchlist.size())
    watchlist.add_movie(Movie("Anabelle", 2020))
    print(watchlist.size())

    i = iter(watchlist)
    print(next(i))
    print(next(i))
    print(next(i))

    for movie in i:
        print(movie)

    watchlist.remove_movie(Movie("Up", 2009))
    print(watchlist.size())
    watchlist.remove_movie(Movie("Left", 2009))
    print(watchlist.size())
    print(watchlist.select_movie_to_watch(0))
    print(watchlist.select_movie_to_watch(4))
    print(watchlist.first_movie_in_watchlist())
    watchlist.remove_movie(Movie("Down", 1999))
    watchlist.remove_movie(Movie("XYZ", 2013))
    watchlist.remove_movie(Movie("Anabelle", 2020))
    print(watchlist.first_movie_in_watchlist())
示例#4
0
 def test_watchlist_remove_movie_not_in_watchlist(self):
     watchlist = WatchList()
     watchlist.add_movie(Movie("Moana", 2016))
     watchlist.add_movie(Movie("Ice Age", 2002))
     watchlist.remove_movie(Movie("Guardians of the Galaxy", 2012))
     watchlist_iter = iter(watchlist)
     print(next(watchlist_iter))
     print(next(watchlist_iter))
示例#5
0
 def test_watchlist_remove(self):
     watchlist = WatchList()
     watchlist.add_movie(Movie("Moana", 2016))
     watchlist.add_movie(Movie("Ice Age", 2002))
     watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
     watchlist.remove_movie(Movie("Moana", 2016))
     print(watchlist.first_movie_in_watchlist())
     assert watchlist.first_movie_in_watchlist() == Movie("Ice Age", 2002)
def test_remove_movie():
    w = WatchList()
    w.add_movie(movie)
    assert w.size() == 1
    w.remove_movie(movie2)
    assert w.size() == 1
    w.remove_movie(movie)
    assert w.size() == 0
示例#7
0
def test_remove_movie_not_in_list():
    watchlist = WatchList()
    assert (f"Size of watchlist: {watchlist.size()}") == f"Size of watchlist: 0"
    watchlist.add_movie(Movie("Moana", 2016))
    watchlist.add_movie(Movie("Ice Age", 2002))
    assert str(watchlist.first_movie_in_watchlist()) == '<Movie Moana, 2016>'
    watchlist.remove_movie(Movie("Rogue One", 2016))
    assert (f"Size of watchlist: {watchlist.size()}") == f"Size of watchlist: 2"
    assert str(watchlist.first_movie_in_watchlist()) == '<Movie Moana, 2016>'
 def test_watchlist_3(self):
     watchlist = WatchList()
     watchlist.add_movie(Movie("Moana", 2016))
     watchlist.add_movie(Movie("Ice Age", 2002))
     watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
     watchlist.remove_movie(Movie("Moana", 2016))
     watchlist.remove_movie(Movie("Ice Age", 2002))
     assert repr(
         watchlist) == "<WatchList [<Movie Guardians of the Galaxy, 2012>]>"
示例#9
0
 def test_init_5(self):
     watchlist_1 = WatchList()
     movie1 = Movie("Moana", 2016)
     movie2 = Movie("Harry Potter", 2010)
     movie3 = Movie("Harry Potter", 2012)
     watchlist_1.add_movie(movie1)
     watchlist_1.add_movie(movie2)
     watchlist_1.remove_movie(movie3)
     assert watchlist_1.size() == 2
示例#10
0
 def test_remove_movies(self):
     watchlist = WatchList()
     watchlist.add_movie(Movie("Moana", 2016))
     watchlist.add_movie(Movie("Ice Age", 2002))
     watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
     watchlist.remove_movie(Movie("Moana", 2016))
     assert watchlist.size == 2
     watchlist.remove_movie(Movie("Transformers", 2007))
     assert watchlist.size == 2
示例#11
0
 def test_remove_movie(self):
     watchlist = WatchList()
     movie1 = Movie("Star Wars", 1999)
     watchlist.add_movie(movie1)
     assert watchlist.size() == 1
     watchlist.remove_movie(movie1)
     assert watchlist.size() == 0 # tests it removes a movie if it is there
     watchlist.remove_movie(movie1)
     assert watchlist.size() == 0 # tests it does nothing if movie not there
示例#12
0
    def test_remove_movie(self):
        movie1 = Movie("Moana", 2016)
        movie2 = Movie("Ice Age", 2002)
        movie3 = Movie("Wall-E", 2008)

        watchlist = WatchList()
        watchlist.add_movie(movie1)
        watchlist.add_movie(movie2)
        watchlist.add_movie(movie3)

        watchlist.remove_movie(movie1)
        assert watchlist.watchlist == [movie2, movie3]
        assert watchlist.size() == 2
示例#13
0
def test_adding_and_removing():
    watchlist = WatchList()
    movie1 = Movie("Moana", 2016)
    movie2 = Movie("Booksmart", 2019)
    movie3 = Movie("School of Rock", 2003)
    movie4 = Movie("Roma", 2018)
    watchlist.add_movie(movie1)
    watchlist.add_movie(movie2)
    watchlist.add_movie(movie3)
    watchlist.add_movie(movie4)
    watchlist.add_movie(movie4)
    assert watchlist.size() == 4
    watchlist.remove_movie(movie1)
    assert watchlist.size() == 3
    watchlist.remove_movie(Movie("Juno", 2007))
    assert watchlist.size() == 3
示例#14
0
    def test_size(self): # this test is a bit silly since most the other tests rely on size working?
        watchlist = WatchList()
        assert watchlist.size() == 0
        watchlist.remove_movie(Movie("Star Wars", 1999))
        assert watchlist.size() == 0
        # ^ I believe this is a great test, checking that remove_movie
        # doesn't subtract 1 from size unless a movie is indeed removed

        watchlist.add_movie(Movie("Star Wars", 1999))
        assert watchlist.size() == 1
        watchlist.add_movie(Movie("Ice Age", 2002))
        assert watchlist.size() == 2
        watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
        assert watchlist.size() == 3
        watchlist.remove_movie(Movie("Star Wars", 1999))
        # ^ as per note above note, __eq___ is defined by same title and year, so this should do the job of removing
        assert watchlist.size() == 2 # test size reacts to movies being removed
示例#15
0
def test_watchlist():
    watchlist = WatchList()

    movies = [
        Movie("Moana", 2016),
        Movie("The Lion King", 1994),
        Movie("Guardians of the Galaxy", 2016),
        Movie("Prometheus", 2012),
        Movie("La La Land", 2016)
    ]

    for movie in movies:
        watchlist.add_movie(movie)

    assert watchlist.size() == 5
    assert watchlist.first_movie_in_watchlist() == movies[0]
    assert watchlist.select_movie_to_watch(2) == movies[2]
    assert watchlist.select_movie_to_watch(7) is None

    movies2 = []

    for movie in watchlist:
        movies2.append(movie)

    assert movies == movies2

    watchlist.remove_movie(movies[3])

    assert watchlist.size() == 4

    watchlist.add_movie(movies[1])

    assert watchlist.size() == 4

    watchlist_iter = iter(watchlist)
    assert next(watchlist_iter) == movies[0]
    assert next(watchlist_iter) == movies[1]
    assert next(watchlist_iter) == movies[2]
    assert next(watchlist_iter) == movies[4]

    with pytest.raises(StopIteration):
        next(watchlist_iter)
示例#16
0
class User:
    def __init__(self, user_name: str, password: str) -> None:
        self._user_name = user_name
        self._password = password
        self._watched_movies: List[Movie] = []
        self._reviews: List[Review] = []
        self._time_spent_watching_movies_minutes: int = 0
        self._watchlist = WatchList()

    @property
    def _user_name(self):
        return self.__user_name

    @_user_name.setter
    def _user_name(self, user_name):
        if user_name == "" or not isinstance(user_name, str):
            self.__user_name = None
        else:
            self.__user_name = user_name.strip().lower()

    @property
    def _password(self):
        return self.__password

    @_password.setter
    def _password(self, password):
        if not isinstance(password, str):
            raise TypeError(f"'password' must be of type 'str' but was '{type(password).__name__}'")
        self.__password = password

    @property
    def user_name(self):
        return self._user_name

    @property
    def password(self):
        return self.__password

    @property
    def watched_movies(self):
        return self._watched_movies

    @property
    def reviews(self):
        return self._reviews

    @property
    def time_spent_watching_movies_minutes(self):
        return self._time_spent_watching_movies_minutes

    @property
    def watchlist(self):
        return self._watchlist

    def __repr__(self) -> str:
        return f'<{type(self).__name__} {self._user_name}>'

    def __eq__(self, other) -> bool:
        if not isinstance(other, User):
            return False
        return self._user_name == other._user_name and self._password == other._password

    def __lt__(self, other) -> bool:
        if not isinstance(other, User):
            raise TypeError(
                f"'<' not supported between instances of '{type(self).__name__}' and '{type(other).__name__}'")
        return self._user_name < other._user_name

    def __hash__(self) -> int:
        return hash(self._user_name)

    def watch_movie(self, movie: Movie) -> None:
        """
        Adds the given movie to this user's list of watched movies, updates time_spent_watching_movies_minutes, and
        removes the movie from this user's WatchList (if it's in their WatchList).
        """
        if not isinstance(movie, Movie):
            raise TypeError(f"'movie' must be of type 'Movie' but was '{type(movie).__name__}'")

        if movie in self._watched_movies:
            return

        self._watched_movies.append(movie)
        self._watchlist.remove_movie(movie)

        if isinstance(movie.runtime_minutes, int) and movie.runtime_minutes > 0:
            self._time_spent_watching_movies_minutes += movie.runtime_minutes

    def add_review(self, review: Review) -> None:
        """ Adds the given review to the list of reviews written by this user. """
        if not isinstance(review, Review):
            raise TypeError(f"'review' must be of type 'Review' but was '{type(review).__name__}'")

        if review in self._reviews:
            return

        self._reviews.append(review)

    def add_to_watchlist(self, movie: Movie) -> None:
        """ Adds the given movie to this user's WatchList. Does nothing if the user has already watched the given movie.
        """
        if not isinstance(movie, Movie):
            raise TypeError(f"'movie' must be of type 'Movie' but was '{type(movie).__name__}'")

        if movie in self._watched_movies:
            return

        self._watchlist.add_movie(movie)

    def remove_from_watchlist(self, movie: Movie) -> None:
        """ Removes the given movie from this user's WatchList. """
        if not isinstance(movie, Movie):
            raise TypeError(f"'movie' must be of type 'Movie' but was '{type(movie).__name__}'")

        self._watchlist.remove_movie(movie)

    def watchlist_size(self) -> int:
        """ Returns the number of movies in this user's WatchList. """
        return self._watchlist.size()
def test_remove_movie_which_is_not_in_watchlist():
    watchlist = WatchList()
    watchlist.add_movie(Movie("a", 2012))
    watchlist.remove_movie(Movie("b", 2010))
    assert f"Size of watchlist: {watchlist.size()}" == "Size of watchlist: 1"
示例#18
0
class User:
    def __init__(self, user_name: str, password: str):
        self.__user_name = user_name.strip().lower()
        self.__password = password
        self.__watched_movies = list()
        self.__reviews = list()
        self.__time_spent_watching_movies_minutes = 0
        self.__watchlist = WatchList()

    @property
    def user_name(self):
        return self.__user_name

    @property
    def password(self):
        return self.__password

    @property
    def watched_movies(self):
        return self.__watched_movies

    @property
    def reviews(self):
        return self.__reviews

    @property
    def time_spent_watching_movies_minutes(self):
        return self.__time_spent_watching_movies_minutes

    @property
    def watchlist(self):
        return self.__watchlist

    def __repr__(self):
        return f"<User {self.__user_name}>"

    def __eq__(self, other):
        return self.__user_name == other.user_name

    def __lt__(self, other):
        return self.__user_name < other.user_name

    def __hash__(self):
        return hash(repr(self))

    def add_movie_to_watchlist(self, movie: Movie):
        self.__watchlist.add_movie(movie)

    def watch_movie(self, movie: Movie):
        if movie not in self.__watched_movies:
            self.__watched_movies.append(movie)
        self.__time_spent_watching_movies_minutes += movie.runtime_minutes
        self.__watchlist.remove_movie(movie)

    def add_unwatched_movies_with_actor_to_watchlist(self, actor: Actor,
                                                     movies):
        for movie in movies:
            if actor in movie.actors and movie not in self.__watched_movies:
                self.__watchlist.add_movie(movie)

    def add_unwatched_movies_by_director_to_watchlist(self, director: Director,
                                                      movies):
        for movie in movies:
            if director == movie.director and movie not in self.__watched_movies:
                self.__watchlist.add_movie(movie)

    def add_review(self, review: Review):
        self.__reviews.append(review)
示例#19
0
def test_remove_movie_not_in_list():
    watchlist = WatchList()
    watchlist.remove_movie(Movie("Your name", 2006))
    assert watchlist.size() == 0
class MovieWatchingSimulation:
    def __init__(self, user: User):
        if type(user) == User:
            self.__user = user
        else:
            self.__user = None
        self.__watch_list = WatchList()
        self.__now_playing = None
        self.__next_playing = None
        self.__play_pointer = 0
        self.__review = list()

    @property
    def user(self):
        return self.__user

    @property
    def watch_list(self):
        return self.__watch_list

    @property
    def now_playing(self):
        return self.__now_playing

    @property
    def next_playing(self):
        return self.__next_playing

    @property
    def review(self):
        return self.__review

    def add_movie_to_playlist(self, movie: Movie):
        if movie not in self.__watch_list and type(movie) == Movie:
            if self.__watch_list.size() == 0:
                self.__watch_list.add_movie(movie)
                self.__now_playing = movie
                self.__play_pointer = 0
            else:
                if self.__watch_list.size() == 1:
                    self.__next_playing = movie
                    self.__watch_list.add_movie(movie)
                else:
                    self.__watch_list.add_movie(movie)

    def remove_movie_from_play_list(self, movie: Movie):
        if movie == self.__now_playing:
            self.__now_playing = self.__next_playing
            self.__watch_list.remove_movie(movie)
            self.__next_playing = self.__watch_list.select_movie_to_watch(
                self.__play_pointer + 1)
        elif movie == self.__next_playing:
            self.__watch_list.remove_movie(movie)
            self.__next_playing = self.__watch_list.select_movie_to_watch(
                self.__play_pointer + 1)
        else:
            self.__watch_list.remove_movie(movie)

    def play_next_movie(self):
        if self.__play_pointer + 1 < self.__watch_list.size():
            self.__play_pointer += 1
            self.__now_playing = self.__watch_list.select_movie_to_watch(
                self.__play_pointer)

            if self.__play_pointer + 1 < self.__watch_list.size():
                self.__next_playing = self.__watch_list.select_movie_to_watch(
                    self.__play_pointer + 1)
            else:
                self.__next_playing = None

        else:
            self.__now_playing = None
            self.__play_pointer += 1

    def play_previous_movie(self):
        if self.__play_pointer == self.__watch_list.size():
            self.__play_pointer -= 1
            self.__now_playing = self.__watch_list.select_movie_to_watch(
                self.__play_pointer)
        elif self.__play_pointer - 1 >= 0:
            self.__play_pointer -= 1
            self.__now_playing = self.__watch_list.select_movie_to_watch(
                self.__play_pointer)
            self.__next_playing = self.__watch_list.select_movie_to_watch(
                self.__play_pointer + 1)
        else:
            pass

    def review_to_current_playing_movie(self):

        # Simulate user input for test only. Request input later on.
        review = Review(self.__now_playing, "Good Movie, I like it.", 10)
        self.__review.append(review)

    def search_movie_from_playlist_to_watch(self, movie: Movie):
        i = 0
        for m in self.__watch_list:
            if movie == m:
                self.__now_playing = movie
                self.__play_pointer = i
                self.__next_playing = self.__watch_list.select_movie_to_watch(
                    i + 1)
                break
            i += 1
def test_add_and_remove_movie():
    watchlist6 = WatchList()
    watchlist6.add_movie(Movie("Moana", 2016))
    watchlist6.remove_movie(Movie("Moana", 2016))
    assert watchlist6.watch_list == []
    assert watchlist6.size() == 0
def test_remove_movie():
    watchlist5 = WatchList()
    watchlist5.add_movie(Movie("Moana", 2016))
    watchlist5.remove_movie(Movie("Transformers", 2007))
    assert watchlist5.size() == 1
    assert repr(watchlist5.first_movie_in_watchlist()) == "<Movie Moana, 2016>"