Exemplo n.º 1
0
def test_cannot_add_review_by_unknown_user(in_memory_repo):
    movie_id = 3
    review_text = 'The loonies are stripping the supermarkets bare!'
    username = '******'

    # Call the service layer to attempt to add the review.
    with pytest.raises(news_services.UnknownUserException):
        news_services.add_review(movie_id, review_text, username,
                                 in_memory_repo)
Exemplo n.º 2
0
def test_cannot_add_review_for_non_existent_movie(in_memory_repo):
    movie_id = 10000
    review_text = "helllllo"
    username = '******'

    # Call the service layer to attempt to add the review.
    with pytest.raises(news_services.NonExistentMovieException):
        news_services.add_review(movie_id, review_text, username,
                                 in_memory_repo)
Exemplo n.º 3
0
def 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 an 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)

        # Cause the web browser to display the page of all movies that have the same date as the reviewed movie,
        # and display all reviews, including the new review.
        return redirect(
            url_for('news_bp.movies_by_date',
                    date=movie['date'],
                    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('news/review_on_movie.html',
                           title='Edit movie',
                           movie=movie,
                           form=form,
                           handler_url=url_for('news_bp.review_on_movie'),
                           selected_movies=utilities.get_selected_movies(),
                           genre_urls=utilities.get_genres_and_urls())
Exemplo n.º 4
0
def test_can_add_review(in_memory_repo):
    movie_id = 3
    review_text = 'The loonies are stripping the supermarkets bare!'
    username = '******'

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

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

    # Check that the reviews include 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