def test_record_user_and_review_single():
    movie1 = Movie("Moana", 2016)
    movie1.runtime_minutes = 107
    user1 = User('Martin', 'pw12345')
    review_text1 = "This movie was very enjoyable."
    rating1 = 9
    cflix = MovieWatchingSimulation(movie1)
    cflix.record_user_and_review(user1, review_text1, rating1)
    assert len(cflix.reviews) == 1
    assert len(cflix.users) == 1
Beispiel #2
0
def test_add_review():
    user1 = User('Me', 'pw12345')
    movie2 = Movie("Star Wars", 1977)

    review = Review(
        movie2,
        "My car turned into the Millennium Falcon after showing the movie to it",
        10)
    user1.add_review(review)
    assert user1.reviews == [review]
Beispiel #3
0
 def test_remove_movie(self):
     watchlist = WatchList()
     movie = Movie("Moana", 2016)
     watchlist.add_movie(movie)
     watchlist.remove_movie("")
     assert len(watchlist.watchlist) == 1
     watchlist.remove_movie(movie)
     assert len(watchlist.watchlist) == 0
     watchlist.remove_movie(movie)
     assert len(watchlist.watchlist) == 0
 def test_watch_done(self):
     user1 = User("Martin", "12345")
     user2 = User("Vivian", "12345")
     the_movie = Movie("Moana", 2016)
     user1.add_watchList(the_movie)
     assert user1.watchList == [the_movie]
     user_list = [user1, user2]
     watchSimulation1 = MovieWatchingSimulation(user_list, the_movie)
     watchSimulation1.done_watching()
     assert len(user1.watchList) == 0
Beispiel #5
0
def test_review_ratings():
    movie = Movie("Moana", 2016)
    review = Review(movie, "was pretty good", -2)
    assert review.rating == None
    review = Review(movie, "was pretty good", 11)
    assert review.rating == None
    review = Review(movie, "was pretty good", 2)
    assert review.rating == 2
    review = Review(movie, "was pretty good", 0)
    assert review.rating == None
Beispiel #6
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)
    def test_import_watchlist(self):
        rank = Ranking()

        wl7 = WatchList()
        wl7.add_movie(Movie("Movie e", 2015))

        rank.import_watch_list(wl7)

        rank_dict = rank.ranking

        assert rank_dict["<Movie Movie e, 2015>"] == 1
 def test_end_session(self, watching_session):
     user1 = User("Aidan", "Wasx")
     user2 = User("Iona", "Mort")
     watching_session.add_friend(user1, user2)
     watching_session.end_session(user2)
     assert watching_session.size() == 2
     assert watching_session.watching == Movie("Cars", 2008)
     watching_session.end_session(user1)
     assert watching_session.size() == 1
     assert watching_session.users_in_session() == [user1]
     assert watching_session.watching is None
Beispiel #9
0
    def _read_row(self, row: _ROW) -> Movie:
        """
        Helper method to construct a Movie from a row.

        Raises:
            ValueError: unable to parse row: {row}
         """
        error = False

        try:
            title = row['Title']
            genres = [
                self._get_genre(Genre(name))
                for name in row['Genre'].split(',')
            ]
            description = row['Description']
            director = self._get_director(Director(row['Director']))
            actors = [
                self._get_actor(Actor(name))
                for name in row['Actors'].split(',')
            ]
            release_year = int(row['Year'])
            runtime_minutes = int(row['Runtime (Minutes)'])
            rating = float(row['Rating'])
            votes = int(row['Votes'])
            revenue_millions = float(
                row['Revenue (Millions)']
            ) if row['Revenue (Millions)'] != 'N/A' else None
            metascore = int(
                row['Metascore']) if row['Metascore'] != 'N/A' else None
        except KeyError:
            error = True
        except ValueError:
            error = True

        if error:
            raise ValueError(f'unable to parse row: {row}')

        movie = Movie(title, release_year)
        movie.genres = genres
        movie.description = description
        movie.director = director
        movie.actors = actors
        movie.runtime_minutes = runtime_minutes
        movie.rating = rating
        movie.votes = votes

        if revenue_millions:
            movie.revenue_millions = revenue_millions

        if metascore:
            movie.metascore = metascore

        return movie
