コード例 #1
0
def test_repository_can_add_movie(in_memory_repo):
    movie = Movie(
        "I am Legend",
        1981
    )
    movie.rank = 1001
    in_memory_repo.add_movie(movie)
    assert in_memory_repo.get_movie(1001) is movie
コード例 #2
0
def test_repository_can_add_director_dict(in_memory_repo):
    movie = Movie(
        "I am Legend",
        1981
    )
    director = Director("James Gunn")
    movie.director=director
    dict_director = {}
    dict_director[director]=[movie]
    in_memory_repo.add_director(dict_director)
    assert in_memory_repo.get_directors() is dict_director
コード例 #3
0
def test_repository_can_add_actor_dict(in_memory_repo):
    movie = Movie(
        "I am Legend",
        1981
    )
    actor = Actor("Will Smith")
    movie.actors=actor
    dict_actor = {}
    dict_actor[actor]=[movie]
    in_memory_repo.add_actor(dict_actor)
    assert in_memory_repo.get_actors() is dict_actor
コード例 #4
0
def test_repository_can_add_genre_dict(in_memory_repo):
    movie = Movie(
        "I am Legend",
        1981
    )
    genre = Genre("Fantasy")
    movie.genres=genre
    dict_genre = {}
    dict_genre[genre]=[movie]
    in_memory_repo.add_genres(dict_genre)
    assert in_memory_repo.get_genres() is dict_genre
コード例 #5
0
def dict_to_movie(dict):
    movie = Movie(dict.title, dict.release_year)
    movie.rank = dict.rank
    movie.description = dict.description
    movie.director = dict_to_director(dict.director)
    movie.actors = dict_to_actors(dict.actors)
    movie.genres = dict_to_genres(dict.genres)
    movie.runtime_minutes = dict.runtime_minutes
    movie.rating = dict.rating
    return movie
コード例 #6
0
def test_director_construction(director):
    assert director.director_name == 'James Gunn'

    for director in director.directed_movies:
        assert False

    assert not director.is_applied_to(Movie(None, None, None, None, None, None, None, None))
コード例 #7
0
def test_genre_construction(genre):
    assert genre.genre_name == 'Action'

    for movie in genre.genre_of_movies:
        assert False

    assert not genre.is_applied_to(Movie(None, None, None, None, None, None, None, None))
コード例 #8
0
ファイル: services.py プロジェクト: clintonmuldoon/Movieapp
def dict_to_movie(dict):
    movie = Movie(dict.id, dict.title, dict.description, dict.year,
                  dict.runtime_minutes, dict.rating, dict.rating, dict.votes,
                  dict.revenue_millions, dict.meta_score, dict.reviews,
                  dict.genres, dict.actors, dict.directors)
    # Note there's no comments or tags.
    return movie
コード例 #9
0
def test_actor_construction(actor):
    assert actor.actor_name == 'Chris Pratt'

    for movie in actor.acted_movies:
        assert False

    assert not actor.is_applied_to(Movie(None, None, None, None, None, None, None, None))
コード例 #10
0
def test_repository_can_add_year_dict(in_memory_repo):
    movie = Movie(
        "I am Legend",
        1981
    )
    dict_year = {}
    dict_year[movie.year]=movie
    in_memory_repo.add_year(dict_year)
    assert in_memory_repo.get_years() is dict_year
コード例 #11
0
def movie():
    return Movie(
        "Guardians of the Galaxy",
        "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.",
        2014,
        121,
        8.1,
        757074,
        333.13,
        76
    )
