コード例 #1
0
def test_init(user):
    assert user.watched_movies == MovieList()
    assert user.time_spent_watching_movies_minutes == 0
    assert user.reviews == []
    assert user.username == "aram485"
    assert user.password == "Spiderman209"
    user1 = User("", 4)
    user2 = User(45, "")
    assert user1.username is None
    assert user1.password is None
    assert user2.username is None
    assert user2.password is None

    mov = Movie("Up", 2009)
    mov2 = Movie("Down", 2019)
    mov.runtime_minutes = 200
    mov2.runtime_minutes = 160
    review = Review(mov, "Nice", 6)
    time = mov.runtime_minutes + mov2.runtime_minutes
    watched_already = MovieList()
    watched_already.add_movie(mov)
    watched_already.add_movie(mov2)
    user2 = User("     ARAM85  ", "spideran", watched_already, None,
                 (review, ), time)

    print("user2:", user2)
    print(user2.watched_movies.list)
    assert user2.watched_movies.list == (Movie("Up",
                                               2009), Movie("Down", 2019))
    assert user2.time_spent_watching_movies_minutes == 360
    assert user2.username == "aram85"
    assert user2.password == "spideran"
コード例 #2
0
def test_get_movies_for_actors(in_memory_repo):
    movie = Movie("Split", 2016)
    in_memory_repo.add_movie(movie)
    assert Movie("Suicide Squad",
                 2016) in in_memory_repo.get_movies_for_actor("Will Smith")
    assert len(in_memory_repo.get_movies_for_actor("Will Smith")) == 1
    assert in_memory_repo.get_movies_for_actor("Katy Perry") == []
コード例 #3
0
ファイル: test_stats.py プロジェクト: adito0/AFlix_A2
def user():
    movie = Movie('Up', 2009)
    movie.add_actor(Actor("Will Smith"))
    movie.add_actor(Actor("Daniel Radcliff"))
    movie.add_genre(Genre("Comedy"))
    movie.add_genre(Genre("Drama"))
    director = Director("Peter Jackson")
    movie.director = director

    movie1 = Movie('Down', 2013)
    movie1.add_actor(Actor("Tom Cruise"))
    movie1.add_actor(Actor("Selena Gomez"))
    movie1.add_genre(Genre("Comedy"))
    movie1.add_genre(Genre("Romance"))
    director = Director("Peter Jackson")
    movie1.director = director

    movie2 = Movie('Boom', 1999)
    movie2.add_actor(Actor("Will Smith"))
    movie2.add_actor(Actor("Tom Cruise"))
    movie2.add_genre(Genre("Comedy"))
    movie2.add_genre(Genre("Action"))
    director = Director("Taika Waititi")
    movie2.director = director

    user = User("aram", "one1")
    user.watch_movie(movie)
    user.watch_movie(movie1)
    user.watch_movie(movie2)
    return user
コード例 #4
0
def test_get_number_of_movies(in_memory_repo):
    assert in_memory_repo.get_number_of_movies() == 13
    movie = Movie("Split", 2017)
    in_memory_repo.add_movie(movie)
    assert in_memory_repo.get_number_of_movies() == 14
    movie = Movie("Split", 2017)
    in_memory_repo.add_movie(movie)
    assert in_memory_repo.get_number_of_movies() == 14
コード例 #5
0
ファイル: test_simulation.py プロジェクト: adito0/AFlix_A2
def test_watch_movie_with_runtime(simulation):
    movie = Movie("Lego", 2019)
    movie.runtime_minutes = 2
    successful = simulation.watch_movie(movie)
    assert successful == True
    assert simulation.movie == Movie("Lego", 2019)
    assert simulation.is_paused is False
    assert simulation.is_playing is True
コード例 #6
0
def test_get_movies_for_director(in_memory_repo):
    movie = Movie("Lion", 2018)
    movie.director = Director("Taika Waititi")
    in_memory_repo.add_movie(movie)
    assert Movie(
        "Lion",
        2018) in in_memory_repo.get_movies_for_director("Taika Waititi")
    assert len(in_memory_repo.get_movies_for_director("Taika Waititi")) == 1
    assert in_memory_repo.get_movies_for_director("Katy Perry") == []
コード例 #7
0
def test_get_movies_for_genre(in_memory_repo):
    assert len(in_memory_repo.get_movies_for_genre("Adventure")) == 7
    assert Movie("Prometheus",
                 2012) in in_memory_repo.get_movies_for_genre("Adventure")
    assert Movie("Guardians of the Galaxy",
                 2014) in in_memory_repo.get_movies_for_genre("Adventure")
    assert Movie("Suicide Squad",
                 2016) in in_memory_repo.get_movies_for_genre("Adventure")
    assert in_memory_repo.get_movies_for_genre("Anime") == []
