Exemplo n.º 1
0
def test_cannot_add_review_by_unknown_user(in_memory_repo):
    movie_rank = 1
    review_text = 'That was such a cool movie!'
    rating = 9
    username = '******'

    # Call the service layer to attempt to add the review.
    with pytest.raises(movies_services.UnknownUserException):
        movies_services.add_review(movie_rank, review_text, rating, username,
                                   in_memory_repo)
Exemplo n.º 2
0
def test_cannot_add_review_for_non_existent_movie(in_memory_repo):
    movie_rank = 0
    review_text = "I do not like this movie..."
    rating = 1
    username = '******'

    # Call the service layer to attempt to add the review.
    with pytest.raises(movies_services.NonExistentMovieException):
        movies_services.add_review(movie_rank, review_text, rating, username,
                                   in_memory_repo)
Exemplo n.º 3
0
def test_cannot_add_review_by_unknown_user(populated_memory_repo):
    movie_title = "Guardians of the Galaxy"
    movie_year = 2014
    review_text = 'This was pretty awesome'
    rating = 9
    username = '******'

    # Call the service layer to attempt to add the review.
    with pytest.raises(services.UnknownUserException):
        services.add_review(movie_title, movie_year, username, review_text,
                            rating, populated_memory_repo)
Exemplo n.º 4
0
def test_cannot_add_review_for_non_existent_movie(populated_memory_repo):
    movie_title = "Guardians of the Universe"
    movie_year = 2022
    review_text = 'This was pretty awesome'
    username = '******'
    rating = 9

    # Call the service layer to attempt to add the review.
    with pytest.raises(services.NonExistentMovieException):
        services.add_review(movie_title, movie_year, username, review_text,
                            rating, populated_memory_repo)
Exemplo n.º 5
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 a movie rank, when subsequently called with a HTTP POST request, the movie rank 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 rank, representing the reviewed movie, from the form.
        movie_rank = int(form.movie_rank.data)

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

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

        return redirect(
            url_for('movies_bp.movie_after_review',
                    view_reviews_for=movie_rank,
                    movie_rank=movie_rank))

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

        # Store the movie rank in the form.
        form.movie_rank.data = movie_rank
    else:
        # Request is a HTTP POST where form validation has failed.
        # Extract the movie rank of the movie being reviewed from the form.
        movie_rank = int(form.movie_rank.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_rank, repo.repo_instance)
    return render_template('movies/review_on_movie.html',
                           title='Review Movie',
                           movie=movie,
                           form=form,
                           handler_url=url_for('movies_bp.review_on_movie'),
                           featured_movies=utilities.get_featured_movies(),
                           genre_urls=utilities.get_genres_and_urls())
Exemplo n.º 6
0
def test_can_add_review(in_memory_repo):
    movie_rank = 1000
    review_text = 'Maybe there were ten lives?'
    rating = 8
    username = '******'

    # Call the service layer to add the review.
    movies_services.add_review(movie_rank, review_text, rating, username,
                               in_memory_repo)

    # Retrieve the reviews for the movie from the repo.
    reviews_as_dict = movies_services.get_reviews_for_movie(
        movie_rank, 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
Exemplo n.º 7
0
def test_can_add_review(populated_memory_repo):
    movie_title = "Guardians of the Galaxy"
    movie_year = 2014
    review_text = 'This was pretty awesome'
    username = '******'
    rating = 9

    # Call the service layer to add the review.
    services.add_review(movie_title, movie_year, username, review_text, rating,
                        populated_memory_repo)

    reviews_as_dict = services.get_reviews_for_movie(movie_title, movie_year,
                                                     populated_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
Exemplo n.º 8
0
def review_movie():
    # Get username
    username = session['username']

    form = ReviewForm()

    if form.validate_on_submit():  # Successful POST
        # Get movie details
        movie_title = form.movie_title.data
        movie_year = int(form.movie_year.data)

        # Add new review
        services.add_review(movie_title, movie_year, username,
                            form.review.data, form.rating.data,
                            repo.repo_instance)

        # Refresh page
        return redirect(
            url_for('movies_bp.movie_details',
                    title=movie_title,
                    release_year=movie_year))

    if request.method == 'GET':
        movie_title = request.args.get('title')
        movie_year = request.args.get('release_year', type=int)

        form.movie_title.data = movie_title
        form.movie_year.data = movie_year
    else:
        movie_title = form.movie_title.data
        movie_year = int(form.movie_year.data)

    movie = services.get_movie_by_title_and_year(movie_title, movie_year,
                                                 repo.repo_instance)
    director = {
        'full_name':
        movie['director'],
        'url':
        url_for('movies_bp.movies_by_search_query',
                search_by='director',
                search_query=movie['director'],
                page=1)
    }
    actors = [{
        'full_name':
        actor,
        'url':
        url_for('movies_bp.movies_by_search_query',
                search_by='actor',
                search_query=actor,
                page=1)
    } for actor in movie['actors']]
    genres = [{
        'name':
        genre,
        'url':
        url_for('movies_bp.movies_by_search_query',
                search_by='genre',
                search_query=genre,
                page=1)
    } for genre in movie['genres']]

    return render_template('movies/review_movie.html',
                           movie=movie,
                           director=director,
                           actors=actors,
                           genres=genres,
                           form=form,
                           handler_url=url_for('movies_bp.review_movie'))