def test_lt_same_name_same_year():
    movie1 = Movie("Spirited Away", 2000)
    movie2 = Movie("Spirited Away", 2000)
    lt = movie1 < movie2
    eq = movie1 == movie2
    assert eq == True
    assert lt == False
def test_eq_diff_name_diff_year():
    movie1 = Movie("Spirited Away", 2000)
    movie2 = Movie("Spirited", 2005)
    equal = movie1 == movie2
    eq = movie1 == movie2
    assert eq == False
    assert equal == False
def test_lt_diff_name_none_year_2():
    movie1 = Movie("Spirited Away", 2008)
    movie2 = Movie("Spirited", 1750)
    lt = movie1 < movie2
    eq = movie1 == movie2
    assert eq == False
    assert lt == False
def test_lt_same_name_none_year_both():
    movie1 = Movie("Spirited Away", None)
    movie2 = Movie("Spirited Away", None)
    lt = movie1 < movie2
    eq = movie1 == movie2
    assert eq == True
    assert lt == False
def test_lt_none_name2_same_year():
    movie1 = Movie("Spirited Away", 2008)
    movie2 = Movie(None, 2008)
    lt = movie1 < movie2
    eq = movie1 == movie2
    assert eq == False
    assert lt == False
def test_lt_same_name_none_year_1():
    movie1 = Movie("Spirited Away", 1550)
    movie2 = Movie("Spirited Away", 2008)
    lt = movie1 < movie2
    eq = movie1 == movie2
    assert eq == False
    assert lt == True
def test_eq_same_name_same_year():
    movie1 = Movie("Spirited Away", 2000)
    movie2 = Movie("Spirited Away", 2000)
    equal = movie1 == movie2
    eq = movie1 == movie2
    assert eq == True
    assert equal == True
def test_lt_diff_name_diff_year():
    movie1 = Movie("Spirited Away", 2000)
    movie2 = Movie("Spirited", 2008)
    lt = movie1 < movie2
    eq = movie1 == movie2
    assert eq == False
    assert lt == False
def test_movie_less_than_operator():
    movie_1 = Movie(date.fromisoformat('2020-03-15'), None, None, None, None,
                    None, None, None, None, None)

    movie_2 = Movie(date.fromisoformat('2020-04-20'), None, None, None, None,
                    None, None, None, None, None)

    assert movie_1 < movie_2
Esempio n. 10
0
def test_add_movie(in_memory_repo):
    assert in_memory_repo.get_movie_size() == 10
    movie1 = Movie(99, "a", 2000, "description")
    in_memory_repo.add_movie(movie1)
    assert in_memory_repo.get_movie_size() == 11
    in_memory_repo.add_movie(movie1)
    assert in_memory_repo.get_movie_size() == 11
    movie2 = Movie(99, "a", 1999, "description")
    in_memory_repo.add_movie(movie2)
    assert in_memory_repo.get_movie_size() == 12
def test_movie_less_than_operator():
    movie_1 = Movie(
        1, "", "", 0, 0, 0, 0, None, None
    )

    movie_2 = Movie(
        2, "", "", 0, 0, 0, 0, None, None
    )

    assert movie_1 > movie_2
def movie():
    m = Movie(
        1,
        "Guardians of the Galaxy",
        "It's a nice movies",
        2020,
        120,
        66.8,
        23424,
        122.7,
        76
    )
    m.director = 'Denis Villeneuve'
    return m
def test_change_title():
    movie1 = Movie("Spirited Awa", 2000)
    movie2 = Movie("Your Nam", 2000)
    movie3 = Movie("Batma", 2000)

    movie1.title = "                         Spirited Away              "
    movie2.title = "          Your     Name          "
    movie3.title = "         Batman     "

    assert movie1.title == "Spirited Away"
    assert movie2.title == "Your     Name"
    assert movie3.title == "Batman"
Esempio n. 14
0
    def get_movies_by_date(self, target_date: date) -> List[Movie]:
        target_movie = Movie(
            date=target_date,
            title=None,
            first_para=None,
            hyperlink=None,
            image_hyperlink=None,
            rank=None,
            director=None,
            time=None,
            rating = None,
            actors = None,
            id=None
        )
        matching_movies = list()

        try:
            index = self.movie_index(target_movie)
            for movie in self._movies[index:None]:
                if movie.date == target_date:
                    matching_movies.append(movie)
                else:
                    break
        except ValueError:
            # No movies for specified date. Simply return an empty list.
            pass

        return matching_movies
def test_genre_construction(genre: Genre):
    assert genre.genre_name == 'Action'

    for movie in genre.genre_movies:
        assert False

    assert not genre.is_applied_to(Movie(0, "", "", 0, 0, 0, 0, None, None))