コード例 #8
0
def test_get_movies_by_title(in_memory_repo):
    assert in_memory_repo.get_movies_by_title("Split") == [
        Movie("Split", 2016)
    ]
    movie = Movie("Split", 2017)
    in_memory_repo.add_movie(movie)
    assert in_memory_repo.get_movies_by_title("Split") == [
        Movie("Split", 2016), Movie("Split", 2017)
    ]
コード例 #9
0
ファイル: test_services.py プロジェクト: adito0/AFlix_A2
def test_search_movies(in_memory_repo):
    movies = movie_services.search_for_movies("Action@@", in_memory_repo)
    assert len(movies) == 4
    assert movies[0] == Movie("Guardians of the Galaxy", 2014)
    assert movies[-1] == Movie("The Lost City of Z", 2016)
    movies1 = movie_services.search_for_movies("Action@@James+Gunn",
                                               in_memory_repo)
    assert len(movies1) == 1
    assert movies1[0] == Movie("Guardians of the Galaxy", 2014)
コード例 #10
0
ファイル: test_services.py プロジェクト: adito0/AFlix_A2
def test_write_review(in_memory_repo):
    review = Review(Movie("Split", 2016), "Great", 9.1)
    review_services.write_review("Split", 2016, "Great", 9.1, "aram485",
                                 in_memory_repo)
    movie_name = "Split"
    movie_year = 2016
    reviews = review_services.get_reviews(Movie(movie_name, movie_year),
                                          in_memory_repo)
    assert reviews[2].review_text == "Great"
    assert len(reviews) == 3
コード例 #11
0
ファイル: test_services.py プロジェクト: adito0/AFlix_A2
def test_get_ordered_movies(in_memory_repo):
    movies = movie_services.get_ordered_movies_for_year(
        0, 8, 2016, in_memory_repo)
    movies1 = movie_services.get_ordered_movies_for_year(
        8, 16, 2016, in_memory_repo)
    assert movies[0] == Movie("Fantastic Beasts and Where to Find Them", 2016)
    assert movies[-1] == Movie("Split", 2016)
    assert len(movies) == 8
    assert movies1[0] == Movie("Suicide Squad", 2016)
    assert movies1[-1] == Movie("The Lost City of Z", 2016)
    assert len(movies1) == 3
コード例 #12
0
def test_eq(review):
    time.sleep(1)
    review1 = Review(Movie("Up", 2009), 'Review Test', 4)
    assert review1 != review
    review2 = Review(Movie("Up", 2009), 'Review Test', 0)
    review3 = Review(Movie("Up", 2009), '', 10)
    review4 = Review(Movie("Up", 2009), 9, 1)
    review5 = Review(Movie("", 1989), "Review Test", 8)
    assert review2 != review
    assert review3 != 9
    assert review4 != review
    assert review5 != review
コード例 #13
0
def test_watch_movie(user):
    user.watch_movie(3)
    assert user.watched_movies == MovieList()
    assert user.time_spent_watching_movies_minutes == 0
    mov = Movie("Up", 2009)
    user.watch_movie(mov)
    assert user.watched_movies.list == (Movie("Up", 2009), )
    assert user.time_spent_watching_movies_minutes == 0
    mov.runtime_minutes = 123
    user.watch_movie(mov)
    assert user.watched_movies.list == (Movie("Up", 2009), )
    assert user.time_spent_watching_movies_minutes == 123
    user.watch_movie(mov)
    assert user.watched_movies.list == (Movie("Up", 2009), )
    assert user.time_spent_watching_movies_minutes == 246
コード例 #14
0
ファイル: test_simulation.py プロジェクト: adito0/AFlix_A2
def test_check_if_finished(simulation):  # Takes one minute to run
    movie = Movie("Lego", 2019)
    movie.runtime_minutes = 1
    simulation.watch_movie(movie)
    assert simulation.time_played == 0
    assert simulation.time_left == 60
    time.sleep(2)
    assert simulation.check_if_finished() == False
    assert simulation.time_played == 2
    assert simulation.time_left == 58
    watched = simulation.time_played
    remaining = simulation.time_left
    print()
    while not simulation.check_if_finished():
        assert simulation.time_left == remaining
        assert simulation.time_played == watched
        watched += 1
        remaining -= 1
        print(watched, "\t", remaining)
        time.sleep(1)
    assert simulation.time_played is None
    assert simulation.time_left is None
    assert simulation.is_paused == False
    assert simulation.movie is None
    assert simulation.is_playing is False
