Beispiel #1
0
def test_cannot_add_review_by_unknown_user(in_memory_repo):
    movie_id = 432
    review_text = 'The movie was terrible, I think no one should watch this movie'
    username = '******'

    # Call the service layer to attempt to add the review.
    with pytest.raises(movie_library_services.UnknownUserException):
        movie_library_services.add_review(movie_id, review_text, username, in_memory_repo)
Beispiel #2
0
def test_cannot_add_review_by_unknown_user(in_memory_repo):
    movie_id = 10
    review_text = 'I hate this movie'
    username = '******'

    with pytest.raises(movie_library_services.UnknownUserException):
        movie_library_services.add_review(movie_id, review_text, username,
                                          in_memory_repo)
Beispiel #3
0
def test_cannot_add_review_by_unknown_user(in_memory_repo):
    movie_id = 10
    review_text = 'I hate this movie. Bad acting!!!'
    username = '******'

    # Call the service layer to attempt to add the review.
    with pytest.raises(movie_library_services.UnknownUserException):
        movie_library_services.add_review(movie_id, review_text, username,
                                          in_memory_repo)
Beispiel #4
0
def test_cannot_add_review_by_unknown_user(in_memory_repo):
    movie_id = 10
    review_text = 'Fantasticccc!!!'
    username = '******'

    # Call the service layer to attempt to add the review.
    with pytest.raises(movie_library_services.UnknownUserException):
        movie_library_services.add_review(movie_id, review_text, username,
                                          in_memory_repo)
Beispiel #5
0
def test_cannot_add_review_for_non_existent_movie(in_memory_repo):
    movie_id = 5000
    review_text = "Great film!"
    new_username = '******'
    new_password = '******'
    auth_services.add_user(new_username, new_password, in_memory_repo)

    with pytest.raises(movie_library_services.NonExistentMovieException):
        movie_library_services.add_review(movie_id, review_text, new_username,
                                          in_memory_repo)
Beispiel #6
0
def test_cannot_add_review_for_non_existent_movie(in_memory_repo):
    movie_id = 5000
    review_text = "The film was so good"
    new_username = '******'
    new_password = '******'
    auth_services.add_user(new_username, new_password, in_memory_repo)

    # Call the service layer to attempt to add the comment.
    with pytest.raises(movie_library_services.NonExistentMovieException):
        movie_library_services.add_review(movie_id, review_text, new_username, in_memory_repo)
Beispiel #7
0
def test_cannot_add_review_for_non_existent_movie(in_memory_repo):
    movie_id = 5000
    review_text = "Great film!"
    new_username = '******'
    new_password = '******'
    auth_services.add_user(new_username, new_password, in_memory_repo)

    # Call the service layer to attempt to add the comment.
    with pytest.raises(movie_library_services.NonExistentMovieException):
        movie_library_services.add_review(movie_id, review_text, new_username,
                                          in_memory_repo)
Beispiel #8
0
def test_cannot_add_review_for_non_existent_movie(in_memory_repo):
    movie_id = 5000
    review_text = "fantastic film!"
    new_username = '******'
    new_password = '******'
    auth_services.add_user(new_username, new_password, in_memory_repo)

    # Call the service layer to attempt to add the comment.
    with pytest.raises(movie_library_services.NonExistentMovieException):
        movie_library_services.add_review(movie_id, review_text, new_username,
                                          in_memory_repo)