Beispiel #10
0
    def test_longest_movie(self):
        movie1 = Movie("Moana", 2016)
        movie2 = Movie("Ice Age", 2002)
        movie3 = Movie("John Cena", 1999)
        movie4 = Movie("Bravo", 2000)
        movie5 = Movie("Charlie", 1987)

        movie1.runtime_minutes = 120
        movie2.runtime_minutes = 120
        movie3.runtime_minutes = 114
        movie4.runtime_minutes = 180
        movie5.runtime_minutes = 86

        lst = [movie1, movie2, movie3, movie4, movie5]
        film_comparison = movie_compare(lst)
        film_comparison.longest_movie()

        assert film_comparison.movies_lst == [
            movie4, movie2, movie1, movie3, movie5
        ]
Beispiel #11
0
def test_add_actor():
    movie1 = Movie("Spirited Away", 2000)

    movie1.actors = [Actor("James Huang")]
    movie1.add_actor(Actor("Jack Huang"))
    assert movie1.actors == [Actor("James Huang"), Actor("Jack Huang")]
    movie1.add_actor("Ron Huang")
    movie1.add_actor("")
    movie1.add_actor(None)
    movie1.add_actor(21345648)
    assert movie1.actors == [Actor("James Huang"), Actor("Jack Huang")]
Beispiel #12
0
def test_add_review(user):
    assert user.reviews == []
    mov = Movie("Up", 2009)
    review = Review(mov, "Nice", 6)
    user.add_review(review)
    assert user.reviews == [Review(mov, "Nice", 6)]
    user.add_review(4)
    assert user.reviews == [Review(mov, "Nice", 6)]
    review = Review(mov, "Okay", 4)
    user.add_review(review)
    assert user.reviews == [Review(mov, "Nice", 6), Review(mov, "Okay", 4)]
Beispiel #13
0
def test_actors():
    movie1 = Movie("Moana", 2016)
    actors = [
        Actor("Auli'i Cravalho"),
        Actor("Dwayne Johnson"),
        Actor("Rachel House"),
        Actor("Temuera Morrison")
    ]
    for actor in actors:
        movie1.add_actor(actor)
    assert movie1.actors == actors
Beispiel #14
0
 def test_init(self):
     # Test first_movie_in_watchlist()
     watchlist1 = WatchList()
     assert watchlist1.first_movie_in_watchlist() == None
     assert watchlist1.size() == 0
     assert watchlist1.select_movie_to_watch(5) == None
     watchlist1.add_movie(Movie("Life Of Pi", 2012))
     assert repr(watchlist1.first_movie_in_watchlist()
                 ) == "<Movie Life Of Pi, 2012>"
     assert watchlist1.size() == 1
     watchlist1.add_movie(Movie("Ice Age", 2002))
     watchlist1.add_movie(Movie("Guardians of the Galaxy", 2012))
     assert repr(watchlist1.first_movie_in_watchlist()
                 ) == "<Movie Life Of Pi, 2012>"
     assert watchlist1.size() == 3
     assert repr(
         watchlist1.select_movie_to_watch(0)) == "<Movie Life Of Pi, 2012>"
     assert watchlist1.select_movie_to_watch(15) == None
     assert repr(
         watchlist1.select_movie_to_watch(1)) == "<Movie Ice Age, 2002>"
 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'])
             movie = Movie(title, release_year)
             self._dataset_of_movies.append(movie)
             self._genre_list += row['Genre'].split(",")
             self._actor_list += row["Actors"].split(',')
             self._director_list += row["Director"].split(',')
Beispiel #16
0
 def test_add_review(self):
     movie = Movie('Moana', 2016)
     review_text = "This movie was very enjoyable."
     rating = 8
     user2 = User('Ian', 'pw67890')
     user3 = User('Daniel', 'pw87465')
     user4 = User('Martin', 'pw12345')
     user_list = [user2, user3, user4]
     watch = MovieWatchingSimulation(user_list, movie)
     watch.add_review(review_text, rating)
     assert (watch.review != None) == True