コード例 #15
0
ファイル: test_simulation.py プロジェクト: adito0/AFlix_A2
def test_watch_movie_no_runtime(simulation):
    movie = Movie("Lego", 2019)
    successful = simulation.watch_movie(movie)
    assert successful == False
    assert simulation.movie is None
    assert simulation.is_paused is False
    assert simulation.is_playing is False
    assert simulation.time_left is None
    assert simulation.time_played is None
コード例 #16
0
def get_image(movie: Movie = Movie("Split", 2016)):
    token = "adea3d0d"
    token = "40e73228"
    movie_name = movie.title.replace(" ", "+")
    movie_year = movie.release_year
    url = "http://www.omdbapi.com/?apikey=" + token + "&t=" + movie_name.lower(
    ) + "&y=" + str(movie_year)
    r = requests.get(url).json()
    if r['Response'] == "True":
        return r['Poster']
コード例 #17
0
ファイル: test_services.py プロジェクト: adito0/AFlix_A2
def test_get_reviews_for_movie(in_memory_repo):
    movie_name = "Split"
    movie_year = 2016
    reviews = review_services.get_reviews(Movie(movie_name, movie_year),
                                          in_memory_repo)
    print(reviews[0].review_text, reviews[1].review_text)
    assert reviews[
        0].review_text == "I love this movie so much!! It really makes you think"
    assert reviews[1].review_text == "Wow!"
    assert len(reviews) == 2
コード例 #18
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)]
コード例 #19
0
ファイル: test_stats.py プロジェクト: adito0/AFlix_A2
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")
    ]
コード例 #20
0
def load_movies(data_path: str, repo: MemoryRepository, data_file):
    print("DATA: ", data_file)
    for row in read_csv_file(os.path.join(data_path, data_file)):
        try:
            movie = Movie(row['Title'], int(row['Year']))
        except ValueError:
            print("Invalid release year")
        else:
            director = Director(row['Director'].strip())
            actors = row['Actors'].split(",")
            genres = row['Genre'].split(",")
            movie.director = director
            repo.add_director(director)
            movie.description = row['Description'].strip()
            for actor_name in actors:
                actor_name = actor_name.strip()
                actor = Actor(actor_name)
                if actor in repo.get_actors():
                    i = repo.get_actors().index(actor)
                    actor = repo.get_actors()[i]
                else:
                    repo.add_actor(actor)
                for actor1_name in actors:
                    actor1_name = actor1_name.strip()
                    if not actor.check_if_this_actor_worked_with(
                            Actor(actor1_name)) and (actor_name !=
                                                     actor1_name):
                        actor.add_actor_colleague(Actor(actor1_name))
                movie.add_actor(actor)
            for genre_name in genres:
                genre = Genre(genre_name.strip())
                movie.add_genre(genre)
                if genre not in repo.get_genres():
                    repo.add_genre(genre)
            try:
                movie.runtime_minutes = int(row['Runtime (Minutes)'])
            except ValueError:
                movie.runtime_minutes = None
            try:
                movie.votes = int(row['Votes'])
            except ValueError:
                movie.votes = None
            try:
                movie.rating = float(row['Rating'])
            except ValueError:
                movie.rating = None
            if movie not in repo.get_movies():
                movie.image = get_image(movie)
                if movie.image == "":
                    movie.image = "../static/none.jpg"
                repo.add_movie(movie)
コード例 #21
0
ファイル: test_stats.py プロジェクト: adito0/AFlix_A2
def test_update(stats):
    movie2 = Movie('Brain', 2002)
    movie2.add_actor(Actor("Julia Roberts"))
    movie2.add_actor(Actor("Tom Cruise"))
    movie2.add_genre(Genre("Sci-Fi"))
    movie2.add_genre(Genre("Action"))
    director = Director("Christopher Nolan")
    movie2.director = director

    stats.user.watch_movie(movie2)
    stats.update_watched_lists()

    assert stats.user == User("aram", "one1", [], [], 0)
    assert stats.watched_movies == [
        Movie("Up", 2009),
        Movie("Down", 2013),
        Movie("Boom", 1999),
        Movie("Brain", 2002)
    ]
    assert stats.watched_actors == {
        Actor("Will Smith"): 2,
        Actor("Daniel Radcliff"): 1,
        Actor("Selena Gomez"): 1,
        Actor("Tom Cruise"): 3,
        Actor("Julia Roberts"): 1
    }
    assert stats.watched_directors == {
        Director("Peter Jackson"): 2,
        Director("Taika Waititi"): 1,
        Director("Christopher Nolan"): 1
    }
    assert stats.watched_genres == {
        Genre("Comedy"): 3,
        Genre("Romance"): 1,
        Genre("Drama"): 1,
        Genre("Action"): 2,
        Genre("Sci-Fi"): 1
    }
