def test_repository_can_retrieve_movie():
    mem_repo = MemoryRepository()
    movie = Movie("Up", 2009, 1)
    mem_repo.add_movie(movie)
    got_movie = mem_repo.get_movie(1)

    assert got_movie == movie
def test_repository_can_get_user():
    mem_repo = MemoryRepository()
    user = User("Terry", "42069")
    mem_repo.add_user(user)
    got_user = mem_repo.get_user("Terry")

    assert got_user == user
示例#3
0
def test_can_add_review():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)
    # ["Dolittle", "Klaus", "Up"]
    movie_id = 3
    review_text = "Very good!"
    username = "******"
    rating = 5
    mem_repo.add_user(User(username, "CS235"))

    # call the service layer to add the comment
    movie_services.add_review(movie_id, review_text, rating, username,
                              mem_repo)

    # retrieve the reviews for the movie from the repository
    reviews_as_dict = movie_services.get_reviews_for_movie(movie_id, mem_repo)

    # check that the reviews inclue a review with the new review text.
    assert next((dictionary['review_text'] for dictionary in reviews_as_dict
                 if dictionary['review_text'] == review_text),
                None) is not None
def test_repository_does_not_retrieve_a_non_existent_user():
    mem_repo = MemoryRepository()
    user = User("Bob", "42069")
    mem_repo.add_user(user)
    got_user = mem_repo.get_user("Terry")

    assert got_user is None
def test_repository_does_not_retrieve_a_non_existent_movie():
    mem_repo = MemoryRepository()
    movie = Movie("Up", 2009, 1)
    mem_repo.add_movie(movie)
    got_movie = mem_repo.get_movie(7)

    assert got_movie is None
def test_repository_can_add_movie_alhpa():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)

    assert mem_repo.get_number_of_movies() == 3
    assert mem_repo.get_first_movie() is dolittle_movie
def test_repository_does_not_retrieve_a_non_existent_id():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)
    movies_by_id = mem_repo.get_movies_by_id([1, 2, 4])

    assert len(movies_by_id) == 2
    assert movies_by_id == [up_movie, klaus_movie]
def test_repository_returns_year_of_next_movie():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)
    # ["Dolittle", "Klaus", "Up"]
    next_year = mem_repo.get_year_of_next_movie(klaus_movie)

    assert next_year is None
def test_repository_does_not_retrieve_a_non_existent_title():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)
    movies_by_title = mem_repo.get_movies_by_title(["Up", "Klaus", "Frozen"])

    assert len(movies_by_title) == 2
    assert movies_by_title == [up_movie, klaus_movie]
示例#10
0
def test_authentication_with_invalid_credentials():
    mem_repo = MemoryRepository()
    new_user_name = "lumehtial"
    new_password = "******"
    auth_services.add_user(new_user_name, new_password, mem_repo)
    with pytest.raises(auth_services.AuthenticationException):
        auth_services.authenticate_user(new_user_name, '0987654321', mem_repo)
示例#11
0
def test_cannot_add_user_with_existing_name():
    mem_repo = MemoryRepository()
    user_name = "annab3ll3"
    password = "******"
    auth_services.add_user(user_name, password, mem_repo)
    with pytest.raises(auth_services.NameNotUniqueException):
        auth_services.add_user(user_name, password, mem_repo)
示例#12
0
def create_app(test_config=None):
    """Construct the core application."""

    # Create the Flask app object.
    app = Flask(__name__)

    # Configure the app from configuration-file settings.
    app.config.from_object('config.Config')
    data_path = os.path.join('CS235Flix', 'datafiles')

    if test_config is not None:
        # Load test configuration, and overrride any configuration settings.
        app.config.from_mapping(test_config)
        data_path = app.config['TEST_DATA_PATH']

    # Create the MemoryRepository implementation for a memory-based repository.
    repo.repo_instance = MemoryRepository()
    populate(data_path, repo.repo_instance)

    # Build the application - these steps require an application context.
    with app.app_context():
        # Register blueprints.
        from .home import home
        app.register_blueprint(home.home_blueprint)

        from .movies import movie_blueprint
        app.register_blueprint(movie_blueprint.movies_blueprint)

        from .authentication import authentication
        app.register_blueprint(authentication.authentication_blueprint)

        from .utilities import utilities
        app.register_blueprint(utilities.utilities_blueprint)

    return app
