Пример #1
0
def test_database_repository_wont_add_movie_that_exists(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    the_ropos_movie_list = repo.get_movies()
    genre_str_list = 'Action,Adventure,Biography'
    actor_str_list = 'Charlie Hunnam, Robert Pattinson, Sienna Miller, Tom Holland'
    description = '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.'
    director_str = 'James Gray'
    a_new_movie = Movie('The Lost City of Z', 2016)
    a_new_movie.director = Director('James Gray')
    a_new_movie.runtime_minutes = 141
    count = 0
    for gen in the_ropos_movie_list:
        if gen == a_new_movie:
            count += 1
    assert count == 1
    with pytest.raises(IntegrityError):
        repo.add_movie(Movie('The Lost City of Z', 2016))
    the_ropos_movie_list = repo.get_movies()
    for gen in the_ropos_movie_list:
        if gen == Movie('The Lost City of Z', 2016):
            b_movie = gen
    genre_list = [Genre(x.strip()) for x in genre_str_list.split(',')]
    actors_list = [Actor(x.strip()) for x in actor_str_list.split(',')]
    assert b_movie.description == description
    assert b_movie.director == Director(director_str)
    assert len(b_movie.genres) == len(genre_list)
    for genre in genre_list:
        assert genre in b_movie.genres
    assert len(b_movie.actors) == len(actors_list)
    for actor in actors_list:
        assert actor in b_movie.actors
Пример #2
0
def test_database_repository_can_get_directors(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    a_director_list = repo.get_directors()
    expected_director = [
        Director("Ridley Scott"),
        Director('Denis Villeneuve')
    ]
    assert len(a_director_list) == 644
    for director in expected_director:
        assert director in a_director_list
Пример #3
0
def test_database_repository_wont_add_director_that_exists(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    the_ropos_director_list = repo.get_directors()
    count = 0
    for gen in the_ropos_director_list:
        if gen == Director('David Yates'):
            count += 1
    assert count == 1
    with pytest.raises(IntegrityError):
        repo.add_director(Director('David Yates'))
Пример #4
0
def test_database_repository_can_add_director(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    the_ropos_director_list = repo.get_directors()
    count = 0
    for gen in the_ropos_director_list:
        if gen == Director('Mike Wastheman'):
            count += 1
    assert count == 0
    repo.add_director(Director('Mike Wastheman'))
    the_ropos_director_list = repo.get_directors()
    assert Director('Mike Wastheman') in the_ropos_director_list
Пример #5
0
def test_load_movie(empty_session):
    movie_title = 'Passengers'
    genre_list = ['Adventure', 'Drama', 'Romance']
    director = 'Morten Tyldum'
    description = '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.'
    actors = [
        'Jennifer Lawrence', 'Chris Pratt', 'Michael Sheen',
        'Laurence Fishburne'
    ]
    run_time = 116
    release_year = 2016
    insert_movie(empty_session, movie_title, director, genre_list, actors,
                 description, release_year, run_time)
    a_movie = Movie(movie_title, release_year)
    a_movie.actors = [Actor(name) for name in actors]
    a_movie.description = description
    a_movie.director = Director(director)
    a_movie.genres = [Genre(name) for name in genre_list]
    a_movie.runtime_minutes = run_time
    b_movie = empty_session.query(Movie).filter(
        Movie._title == 'Passengers').one()
    assert b_movie == a_movie
    assert b_movie.director == a_movie.director
    assert b_movie.runtime_minutes == a_movie.runtime_minutes
    assert a_movie.description == b_movie.description
    assert len(a_movie.actors) == len(b_movie.actors)
    assert len(a_movie.genres) == len(b_movie.genres)
    for genre in a_movie.genres:
        assert genre in b_movie.genres
    for actor in a_movie.actors:
        assert actor in b_movie.actors
Пример #6
0
def test_database_repository_can_add_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    new_movie = Movie('Guardians of Goatboy', 1914)
    new_movie.genres = [Genre('Action'), Genre('Sci-Fi')]
    new_movie.description = 'Adventures of Space soldiers sworn to protect a boy that is also a goat.'
    new_movie.director = Director("Ben Span")
    new_movie.actors = [Actor('Chris Pratt'), Actor("Bill Clinton")]
    new_movie.runtime_minutes = 400
    the_repos_movie_list = repo.get_movies()
    count = 0
    for movie in the_repos_movie_list:
        if movie == Movie('Guardians of Goatboy', 1914):
            count += 1
    assert count == 0
    repo.add_movie(new_movie)
    the_repos_movie_list = repo.get_movies()
    count = 0
    for movie in the_repos_movie_list:
        if movie == Movie('Guardians of Goatboy', 1914):
            b_movie = movie
            count += 1
    assert count == 1
    assert b_movie.description == new_movie.description
    assert b_movie.director == new_movie.director
    assert b_movie.runtime_minutes == new_movie.runtime_minutes
    assert len(b_movie.genres) == len(new_movie.genres)
    for genre in new_movie.genres:
        assert genre in b_movie.genres
    assert len(b_movie.actors) == len(new_movie.actors)
    for actor in new_movie.actors:
        assert actor in b_movie.actors
Пример #7
0
def get_movies_by_director(director_name: str, repo: 'AbstractRepository') -> list:
    a_director = Director(director_name)
    movie_list = list()
    for movie in repo.get_movies():
        if a_director == movie.director:
            movie_list.append(movie)
    return movie_list
Пример #8
0
 def read_csv_file(self) -> None:
     with open(self.__filename, encoding='utf-8-sig') as file_data:
         reader = csv.DictReader(file_data)
         self.__dataset_of_movies = list()
         for row in reader:
             new_movie = Movie(row['Title'], int(row['Year']))
             new_movie.description = row['Description']
             new_movie.genres = [
                 Genre(i.strip()) for i in row['Genre'].split(',')
             ]
             new_movie.actors = [
                 Actor(i.strip()) for i in row['Actors'].split(',')
             ]
             new_movie.director = Director(row['Director'].strip())
             if row['Runtime (Minutes)'].isdigit():
                 new_movie.runtime_minutes = int(row['Runtime (Minutes)'])
             self.__dataset_of_movies.append(new_movie)
             for i in new_movie.genres:
                 self.add_genre(i)
             for i in new_movie.actors:
                 self.add_actor(i)
             self.add_director(new_movie.director)
Пример #9
0
def test_load_review(empty_session):
    movie_title = 'Passengers'
    genre_list = ['Adventure', 'Drama', 'Romance']
    director = 'Morten Tyldum'
    description = '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.'
    actors = [
        'Jennifer Lawrence', 'Chris Pratt', 'Michael Sheen',
        'Laurence Fishburne'
    ]
    run_time = 116
    release_year = 2016
    insert_movie(empty_session, movie_title, director, genre_list, actors,
                 description, release_year, run_time)
    a_movie = Movie(movie_title, release_year)
    a_movie.actors = [Actor(name) for name in actors]
    a_movie.description = description
    a_movie.director = Director(director)
    a_movie.genres = [Genre(name) for name in genre_list]
    a_movie.runtime_minutes = run_time
    users = [["jill", '98765432'], ['jim', 'mjydfefs']]
    insert_users(empty_session, users)
    review_text = 'was definitely a 5'
    rating = 5
    result = empty_session.execute(
        f"SELECT id from users WHERE username = '******'").fetchone()
    insert_review(empty_session, movie_title, release_year, result[0],
                  review_text, rating)
    users = empty_session.query(User).all()
    found_review = None
    for user in users:
        if user.username == 'jim':
            for review in user.reviews:
                if review.movie == Movie(movie_title, release_year):
                    found_review = review
                    break
    assert found_review.review_text == 'was definitely a 5'
    assert found_review.rating == 5
Пример #10
0
def test_load_director(empty_session):
    dirctor_list = ["Ridley Scott", 'Stephen Burg']
    insert_directors(empty_session, dirctor_list)
    expected = [Director('Ridley Scott'), Director('Stephen Burg')]
    assert empty_session.query(Director).all() == expected
Пример #11
0
def test_repository_can_get_directors(a_memory_repo):
    a_director_list = a_memory_repo.get_directors()
    a_director = Director("Ridley Scott")
    assert a_director in a_director_list
def test_create_Director():
    burg = Director('Stephen burg')
    assert burg.__repr__() == f'<Director Stephen burg>'
def test_add_director():
    direc = Director("John Candy")
    movie = Movie("Moana", 2016)
    movie.director = direc
    assert movie.director.__repr__() == f'<Director John Candy>'
def test_compare_Director():
    burg = Director('Stephen burg')
    director = Director('Stephen burg')
    director2 = Director('Tom')
    assert (burg == director) == True
    assert (director2 == director) == False