コード例 #22
0
ファイル: test_stats.py プロジェクト: adito0/AFlix_A2
def test_init(stats):
    assert stats.user == User("aram", "one1", [], [], None, 0)
    assert stats.watched_movies == [
        Movie("Up", 2009),
        Movie("Down", 2013),
        Movie("Boom", 1999)
    ]
    assert stats.watched_actors == {
        Actor("Will Smith"): 2,
        Actor("Daniel Radcliff"): 1,
        Actor("Selena Gomez"): 1,
        Actor("Tom Cruise"): 2
    }
    assert stats.watched_directors == {
        Director("Peter Jackson"): 2,
        Director("Taika Waititi"): 1
    }
    assert stats.watched_genres == {
        Genre("Comedy"): 3,
        Genre("Romance"): 1,
        Genre("Drama"): 1,
        Genre("Action"): 1
    }
コード例 #23
0
ファイル: test_simulation.py プロジェクト: adito0/AFlix_A2
def test_pause_play(simulation):
    assert simulation.pause() == False
    movie = Movie("Lego", 2019)
    movie.runtime_minutes = 2
    simulation.watch_movie(movie)
    time.sleep(2)
    simulation.pause()
    time.sleep(2)
    assert simulation.is_paused == True
    simulation.play()
    assert simulation.time_played == 2
    assert simulation.time_left == 118
    assert simulation.is_paused == False
    time.sleep(2)
    assert simulation.time_played == 4
    assert simulation.time_left == 116
コード例 #24
0
ファイル: test_movie.py プロジェクト: adito0/AFlix_A2
def test_lt(movie):
    movie1 = Movie("", 2009)
    movie2 = Movie(45, 2009)
    movie3 = Movie("Hello", "f")
    movie4 = Movie("Hello", 1888)
    movie5 = Movie("Hello", 2009)
    movie6 = Movie("Goodbye", 2019)
    movie7 = Movie("Hello", 2019)
    assert movie5 < movie7
    assert movie5 > movie6
    assert movie7 > movie6
    assert (movie1 > movie) is None
    assert (movie2 > movie) is None
    assert movie > movie3
    assert movie > movie4
コード例 #25
0
ファイル: test_movie.py プロジェクト: adito0/AFlix_A2
def test_eq(movie):
    movie1 = Movie("Up", 2009)
    movie2 = Movie("Upp", 2009)
    movie3 = Movie("Up", 2019)
    assert movie == movie1
    assert movie != movie2
    assert movie != movie3
    movie2 = 4
    assert movie != movie2
    movie1 = Movie("", 2009)
    movie2 = Movie(45, 2009)
    movie3 = Movie("Hello", "f")
    movie4 = Movie("Hello", 1888)
    assert movie != movie1
    assert movie != movie2
    assert movie2 == movie1
    assert movie != movie3
    assert movie3 == movie4
コード例 #26
0
ファイル: test_movie.py プロジェクト: adito0/AFlix_A2
def test_hash():
    movie1 = Movie("HI", 1998)
    movie2 = Movie("HI", 1998)
    assert hash(movie1) == hash(movie2)
    movie2 = Movie("HI", 1997)
    assert hash(movie1) != hash(movie2)
    movie2 = Movie("HJ", 1998)
    assert hash(movie1) != hash(movie2)
    dict1 = dict()
    dict1[movie1] = movie2
    assert dict1[movie1] == movie2
    assert repr(dict1[movie1]) == "<Movie HJ, 1998>"
    movie1 = Movie("", 2009)
    movie2 = Movie(45, 2009)
    movie3 = Movie("Hello", "f")
    movie4 = Movie("Hello", 1888)
    dict1[movie1] = movie2
    dict1[movie3] = movie4
    assert dict1[movie1] == movie2
    assert repr(dict1[movie1]) == "<Movie None, 2009>"
    assert dict1[movie3] == movie4
    assert repr(dict1[movie3]) == "<Movie Hello, None>"