コード例 #12
0
def test_init(review):
    user = User('Steve', 'pass123')
    movie = Movie("Moana", 2016)
    review_text = "This movie was very enjoyable."
    rating = 8
    timestamp = datetime.today()
    review = Review(user, movie, review_text, timestamp, rating)

    ## test cr3
    assert repr(review.movie) == "<Movie Moana, 2016>"
    assert "Review: {}".format(
        review.review_text) == "Review: This movie was very enjoyable."
    assert "Rating: {}".format(review.rating) == "Rating: 8"

    ##test movie
    actor = Actor("Will Smith")
    review.movie = actor  ##illegal
    assert repr(review.movie) == "<Movie Moana, 2016>"
    movie = Movie("Will Smith smith Will Smith?", 1900)
    review.movie = movie  ##legal
    assert repr(review.movie) == "<Movie Will Smith smith Will Smith?, 1900>"

    ##test review text
    review.review_text = 1900  ##illegal
    assert review.review_text == "This movie was very enjoyable."
    review.review_text = "Will Smith will smith Will Smith"  ##legal
    assert review.review_text == "Will Smith will smith Will Smith"

    ##test rating
    review.rating = 10.1
    assert review.rating == 8
    review.rating = 9
    assert review.rating == 9

    ##test __eq__
    movie = Movie("Will Smith smith Will Smith?", 1900)
    review_text = "Will Smith will smith Will Smith"
    rating = 9
    review1 = Review(user, movie, review_text, timestamp, rating)
    assert review == review1
コード例 #13
0
def load_movie_data(data_path: str, repo: MemoryRepository):
    actors = dict()
    genres = dict()
    directors = dict()

    for line in read_csv_file(os.path.join(data_path, 'Data1000Movies.csv')):
        movie_id = line[0]
        movie_genres = line[2].split(',')
        movie_director = line[4].strip()
        movie_actors = line[5].split(',')

        for actor in movie_actors:
            actor = actor.strip()
            if actor not in actors.keys():
                actors[actor] = list()
            actors[actor].append(movie_id)

        for genre in movie_genres:
            if genre not in genres.keys():
                genres[genre] = list()
            genres[genre].append(movie_id)

        if movie_director not in directors.keys():
            directors[movie_director] = list()
        directors[movie_director].append(movie_id)

        movie = Movie(
            title=line[1], description=line[3], year=line[6], runtime_minutes=line[7], rating=line[8],
            votes=line[9], revenue_millions=line[10], meta_score=line[11], id=movie_id
            )
        repo.add_movie(movie)

    for actor in actors.keys():
        actorobj = Actor(actor)
        for movie_id in actors[actor]:
            movie = repo.get_movie(movie_id)
            make_actor_association(movie, actorobj)
        repo.add_actor(actorobj)

    for genre in genres.keys():
        genreobj = Genre(genre)
        for movie_id in genres[genre]:
            movie = repo.get_movie(movie_id)
            make_genre_association(movie, genreobj)
        repo.add_genre(genreobj)

    for director in directors.keys():
        directorobj = Director(director)
        for movie_id in directors[director]:
            movie = repo.get_movie(movie_id)
            make_director_association(movie, directorobj)
        repo.add_director(directorobj)
コード例 #14
0
def test_init(movie):
    #test cr3
    movie1 = Movie("Moana", 2016)
    assert repr(movie1) == "<Movie Moana, 2016>"
    movie3 = Movie("Moana", 1899)
    assert movie3.title is None
    # check for equality of two Director object instances by comparing the names
    movie4 = Movie("Moana", 2016)
    assert (movie1 == movie4) == True
    # implement a sorting order defined by the name
    a_list = []
    movie5 = Movie("Yasuo The Retarded", 2015)
    a_list.append(movie5)
    a_list.append(movie1)
    a_list.sort()
    assert a_list[0] == movie1
    # defines which attribute is used for computing a hash value as used in set or dictionary keys
    movies = {movie1, movie4}
    assert len(movies) == 1
    movie5 = Movie("Moana", 2015)
    movies = {movie1, movie5}
    assert len(movies) == 2
コード例 #15
0
def test_repository_can_add_movie(in_memory_repo):
    movie = Movie(
            "Guardians of the Galaxy",
            "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.",
            2014,
            121,
            8.1,
            757074,
            333.13,
            76
    )
    in_memory_repo.add_movie(movie)

    assert in_memory_repo.get_movie(9) is movie