def test_repository_can_get_movies_by_id():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)
    # ["Dolittle", "Klaus", "Up"]
    movies_by_id = mem_repo.get_movies_by_id([1, 2, 3])

    assert len(movies_by_id) == 3
    assert movies_by_id == [up_movie, klaus_movie, dolittle_movie]
示例#14
0
def test_authentication_with_valid_credentials():
    mem_repo = MemoryRepository()
    new_user_name = "ecartman"
    new_password = "******"
    auth_services.add_user(new_user_name, new_password, mem_repo)
    try:
        auth_services.authenticate_user(new_user_name, new_password, mem_repo)
    except AuthenticationException:
        assert False
def test_repository_does_not_retrieve_a_non_existent_actor():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    the_avengers_movie = Movie("The Avengers", 2012, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    up_movie.add_actor(Actor("Ed Asner"))
    the_avengers_movie.add_actor(Actor("Robert Downey, Jr."))
    dolittle_movie.add_actor(Actor("Robert Downey, Jr."))
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(the_avengers_movie)
    mem_repo.add_movie(dolittle_movie)
    movies_by_actor = mem_repo.get_movies_by_actor(Actor("Jim Carrey"))

    assert len(movies_by_actor) == 0
    assert movies_by_actor == []
def test_repository_can_get_movies_by_genre():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    schindlers_list_movie = Movie("Schindler's List", 1993, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    up_movie.add_genre(Genre("Comedy"))
    schindlers_list_movie.add_genre(Genre("War"))
    dolittle_movie.add_genre(Genre("Comedy"))
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(schindlers_list_movie)
    mem_repo.add_movie(dolittle_movie)
    movies_by_genre = mem_repo.get_movies_by_genre(Genre("Comedy"))

    assert len(movies_by_genre) == 2
    assert movies_by_genre == [dolittle_movie, up_movie]
def test_cannot_add_movie_with_non_unique_id():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 1)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)

    assert mem_repo.get_number_of_movies() == 1
def test_repository_can_get_movies_by_rating_low_to_high():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    up_movie.external_rating = 89
    klaus_movie.external_rating = 90
    dolittle_movie.external_rating = 76
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)
    movies_by_low_to_high = mem_repo.get_movies_by_rating_low()

    assert len(movies_by_low_to_high) == 3
    assert movies_by_low_to_high == [dolittle_movie, up_movie, klaus_movie]
def test_repository_does_not_retrieve_a_non_existent_genre():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    up_movie.add_genre(Genre("Comedy"))
    klaus_movie.add_genre(Genre("Comedy"))
    dolittle_movie.add_genre(Genre("Comedy"))
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)
    movies_by_genre = mem_repo.get_movies_by_genre(Genre("War"))

    assert len(movies_by_genre) == 0
    assert movies_by_genre == []
def test_repository_can_get_movies_by_actor():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    the_avengers_movie = Movie("The Avengers", 2012, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    up_movie.add_actor(Actor("Ed Asner"))
    the_avengers_movie.add_actor(Actor("Robert Downey, Jr."))
    dolittle_movie.add_actor(Actor("Robert Downey, Jr."))
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(the_avengers_movie)
    mem_repo.add_movie(dolittle_movie)
    movies_by_actor = mem_repo.get_movies_by_actor(Actor("Robert Downey, Jr."))

    assert len(movies_by_actor) == 2
    assert movies_by_actor == [dolittle_movie, the_avengers_movie]
示例#21
0
def test_get_last_movie():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)
    movie_as_dict = movie_services.get_last_movie(mem_repo)
    # ["Dolittle", "Klaus", "Up"]

    assert movie_as_dict["ID"] == 1