コード例 #27
0
def test_init(review):
    assert review.movie == Movie("Up", 2009)
    assert review.review_text == 'Review Test'
    assert review.rating == 4
    assert type(review.timestamp) == datetime
    review1 = Review(Movie("Up", 2009), 'Review Test', 11)
    review2 = Review(Movie("Up", 2009), 'Review Test', 0)
    review3 = Review(Movie("Up", 2009), '', 10)
    review4 = Review(Movie("Up", 2009), 9, 1)
    review5 = Review(Movie("", 1989), "Review Test", 8)
    assert review1.rating is None
    assert review2.rating is None
    assert review3.review_text is None
    assert review4.review_text is None
    assert repr(review5.movie) == "<Movie None, None>"
    assert repr(review1) == "<Rating None, Review Review Test>"
    assert repr(review4) == "<Rating 1, Review None>"
コード例 #28
0
ファイル: test_movie.py プロジェクト: adito0/AFlix_A2
def test_init(movie):
    assert movie.title == 'Up'
    assert movie.release_year == 2009
    movie1 = Movie("Enchanted", 2012)
    assert repr(movie) == "<Movie Up, 2009>"
    assert repr(movie1) == "<Movie Enchanted, 2012>"
    movie1 = Movie("Enchanted", 'a')
    assert repr(movie1) == "<Movie Enchanted, None>"
    movie1 = Movie("Enchanted", 10)
    assert repr(movie1) == "<Movie Enchanted, None>"
    movie1 = Movie("Enchanted", 2021)
    assert repr(movie1) == "<Movie Enchanted, None>"
    movie2 = Movie("", 4)
    assert movie2.title is None
    assert repr(movie2) == "<Movie None, None>"
    movie3 = Movie(42, 2000)
    assert movie3.title is None
    assert repr(movie3) == "<Movie None, 2000>"
コード例 #29
0
def load_users(data_path: str, repo: MemoryRepository):
    #    for row in read_csv_file(os.path.join(data_path, 'test1user.csv')):
    print("OS", os.path.join(data_path, 'Data5Users.csv'))
    for row in read_csv_file(os.path.join(data_path, 'Data5Users.csv')):
        watching_time = 0
        watchlist_string = row['Watchlist'].strip().split("|")
        watchlist = MovieList()
        for movie_name in watchlist_string:
            movie_name = movie_name.strip().split(";")
            try:
                movie = Movie(movie_name[0].strip(),
                              int(movie_name[1].strip()))
            except:
                print("Invalid movie")
            else:
                if movie in repo.get_movies():
                    i = repo.get_movies().index(movie)
                    movie = repo.get_movies()[i]
                else:
                    pass
                    #repo.add_movie(movie)
                if movie not in watchlist.list:
                    watchlist.add_movie(movie)

        watched_string = row["Watched_movies"].strip().split("|")
        watched = MovieList()
        for movie_name in watched_string:
            movie_name = movie_name.strip().split(";")
            try:
                movie = Movie(movie_name[0].strip(),
                              int(movie_name[1].strip()))
            except:
                print("Invalid movie")
            else:
                if movie in repo.get_movies():
                    i = repo.get_movies().index(movie)
                    movie = repo.get_movies()[i]
                else:
                    pass
                    #repo.add_movie(movie)
                if movie not in watched:
                    watched.add_movie(movie)
                    if movie.runtime_minutes is not None:
                        try:
                            watching_time += movie.runtime_minutes
                        except:
                            pass

        reviews_string = row["Reviews"].strip().split("|")
        review_list = []
        for review_string in reviews_string:
            review_string = review_string.strip().split(";")
            if len(review_string) > 4:
                try:
                    movie = Movie(review_string[0].strip(),
                                  int(review_string[1].strip()))
                except:
                    print("Invalid movie")
                else:
                    if movie in repo.get_movies():
                        i = repo.get_movies().index(movie)
                        movie = repo.get_movies()[i]
                    else:
                        pass
                        #repo.add_movie(movie)

                    review_message = review_string[3].strip()

                    try:
                        #timestamp = datetime.strptime(review_string[4].strip())
                        timestamp = datetime.fromisoformat(
                            review_string[4].strip())
                    except:
                        pass
                    else:
                        try:
                            rating = float(review_string[2])
                        except:
                            pass
                        else:
                            review = Review(movie, review_message, rating)
                            review.timestamp = timestamp
                            review_list.append(review)
                            repo.add_review(review)
        user = User(username=row['Username'].strip(),
                    password=generate_password_hash(row['Password'].strip()),
                    watched=watched,
                    reviews=tuple(review_list),
                    time_spent=watching_time,
                    watchlist=watchlist)
        repo.add_user(user)
コード例 #30
0
ファイル: test_services.py プロジェクト: adito0/AFlix_A2
def test_can_get_user_for_review(in_memory_repo):
    new_username = '******'
    user = review_services.get_user(new_username, in_memory_repo)
    assert Movie("Split", 2016) in user.watchlist