Beispiel #9
0
def write_review_on_movie():
    # Obtain the username of the currently logged in user.
    username = session['username']

    # Create form. The form maintains state, e.g. when this method is called with a HTTP GET request and populates
    # the form with a movie id, when subsequently called with a HTTP POST request, the movie id remains in the
    # form.
    form = ReviewForm()

    if form.validate_on_submit():
        # Successful POST, i.e. the review text has passed data validation.
        # Extract the movie id, representing the reviewed movie, from the form.
        movie_id = int(form.movie_id.data)

        # Use the service layer to store the new review.
        services.add_review(movie_id, form.review.data, username,
                            repo.repo_instance)

        # Retrieve the movie in dict form.
        movie = services.get_movie(movie_id, repo.repo_instance)

        # display all reviews, including the new review.
        return redirect(
            url_for('movie_library_bp.movies_by_rank',
                    id=movie_id,
                    view_reviews_for=movie_id))

    if request.method == 'GET':
        # Request is a HTTP GET to display the form.
        # Extract the movie_id, representing the movie to review, from a query parameter of the GET request.
        movie_id = int(request.args.get('movie'))

        # Store the movie id in the form.
        form.movie_id.data = movie_id
    else:
        # Request is a HTTP POST where form validation has failed.
        # Extract the movie id of the movie being reviewed from the form.
        movie_id = int(form.movie_id.data)

    # For a GET or an unsuccessful POST, retrieve the movie to review in dict form, and return a Web page that allows
    # the user to enter a review. The generated Web page includes a form object.
    movie = services.get_movie(movie_id, repo.repo_instance)
    return render_template(
        'movie_library/write_review_for_movie.html',
        title='Edit Movie',
        movie=movie,
        form=form,
        handler_url=url_for('movie_library_bp.write_review_on_movie'),
    )
Beispiel #10
0
def test_get_reviews_for_movie(in_memory_repo):
    movie_id = 1
    review_text = "Great film!"
    new_username = '******'
    new_password = '******'
    auth_services.add_user(new_username, new_password, in_memory_repo)
    movie_library_services.add_review(movie_id, review_text, new_username,
                                      in_memory_repo)

    reviews_as_dict = movie_library_services.get_reviews_for_movie(
        1, in_memory_repo)
    assert len(reviews_as_dict) == 1

    movie_ids = [review['movie_id'] for review in reviews_as_dict]
    movie_ids = set(movie_ids)
    assert 1 in movie_ids and len(movie_ids) == 1
Beispiel #11
0
def test_get_reviews_for_movie(in_memory_repo):
    movie_id = 1
    review_text = "Great film!"
    new_username = '******'
    new_password = '******'
    auth_services.add_user(new_username, new_password, in_memory_repo)
    movie_library_services.add_review(movie_id, review_text, new_username, in_memory_repo)

    reviews_as_dict = movie_library_services.get_reviews_for_movie(1, in_memory_repo)
    # Check that 1 review is returned for movie with id 1.
    assert len(reviews_as_dict) == 1

    # Check that the review relates to the movie whose id is 1.
    movie_ids = [review['movie_id'] for review in reviews_as_dict]
    movie_ids = set(movie_ids)
    assert 1 in movie_ids and len(movie_ids) == 1
Beispiel #12
0
def test_can_add_review(in_memory_repo):
    new_username = '******'
    new_password = '******'
    auth_services.add_user(new_username, new_password, in_memory_repo)

    movie_id = 3
    review_text = 'I like this movie'

    movie_library_services.add_review(movie_id, review_text, new_username,
                                      in_memory_repo)

    reviews_as_dict = movie_library_services.get_reviews_for_movie(
        movie_id, in_memory_repo)

    assert next((dictionary['review_text'] for dictionary in reviews_as_dict
                 if dictionary['review_text'] == review_text),
                None) is not None
Beispiel #13
0
def test_can_add_review(in_memory_repo):
    new_username = '******'
    new_password = '******'
    auth_services.add_user(new_username, new_password, in_memory_repo)

    movie_id = 3
    review_text = 'This was the worse movie ever'

    # Call the service layer to add the review.
    movie_library_services.add_review(movie_id, review_text, new_username, in_memory_repo)

    # Retrieve the review for the movie from the repository.
    reviews_as_dict = movie_library_services.get_reviews_for_movie(movie_id, in_memory_repo)

    # Check that the review includes 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
Beispiel #14
0
def test_can_add_review(in_memory_repo):
    new_username = '******'
    new_password = '******'
    auth_services.add_user(new_username, new_password, in_memory_repo)

    movie_id = 3
    review_text = 'greatest of all time!'

    # Call the service layer to add the review.
    movie_library_services.add_review(movie_id, review_text, new_username,
                                      in_memory_repo)

    # Retrieve the review for the movie from the repository.
    reviews_as_dict = movie_library_services.get_reviews_for_movie(
        movie_id, in_memory_repo)

    # Check that the review includes 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