Beispiel #17
0
    def test_remove_from_watchlist(self):
        # initialise the different movies
        movies = [
            Movie("Moana", 2016),
            Movie("Guardians of the Galaxy", 2014),
            Movie("Ice Age", 2002),
            Movie("Transformers", 2007)
        ]
        movies[0].runtime_minutes = 107
        movies[1].runtime_minutes = 121
        movies[2].runtime_minutes = 103
        movies[3].runtime_minutes = 144
        movie = Movie("Us", 2019)
        movie.runtime_minutes = 121
        random_movie1 = Movie("Black Panther", 2018)
        random_movie1.runtime_minutes = 135
        random_movie2 = Movie("Night School", 2018)
        random_movie2.runtime_minutes = 112

        # user 1
        user1 = User("Martin", "pw12345")
        for mov in movies:
            user1.watch_movie(mov)
        user1.watchlist.add_movie(movie)
        user1.watchlist.add_movie(random_movie1)

        # user 2
        user2 = User("Alfie", "pw23456")
        user2.watch_movie(movies[0])
        user2.watchlist.add_movie(random_movie1)
        user2.watchlist.add_movie(random_movie2)

        # user 3 will be added in after the movie is watchingsimulation
        user3 = User("Yara", "pw34567")
        user3.watch_movie(movies[0])
        user3.watch_movie(movies[2])
        user3.watch_movie(movies[3])
        user3.watchlist.add_movie(movie)

        # user 4
        user4 = User("Danny", "pw45678")
        user4.watch_movie(movies[0])
        user4.watch_movie(movies[2])
        user4.watch_movie(movie)
        user4.watchlist.add_movie(random_movie2)

        user_list = [user1, user2, user4]
        simulation = MovieWatchingSimulation(movie, user_list)
        assert repr(simulation.movie) == "<Movie Us, 2019>"
        assert repr(simulation.user_list
                    ) == "[<User martin>, <User alfie>, <User danny>]"

        assert user1.watchlist.size == 1
        assert user2.watchlist.size == 2
        assert user3.watchlist.size == 1
        assert user4.watchlist.size == 1
Beispiel #18
0
 def test_init(self):
     watchlist_empty = WatchList()
     assert watchlist_empty.size() == 0
     assert watchlist_empty.first_movie_in_watchlist() is None
     watchlist_empty.remove_movie(Movie("Mummy", 2018))
     assert watchlist_empty.size() == 0
     try:
         iter1 = iter(watchlist_empty)
         next(iter1)
         assert False
     except StopIteration:
         assert True
Beispiel #19
0
    def test_init(self):
        movie = Movie("Moana", 2016)
        review_text = "This movie was very enjoyable."
        rating = 8
        review = Review(movie, review_text, rating)

        print(review.movie)
        assert "<Movie Moana, 2016>"
        print("Review: {}".format(review.review_text))
        assert "Review: This movie was very enjoyable."
        print("Rating: {}".format(review.rating))
        assert "Rating: 8"
Beispiel #20
0
def test_replies():
    movie = Movie("Her", 2013)
    comment = Comment(movie, "What year was this movie set in?")
    reply = Comment(movie, "Wait nevermind I just Googled it")
    comment.add_reply(reply)
    assert reply in comment.replies
    assert reply.parent == comment
    reply2 = Comment(movie, "haha wow")
    reply.add_reply(reply2)
    assert reply2.parent is comment
    reply3 = Comment(movie, "oh my god")
    reply2.add_reply(reply3)
    assert reply3.parent is comment
    reply4 = Comment(Movie("Kill Bill: Volume 1", 2003),
                     "I hope they make a sequel")
    comment.add_reply(reply4)
    assert reply4.parent is None
    comment.remove_reply(reply)
    assert reply not in comment.replies
    comment.remove_reply(reply4)
    assert reply4 not in comment.replies
def test_play_previous_not_at_start():
    movie1 = Movie("a", 2020)
    movie2 = Movie("b", 2020)
    movie3 = Movie("c", 2020)
    user = User("ydia530", '123')
    watching_simulation = MovieWatchingSimulation(user)
    watching_simulation.add_movie_to_playlist(movie1)
    watching_simulation.add_movie_to_playlist(movie2)
    watching_simulation.add_movie_to_playlist(movie3)
    watching_simulation.play_next_movie()
    watching_simulation.play_next_movie()
    watching_simulation.play_next_movie()
    watching_simulation.play_previous_movie()
    assert watching_simulation.now_playing == movie3
    assert watching_simulation.next_playing is None
    watching_simulation.play_previous_movie()
    assert watching_simulation.now_playing == movie2
    assert watching_simulation.next_playing == movie3
    watching_simulation.play_previous_movie()
    assert watching_simulation.now_playing == movie1
    assert watching_simulation.next_playing == movie2
Beispiel #22
0
    def test_init(self):
        movie1 = Movie("Moana", 2016)
        movie2 = Movie("Ice Age", 2002)
        movie3 = Movie("John Cena", 1999)
        movie4 = Movie("Bravo", 2000)
        movie5 = Movie("Charlie", 1987)

        not_movie = "Hello World"
        not_movie2 = 123

        lst = [movie1, movie2, movie3, movie4, movie5, not_movie, not_movie2]

        not_lst = "string"
        film_compare1 = movie_compare(not_lst)

        assert film_compare1.movies_lst == []

        film_comparison2 = movie_compare(lst)
        assert film_comparison2.movies_lst == [
            movie1, movie2, movie3, movie4, movie5
        ]