def test_genre_construction(genre):
    assert genre.genre_name == 'New Zealand'

    for movie in genre.genreged_movies:
        assert False

    assert not genre.is_applied_to(
        Movie(None, None, None, None, None, None, None, None, None, None))
Esempio n. 17
0
def load_movies(data_path: str, repo: MemoryRepository):
    movies = dict()

    for data_row in read_csv_file(os.path.join(data_path, 'Data1000Movies.csv')):
        movie = Movie(
            rank=int(data_row[0]),
            title=data_row[1].strip(),
            release_year=int(data_row[6]),
            description=data_row[3].strip()
        )

        actors = data_row[5]
        actors = actors.split(',')
        for actor in actors:
            actor = actor.strip()
            if Actor(actor) not in movie.actors:
                movie.add_actor(Actor(actor))

        genres = data_row[2]
        genres = genres.split(',')
        for genre in genres:
            genre = genre.strip()
            if Genre(genre) not in movie.genres:
                movie.add_genre(Genre(genre))

        director = data_row[4]
        director = director.strip()
        movie.director = Director(director)

        repo.add_movie(movie)
        movies[data_row[0]] = movie
    return movies
Esempio n. 18
0
def make_movie(new_movie_date):
    movie = Movie(
        new_movie_date,
        'Coronavirus travel restrictions: Self-isolation deadline pushed back to give airlines breathing room',
        'The self-isolation deadline has been pushed back',
        'https://www.nzherald.co.nz/business/news/movie.cfm?c_id=3&objectid=12316800',
        'https://th.bing.com/th/id/OIP.0lCxLKfDnOyswQCF9rcv7AHaCz?w=344&h=132&c=7&o=5&pid=1.7'
    )
    return movie
def test_add_review():
    user = User("Jack Huang", "123124")
    movie1 = Movie("Your Name", 2000)
    movie2 = Movie("Spirited Away", 1995)
    movie3 = Movie("Avengers 4", 1899)

    review1 = Review(user, movie1, "Good 1", 1)
    review2 = Review(user, movie2, "Good 2", 2)
    review3 = Review(user, movie3, "Good 3", 3)

    assert user.reviews == []
    user.add_review(review1)
    user.add_review(review2)
    user.add_review(review3)
    assert user.reviews == [
        Review(user, movie1, "Good 1", 1),
        Review(user, movie2, "Good 2", 2),
        Review(user, movie3, "Good 3", 3)
    ]
Esempio n. 20
0
def test_repository_can_add_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    number_of_movies = repo.get_number_of_movies()

    new_movie_id = number_of_movies + 1

    movie = Movie(date.fromisoformat('2020-03-09'), "wa", "ga", "", "img",
                  5000, "as,df", 124, "asdf", 44, new_movie_id)
    repo.add_movie(movie)

    assert repo.get_movie(new_movie_id) == movie
def test_code_runner():
    movie = Movie("Moana", 2016)
    assert movie.title == "Moana"
    assert movie.release_year == 2016
    director = Director("Ron Clements")
    movie.director = director
    assert movie.director == Director("Ron Clements")

    actors = [
        Actor("Auli'i Cravalho"),
        Actor("Dwayne Johnson"),
        Actor("Rachel House"),
        Actor("Temuera Morrison")
    ]
    for actor in actors:
        movie.add_actor(actor)
    assert movie.actors == [
        Actor("Auli'i Cravalho"),
        Actor("Dwayne Johnson"),
        Actor("Rachel House"),
        Actor("Temuera Morrison")
    ]

    movie.runtime_minutes = 107
    assert movie.runtime_minutes == 107
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}
Esempio n. 23
0
def test_get_movie_by_actor(in_memory_repo):
    assert in_memory_repo.get_movie_by_actor('Chris Pratt') == [
        Movie(
            1, 'Guardians of the Galaxy', 2014, "A group of \
                                                        intergalactic criminals are forced to work together\
                                                        to stop a fanatical warrior from taking control of\
                                                        the universe."),
        Movie(
            10, 'Passengers', 2016, "A spacecraft \
                                                                traveling to a distant colony planet and \
                                                                transporting thousands of people has a \
                                                                malfunction in its sleep chambers. As a result, \
                                                                two passengers are awakened 90 years early."
        )
    ]
    movie1 = Movie(11, '1', 2000, "a")
    movie2 = Movie(12, '2', 3000, "a")
    actor1 = Actor('a')
    movie1.add_actor(actor1)
    movie2.add_actor(actor1)
    in_memory_repo.add_movie(movie1)
    in_memory_repo.add_movie(movie2)
    assert in_memory_repo.get_movie_by_actor('a') == [movie1, movie2]