コード例 #16
0
def test_cr3(watchlist):
    watchlist = WatchList()
    print(f"Size of watchlist: {watchlist.size()}")
    watchlist.add_movie(Movie("Moana", 2016))
    watchlist.add_movie(Movie("Ice Age", 2002))
    watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
    print(watchlist.first_movie_in_watchlist())
    print(watchlist.size())
    watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
    print(watchlist.size())
    watchlist.remove_movie(Movie("Moana", 2016))
    print(watchlist.size())
    watchlist.remove_movie(Movie("Moana", 2016))
    print(watchlist.size())
    print(watchlist.select_movie_to_watch(1))
    print(watchlist.select_movie_to_watch(100))
    watchlist.add_movie(Movie("Yasuo The Retarded", 2012))
    i = iter(watchlist)
    for movie in i:
        print(movie)
コード例 #17
0
def movie():
    return Movie('', 0)
コード例 #18
0
def test_properties(movie):
    movie1 = Movie("Moana", 2016)
    movie1.title = "Hokage"  # legal title
    assert repr(movie1) == "<Movie Hokage, 2016>"
    movie1.title = 1234  # illegal title
    assert repr(movie1) == "<Movie Hokage, 2016>"

    movie2 = Movie("Raikage", 2004)
    movie2.description = " Faster than speed of light for real "  # legal description
    assert movie2.description == "Faster than speed of light for real"
    movie2.description = ""  # illegal description
    assert movie2.description == "Faster than speed of light for real"

    movie3 = Movie("Moana", 2016)
    actor = Actor("Jacinda Adern")
    director = Director("Ron Clements")
    movie3.director = actor  #illegal director
    assert movie3.director is None
    movie3.director = director  #legal director
    assert repr(movie3.director) == "<Director Ron Clements>"

    actors = [
        Actor("Auli'i Cravalho"),
        Actor("Dwayne Johnson"),
        Actor("Rachel House"),
        Actor("Temuera Morrison")
    ]
    for actor in actors:
        movie3.add_actor(actor)  ##legal adding actor
    assert str(
        movie3.actors
    ) == "[<Actor Auli'i Cravalho>, <Actor Dwayne Johnson>, <Actor Rachel House>, <Actor Temuera Morrison>]"
    movie3.add_actor(director)  ##illegal adding actor
    assert str(
        movie3.actors
    ) == "[<Actor Auli'i Cravalho>, <Actor Dwayne Johnson>, <Actor Rachel House>, <Actor Temuera Morrison>]"
    movie3.remove_actor(Actor("Rachel House"))  ##legal remove actor
    assert str(
        movie3.actors
    ) == "[<Actor Auli'i Cravalho>, <Actor Dwayne Johnson>, <Actor Temuera Morrison>]"
    movie3.remove_actor(director)  ##illegal remove actor
    assert str(
        movie3.actors
    ) == "[<Actor Auli'i Cravalho>, <Actor Dwayne Johnson>, <Actor Temuera Morrison>]"
    movie3.actors = Actor("Dwayne Johnson")  ##test setter
    assert str(movie3.actors) == "[<Actor Dwayne Johnson>]"

    genres = [
        Genre("Comedy"),
        Genre("Action"),
        Genre("Disney"),
        Genre("Romantic")
    ]
    for genre in genres:
        movie3.add_genre(genre)  ##legal adding genre
    assert str(
        sorted(movie3.genres)
    ) == "[<Genre Action>, <Genre Comedy>, <Genre Disney>, <Genre Romantic>]"
    movie3.add_genre(director)  ##illegal adding genre
    assert str(
        movie3.genres
    ) == "[<Genre Comedy>, <Genre Action>, <Genre Disney>, <Genre Romantic>]"
    movie3.remove_genre(Genre("Romantic"))  ##legal remove genre
    assert str(
        movie3.genres) == "[<Genre Comedy>, <Genre Action>, <Genre Disney>]"
    movie3.remove_genre(director)  ##illegal remove genre
    assert str(
        movie3.genres) == "[<Genre Comedy>, <Genre Action>, <Genre Disney>]"
    movie3.genres = Genre("Comedy")  ##test setter
    assert str(movie3.genres) == "[<Genre Comedy>]"

    movie3.runtime_minutes = 107  ## legal runtime
    assert "Movie runtime: {} minutes".format(
        movie3.runtime_minutes) == "Movie runtime: 107 minutes"
    with pytest.raises(ValueError):
        movie3.runtime_minutes = -1  ## illegal runtime

    ###################################### test extension ######################################

    movie3.rank = 185  ## legal rank
    assert movie3.rank == 185
    with pytest.raises(ValueError):
        movie3.rank = -1  ## illegal rank

    movie3.rating = 8.1  ## legal rating
    assert movie3.rating == 8.1
    with pytest.raises(ValueError):
        movie3.rating = 11  ## illegal rating

    movie3.votes = 107583  ## legal votes
    assert movie3.votes == 107583
    with pytest.raises(ValueError):
        movie3.votes = -1  ## illegal votes

    movie3.revenue_millions = 510.365  ## legal revenue_millions
    assert movie3.revenue_millions == 510.365
    with pytest.raises(ValueError):
        movie3.revenue_millions = -510.365  ## illegal revenue_millions

    movie3.metascore = 91.6  ## legal metascore
    assert movie3.metascore == 91.6
    with pytest.raises(ValueError):
        movie3.metascore = -91.6  ## illegal metascore
