Пример #1
0
def comment_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 article id, when subsequently called with a HTTP POST request, the article id remains in the
    # form.
    form = CommentForm()

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

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

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

        # Cause the web browser to display the page of all articles that have the same date as the commented article,
        # and display all comments, including the new comment.
        return redirect(
            url_for('movies_bp.movies_by_rank',
                    rank=movie['rank'],
                    view_comments_for=movie_id))

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

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

    # For a GET or an unsuccessful POST, retrieve the article to comment in dict form, and return a Web page that allows
    # the user to enter a comment. The generated Web page includes a form object.
    movie = services.get_movie(movie_id, repo.repo_instance)
    return render_template(
        'news/comment_on_article.html',
        title='Edit movie',
        movie=movie,
        form=form,
        handler_url=url_for('movies_bp.comment_on_movie'),
    )
Пример #2
0
def show_movie(hyperlink):
    rev_tr = False
    mov = services.get_movie(hyperlink)
    reviews = mov.get_reviews()
    if not len(reviews):
        rev_tr = True
    return render_template('movie/movie_disp.html', rev_tr=rev_tr, reviews=reviews, title="Movie Details", movie=mov, watchlist=utilities.get_watchlist())
Пример #3
0
def add_to_list(movie):
    mov = services.get_movie(movie)
    try:
        if 'username' in session:
            user = services.get_user(session['username'])
            user.watch_movie(mov)
    except ValueError:
        session.clear()
    except AttributeError:
        session.clear()
    return show_movie(mov.hyperlink)
Пример #4
0
def add_review_v2(hyperlink):
    text = request.form['text']
    if text == "":
        return show_movie(hyperlink)
    else:
        try:
            mov = services.get_movie(hyperlink)
            services.add_review_for_current_user(mov, text, session['username'])
            return show_movie(hyperlink)
        except ValueError:
            session.clear()
            return redirect(url_for('home_bp.home'))
Пример #5
0
def test_can_get_movie(in_memory_repo):
    movie_rank = 1

    movie_as_dict = news_services.get_movie(movie_rank, in_memory_repo)

    assert movie_as_dict['rank'] == movie_rank
    assert movie_as_dict['title'] == 'Guardians of the Galaxy'
    assert movie_as_dict['description'] == 'A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.'
    assert movie_as_dict['year'] == 2014
    assert movie_as_dict['duration'] == 121
    assert movie_as_dict['rating'] == 8.1
    assert len(movie_as_dict['comments']) == 3
    assert movie_as_dict['votes'] == 757074
    assert movie_as_dict['revenue'] == '333.13'
    assert movie_as_dict['metascore'] =='76'
Пример #6
0
def test_cannot_get_movie_with_non_existent_rank(in_memory_repo):
    movie_rank = 1001

    # Call the service layer to attempt to retrieve the movie.
    with pytest.raises(news_services.NonExistentMovieException):
        news_services.get_movie(movie_rank, in_memory_repo)