Esempio n. 24
0
def make_movie():
    movie = Movie(
        datetime.date.fromisoformat('2020-03-09'),
        "wa",
        "ga",
        "",
        "img",
        5000,
        "as,df",
        124,
        "asdf",
        44,
    )
    return movie
def test_repository_can_add_movie(in_memory_repo):
    movie = Movie(
        date.fromisoformat('2016-01-01'),
        "2016-01-01 La La Land",
        "woooow grape",
        "http.google.com",
        "sasdf",
        1,
        "me",
        123,
        "also me",
        10,
    )
    in_memory_repo.add_movie(movie)

    assert movie is movie
Esempio n. 26
0
def test_get_movie_by_director(in_memory_repo):
    assert in_memory_repo.get_movie_by_director('M. Night Shyamalan') == [
        Movie(
            3, 'Split', 2016, "Three girls are\
                                                                        kidnapped by a man with a diagnosed 23 \
                                                                        distinct personalities. They must try to \
                                                                        escape before the apparent emergence of \
                                                                        a frightful new 24th."
        )
    ]
    movie1 = Movie(11, '1', 2000, "b")
    movie2 = Movie(12, '2', 3000, "a")
    director1 = Director('a')
    movie1.director = director1
    movie2.director = director1
    in_memory_repo.add_movie(movie1)
    in_memory_repo.add_movie(movie2)
    assert in_memory_repo.get_movie_by_director('a') == [movie1, movie2]
Esempio n. 27
0
def load_movies_and_genres(data_path: str, repo: MemoryRepository):
    genres = dict()

    for data_row in read_csv_file(os.path.join(data_path, 'Data1000Movies.csv')):

        movie_key = int(data_row[0])
        movie_genres = data_row[2].split(",")
        # Add any new genres; associate the current movie with genres.
        for genre in movie_genres:
            if genre not in genres.keys():
                genres[genre] = list()
            genres[genre].append(movie_key)

        # Create Movie object.
        movie = Movie(
            date=date.fromisoformat(data_row[6]+"-01-01"),
            title=data_row[1],
            first_para=data_row[3],
            hyperlink="",

            rank=data_row[0],
            director=data_row[4],
            time=data_row[7],
            rating=data_row[8],
            actors=data_row[5],
            id=movie_key,
        image_hyperlink = "https://image.tmdb.org/t/p/w780" + data_row[14]
        )

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

    # Create Genre objects, associate them with Movies and add them to the repository.
    for genre_name in genres.keys():
        genre = Genre(genre_name)
        for movie_id in genres[genre_name]:
            movie = repo.get_movie(movie_id)
            make_genre_association(movie, genre)
        repo.add_genre(genre)
Esempio n. 28
0
    def read_csv_file(self):
        with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
            movie_file_reader = csv.DictReader(csvfile)

            index = 0
            for row in movie_file_reader:
                # Read in Title
                title = row['Title']

                # Read in Year
                release_year = int(row['Year'])
                movie = Movie(title, release_year)
                self.__dataset_of_movies.append(movie)

                # Read in description
                description = row["Description"]
                movie.description = description

                # Read in runtime
                runtime = row["Runtime (Minutes)"]
                movie.runtime_minutes = int(runtime)

                # Read in Actors
                actors = row['Actors']
                actor = actors.split(",")
                for i in actor:
                    actor = i.strip()
                    movie.add_actor(Actor(actor))
                    self.__dataset_of_actors.add(Actor(actor))

                # Read in Directors
                director = row['Director']
                movie.director = Director(director)
                self.__dataset_of_directors.add(Director(director))

                # Read in Genre
                genres = row['Genre']
                genre = genres.split(",")
                for i in genre:
                    a = i.strip()
                    movie.add_genre(Genre(a))
                    self.__dataset_of_genres.add(Genre(a))

                # Read in Rank
                rank = row["Rank"]
                movie.rank = rank

                # Read in Rating
                rating = row["Rating"]
                movie.rating = rating

                # Read in Votes
                vote = row["Votes"]
                movie.votes = vote

                # Read in revenue
                revenue = row["Revenue (Millions)"]
                movie.revenue = revenue

                # Read in meta_scores
                metascore = row["Metascore"]
                movie.metascore = metascore

                index += 1
Esempio n. 29
0
def dict_to_movie(dict):
    movie = Movie(dict.id, dict.date, dict.title, dict.first_para, dict.hyperlink)
    # Note there's no reviews or genres.
    return movie
Esempio n. 30
0
def test_repository_can_add_movie(in_memory_repo):
    movie = Movie("Your name", 2016)
    in_memory_repo.add_movie(movie)

    assert in_memory_repo.get_movie(1001) is movie