示例#22
0
def test_can_add_user():
    mem_repo = MemoryRepository()
    new_user_name = "kelly007"
    new_password = "******"
    auth_services.add_user(new_user_name, new_password, mem_repo)
    user_as_dict = auth_services.get_user(new_user_name, mem_repo)
    assert user_as_dict["username"] == new_user_name

    # check that password has been encrypted.
    assert user_as_dict["password"].startswith("pbkdf2:sha256:")
def test_repository_can_get_movies_by_director():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    inside_out_movie = Movie("Inside Out", 2015, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    up_movie.director = Director("Pete Docter")
    inside_out_movie.director = Director("Pete Docter")
    dolittle_movie.director = Director("Stephen Gaghan")
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(inside_out_movie)
    mem_repo.add_movie(dolittle_movie)
    movies_by_director = mem_repo.get_movies_by_director(
        Director("Pete Docter"))

    assert len(movies_by_director) == 2
    assert movies_by_director == [inside_out_movie, up_movie]
def test_repository_does_not_retrieve_a_non_existent_director():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    inside_out_movie = Movie("Inside Out", 2015, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    up_movie.director = Director("Pete Docter")
    inside_out_movie.director = Director("Pete Docter")
    dolittle_movie.director = Director("Stephen Gaghan")
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(inside_out_movie)
    mem_repo.add_movie(dolittle_movie)
    movies_by_director = mem_repo.get_movies_by_director(
        Director("Sergio Pablos"))

    assert len(movies_by_director) == 0
    assert movies_by_director == []
示例#25
0
def test_cannot_get_movie_with_non_existent_id():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)
    # ["Dolittle", "Klaus", "Up"]
    movie_id = 7

    with pytest.raises(movie_services.NonExistentMovieException):
        movie_services.get_movie(movie_id, mem_repo)
示例#26
0
def test_get_movies_by_year_with_multiple_years():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    sonic_movie = Movie("Sonic the Hedgehog", 2020, 4)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)
    mem_repo.add_movie(sonic_movie)

    target_year = 2019
    movies_as_dict, prev_date, next_date = movie_services.get_movies_by_year(
        target_year, mem_repo)

    assert len(movies_as_dict) == 2
    movie_ids = [movie["ID"] for movie in movies_as_dict]
    assert {2, 3}.issubset(movie_ids)

    assert prev_date == 2009
    assert next_date == 2020
示例#27
0
def test_get_movies_by_year_with_non_existent_date():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)

    target_year = 2020
    movies_as_dict, prev_date, next_date = movie_services.get_movies_by_year(
        target_year, mem_repo)

    assert len(movies_as_dict) == 0
示例#28
0
def test_can_get_movie():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)
    # ["Dolittle", "Klaus", "Up"]
    movie_id = 2
    movie_as_dict = movie_services.get_movie(movie_id, mem_repo)

    assert movie_as_dict["ID"] == movie_id
    assert movie_as_dict["release_year"] == klaus_movie.release_year
    assert movie_as_dict["title"] == "Klaus"
示例#29
0
def test_get_movies_by_year_with_one_year():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)

    target_year = 2009
    movies_as_dict, prev_date, next_date = movie_services.get_movies_by_year(
        target_year, mem_repo)

    assert len(movies_as_dict) == 1
    assert movies_as_dict[0]["ID"] == 1

    assert prev_date is None
    assert next_date == 2019
示例#30
0
def test_get_movies_by_id():
    mem_repo = MemoryRepository()
    up_movie = Movie("Up", 2009, 1)
    klaus_movie = Movie("Klaus", 2019, 2)
    dolittle_movie = Movie("Dolittle", 2019, 3)
    mem_repo.add_movie(up_movie)
    mem_repo.add_movie(klaus_movie)
    mem_repo.add_movie(dolittle_movie)

    target_movie_ids = [2, 1, 4, 5]
    movies_as_dict = movie_services.get_movies_by_ids(target_movie_ids,
                                                      mem_repo)

    # check that 2 movies were returned from the query
    assert len(movies_as_dict) == 2

    # check that the movie ids returned were 1 and 2
    movie_ids = [movie["ID"] for movie in movies_as_dict]
    assert {1, 2}.issubset(movie_ids)