Beispiel #23
0
 def create_movie_instance(self, row):
     movie = Movie(row["Title"], int(row["Year"]))
     movie.director = Director(row["Director"])
     movie.runtime_minutes = int(row["Runtime (Minutes)"])
     movie.actors = [
         Actor(actor.strip()) for actor in row['Actors'].split(",")
     ]
     movie.genres = [
         Genre(genre.strip()) for genre in row['Genre'].split(",")
     ]
     movie.description = row["Description"]
     return movie
Beispiel #24
0
def test_add_genre():
    movie1 = Movie("Spirited Away", 2000)

    movie1.genres = [Genre("Comedy")]
    movie1.add_genre(Genre("Horror"))
    assert movie1.genres == [Genre("Comedy"), Genre("Horror")]
    movie1.add_genre("Scifi")
    movie1.add_genre(Genre("Hhiya"))
    movie1.add_genre("")
    movie1.add_genre(None)
    movie1.add_genre(21345648)
    assert movie1.genres == [Genre("Comedy"), Genre("Horror"), Genre("Hhiya")]
Beispiel #25
0
 def test_init(self, movie):
     assert movie == Movie("The 100", 2016)
     assert movie.description == ""
     assert movie.director is None
     assert movie.actors == []
     assert movie.genres == []
     assert movie.runtime_minutes == 0
     assert movie.rank is None
     assert movie.rating is None
     assert movie.votes is None
     assert movie.revenue is None
     assert movie.metascore is None
Beispiel #26
0
    def test_watch_movie(self):
        user = User('Martin', 'pw12345')

        movie1 = Movie('Moana', 2016)
        movie1.runtime_minutes = 113

        movie2 = Movie('Frozen', 2014)
        movie2.runtime_minutes = 109

        user.watch_movie(movie1)
        assert len(user.watched_movies) == 1
        assert user.watched_movies[0] == movie1
        assert user.time_spent_watching_movies_minutes == 113

        user.watch_movie(movie2)
        assert len(user.watched_movies) == 2
        assert user.watched_movies[1] == movie2
        assert user.time_spent_watching_movies_minutes == 222

        user.watch_movie(movie1)
        assert len(user.watched_movies) == 2
        assert user.time_spent_watching_movies_minutes == 222
def test_repr_():
    movie1 = Movie("Moana", 2016)
    movie1.runtime_minutes = 107
    user1 = User('Martin', 'pw12345')
    review_text1 = "This movie was very enjoyable."
    rating1 = 9
    user2 = User('Ashton', 'pw54321')
    review_text2 = "This movie was ok."
    rating2 = 6
    cflix = MovieWatchingSimulation(movie1)
    cflix.record_user_and_review(user1, review_text1, rating1)
    cflix.record_user_and_review(user2, review_text2, rating2)
    print(repr(cflix))
Beispiel #28
0
def test_top_actors(stats):
    movie2 = Movie('Brin', 2002)
    movie2.add_actor(Actor("Tom Cruise"))
    stats.user.watch_movie(movie2)
    stats.update_watched_lists()
    assert stats.top_actors(2) == [Actor("Tom Cruise"), Actor("Will Smith")]
    assert stats.top_actors(6) == []
    assert stats.top_actors(-1) == [
        Actor("Tom Cruise"),
        Actor("Will Smith"),
        Actor("Selena Gomez"),
        Actor("Daniel Radcliff")
    ]
Beispiel #29
0
def test_hash_1():
    movie1 = Movie("Spirited Away", 2000)
    movie2 = Movie("Spirited Away", 2000)
    movie3 = Movie("Spirited Away", 2001)
    movie4 = Movie("Spirited Away", 2002)
    movie5 = Movie("Spirited Away", 2003)
    movie6 = Movie("Spirited Away", 2004)
    movie7 = Movie("Spirited Away", 1885)

    seta = {movie1, movie2, movie3, movie4, movie5, movie6, movie7}
    assert seta == {movie1, movie3, movie4, movie5, movie6, movie7}
Beispiel #30
0
def test_iterator_used(watchlist):
    watchlist.add_movie(Movie("Moana", 2016))
    watchlist.add_movie(Movie("Your Name", 2016))
    watchlist.add_movie(Movie("A Silent Voice", 2016))
    iterator = iter(watchlist)
    assert next(watchlist) == Movie("Moana", 2016)
    assert next(watchlist) == Movie("Your Name", 2016)
    assert next(watchlist) == Movie("A Silent Voice", 2016)