コード例 #19
0
def load_movies(data_path: str, repo: MemoryRepository):
    dataset_of_movies = []
    dataset_of_actors = []
    dataset_of_directors = []
    dataset_of_genres = []
    dictionary_genres = {}  # extension
    dictionary_actors = {}  # extension
    dictionary_directors = {}  # extension
    dictionary_years = {}
    ignore_row = 0
    for row in read_csv_file(os.path.join(data_path, 'Data1000Movies.csv')):
        if ignore_row == 0:
            ignore_row += 1
            continue
        rank = int(row[0])
        title = row[1]
        genres = row[2].split(',')
        description = row[3]
        director = Director(str(row[4]))
        actors = row[5].split(',')
        release_year = int(row[6])
        runtime_minutes = int(row[7])
        rating = float(row[8])
        votes = int(row[9])
        revenue_millions = row[10]
        metascore = row[11]
        image_hyperlink = row[12]

        # create movie object
        movie = Movie(title, release_year)
        dataset_of_movies.append(movie)
        if movie.year not in dictionary_years:
            dictionary_years[movie.year] = [movie]  # extension
        else:
            dictionary_years[movie.year].append(movie)

        # add actors
        for actor in actors:
            actor_obj = Actor(actor)
            movie.add_actor(actor_obj)
            if actor_obj not in dataset_of_actors:
                dataset_of_actors.append(actor_obj)
                dictionary_actors[actor_obj] = [movie]  # extension
            else:
                dictionary_actors[actor_obj].append(movie)  # extension

        # add director
        movie.director = director
        if director not in dataset_of_directors:
            dataset_of_directors.append(director)
            dictionary_directors[director] = [movie]
        else:
            dictionary_directors[director].append(movie)

        # add genre
        for genre in genres:
            genre_obj = Genre(genre)
            movie.add_genre(genre_obj)
            if genre_obj not in dataset_of_genres:
                dataset_of_genres.append(genre_obj)
                dictionary_genres[genre_obj] = [movie]  # extension
            else:
                dictionary_genres[genre_obj].append(movie)  # extension

        # add description
        movie.description = description

        # add runtime
        movie.runtime_minutes = runtime_minutes

        # add rank
        movie.rank = rank

        # add rating
        movie.rating = rating

        # add votes
        movie.votes = votes

        # add revenue_million
        movie.revenue_millions = revenue_millions

        # add metascore
        movie.metascore = metascore

        # add metascore
        movie.image_hyperlink = image_hyperlink

        # Add the Movie to the repository.
        repo.add_movie(movie)

    repo.add_year(dictionary_years)
    repo.add_genres(dictionary_genres)
    repo.add_director(dictionary_directors)
    repo.add_actor(dictionary_actors)
コード例 #20
0
def review():
    timestamp = datetime.today()
    return Review(User("", ""), Movie("", 0), "", timestamp, 0)