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_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_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_actors():
    movie1 = Movie("Spirited Away", 2000)
    movie2 = Movie("Your Name", 2000)
    movie3 = Movie("Batman", 2000)
    movie4 = Movie(None, None)

    movie1.actors = [
        Actor("Jack Huang"),
        Actor("James Huang"),
        Actor("Ron Huang"),
        Actor("Jane Tang")
    ]
    assert movie1.actors == [
        Actor("Jack Huang"),
        Actor("James Huang"),
        Actor("Ron Huang"),
        Actor("Jane Tang")
    ]
    movie2.actors = [
        Actor("Jack Huang"), "James Huang",
        Actor("Ron Huang"), 123456
    ]
    assert movie2.actors == []
    movie3.actors = Actor("Jack Huang")
    assert movie3.actors == [Actor("Jack Huang")]
    movie4.actors = "Jack Huang"
    assert movie4.actors == []
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_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_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_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_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
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 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"
def test_runtime():
    movie1 = Movie("Spirited Away", 2000)
    movie2 = Movie("Your Name", 2000)
    movie3 = Movie("Batman", 2000)
    movie4 = Movie(None, None)

    movie1.runtime_minutes = 150
    assert movie1.runtime_minutes == 150
    movie2.runtime_minutes = 1
    assert movie2.runtime_minutes == 1
    movie3.runtime_minutes = "150"
    assert movie3.runtime_minutes == 0
    movie4.runtime_minutes = None
    assert movie4.runtime_minutes == 0
def test_genres():
    movie1 = Movie("Spirited Away", 2000)
    movie2 = Movie("Your Name", 2000)
    movie3 = Movie("Batman", 2000)
    movie4 = Movie(None, None)

    movie1.genres = [Genre("Comedy"), Genre("Horror"), Genre("Sci-fi")]
    assert movie1.genres == [Genre("Comedy"), Genre("Horror"), Genre("Sci-fi")]
    movie2.genres = [Genre("Comedy"), Genre("Horror"), Genre("Sci-fi"), 12345]
    assert movie2.genres == []
    movie3.genres = Genre("Comedy")
    assert movie3.genres == [Genre("Comedy")]
    movie4.genres = "Comedy"
    assert movie4.genres == []
def test_change_description():
    movie1 = Movie("Spirited Away", 2000)
    movie2 = Movie("Your Name", 2000)
    movie3 = Movie("Batman", 2000)
    movie4 = Movie(None, None)

    movie1.description = "Best movie"
    movie2.description = ""
    movie3.description = 123124124
    movie4.description = None

    assert movie1.description == "Best movie"
    assert movie2.description == ""
    assert movie3.description == ""
    assert movie4.description == ""
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_director():
    movie1 = Movie("Spirited Away", 2000)
    movie2 = Movie("Your Name", 2000)
    movie3 = Movie("Batman", 2000)
    movie4 = Movie(None, None)

    movie1.director = Director("BB Huang")
    assert movie1.director == Director("BB Huang")
    movie1.director = Director("Jack Huang")
    assert movie1.director == Director("Jack Huang")
    movie2.director = "Jack Huang"
    assert movie2.director == None
    movie3.director = 123456
    assert movie3.director == None
    movie3.director = None
    assert movie4.director == None
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))
Example #20
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
Example #21
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
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))
Example #23
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_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]
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)
    ]
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")]
Example #27
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_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")]
def test_get_movie_by_genre(in_memory_repo):
    assert in_memory_repo.get_movie_by_genre('Action') == [
        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(
            5, 'Suicide Squad', 2016, "A secret government agency\
                                                            recruits some of the most dangerous incarcerated \
                                                            super-villains to form a defensive task force. \
                                                            Their first mission: save the world from the apocalypse."
        ),
        Movie(
            6, 'The Great Wall', 2016, "European mercenaries \
                                                           searching for black powder become embroiled in the defense\
                                                            of the Great Wall of China against a horde of monstrous\
                                                             creatures."),
        Movie(
            9, 'The Lost City of Z', 2016, "A true-life drama, \
                                                           centering on British explorer Col. Percival Fawcett, who\
                                                            disappeared while searching for a mysterious city in the\
                                                             Amazon in the 1920s."
        )
    ]
    movie1 = Movie(11, '1', 2000, "a")
    movie2 = Movie(12, '2', 3000, "a")
    genre1 = Genre('a')
    movie1.add_genre(genre1)
    movie2.add_genre(genre1)
    in_memory_repo.add_movie(movie1)
    in_memory_repo.add_movie(movie2)
    assert in_memory_repo.get_movie_by_genre('a') == [movie1, movie2]
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}