Example #1
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 comment text has passed data validation.
        # Extract the movie id, representing the reviewed movie, from the form.
        movie_id = int(form.movie_id.data)
        rating = int(form.rating.data)

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

        # Retrieve the movie in dict form.
        movie = services.get_movie(movie_id, repo.repo_instance)
        release_year = movie['release_year']
        # genre_name = movie['genres'][0]
        print(movie['reviews'][0]['timestamp'])
        # Cause the web browser to display the page of all movies that have the same genre as the reviewed movie, and
        # display all reviews, including the new review.

        # return redirect(url_for('movies_bp.movies_by_release_year', year=release_year, view_reviews_for=movie_id))
        return redirect(
            url_for('movies_bp.search_movies_by_title', title=movie['title']))

    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 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 movie to review in dict form, and return a Web page that allows
    # the user to enter a review. The generated Web page include a form object.
    movie = services.get_movie(movie_id, repo.repo_instance)

    return render_template(
        'movies/review_on_movie.html',
        title='Edit movie',
        movie=movie,
        form_review=form,
        form=SearchForm(),
        handler_url_review=url_for('movies_bp.review_on_movie'),
        handler_url=url_for("movies_bp.search"),
        selected_movies=utilities.get_selected_movies(),
        genre_urls=utilities.get_genres_and_urls(),
        title_form=SearchByTitleForm(),
        handler_url_title=url_for('movies_bp.search_by_title'),
    )
Example #2
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 article id, when subsequently called with a HTTP POST request, the article id remains in the
    # form.
    form = ReviewForm()

    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_review(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.review_on_movie',
                    date=movie['year'],
                    view_reviews_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(
        'movies/review_on_movie.html',
        title='Review movie',
        movie=movie,
        form=form,
        handler_url=url_for('movie_bp.review_on_movie'),
        selected_articles=utilities.get_selected_movies(),
        genre_urls=utilities.get_genres_and_urls(),
        actor_urls=utilities.get_actors_and_urls(),
        director_urls=utilities.get_directors_and_urls(),
    )
Example #3
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)
Example #4
0
def review_movie():
    # obatin the username of the currently logged in user
    username = session['username']

    # create form
    form = ReviewForm()

    if form.validate_on_submit():
        # successful POST
        # extract movie id
        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, 0,
                            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('movies_bp.movies_by_date',
                    year=movie['release_year'],
                    view_reviews_for=movie_id))

    if request.method == 'GET':
        # request is a HTTP GET to display the form
        # extract the movie
        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 for 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('movies/review_movie.html',
                           title='Edit movie',
                           movie=movie,
                           form=form,
                           handler_url=url_for('movies_bp.review_movie'),
                           selected_movies=utilities.get_selected_movies(),
                           genre_urls=utilities.get_genres_and_urls())
Example #5
0
def test_can_get_a_movie(in_memory_repo):
    movie_id = 1
    movie_as_dict = movies_services.get_movie(movie_id=movie_id,
                                              repo=in_memory_repo)

    assert movie_as_dict['id'] == movie_id
    assert movie_as_dict['title'] == 'Guardians of the Galaxy'
    assert movie_as_dict['release_year'] == 2014
    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['director'] == 'James Gunn'
    assert movie_as_dict['runtime_minutes'] == 121

    actor_fullnames = [
        dictionary['actor_fullname'] for dictionary in movie_as_dict['actors']
    ]
    assert 'Chris Pratt' in actor_fullnames
    assert 'Vin Diesel' in actor_fullnames
    assert 'Bradley Cooper' in actor_fullnames
    assert 'Zoe Saldana' in actor_fullnames

    genres = [
        dictionary['genre_name'] for dictionary in movie_as_dict['genres']
    ]
    assert 'Action' in genres
    assert 'Adventure' in genres
    assert 'Sci-Fi' in genres
Example #6
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"
Example #7
0
def test_can_get_movie(in_memory_repo):
    movie_id = 2

    movie_as_dict = movie_services.get_movie(movie_id, in_memory_repo)

    assert movie_as_dict['id'] == movie_id
    assert movie_as_dict['year'] == date.fromisoformat('2012')
    assert movie_as_dict['title'] == 'Prometheus'
    assert movie_as_dict[
        'description'] == 'Following clues to the origin of mankind, a team finds a structure on a distant moon, but they soon realize they are not alone.'
    assert movie_as_dict['director'] == 'Ridley Scott'
    assert movie_as_dict['runtime_minutes'] == 124
    assert len(movie_as_dict['reviews']) == 0
    assert movie_as_dict['rating'] == 7
    assert movie_as_dict['votes'] == 485820
    assert movie_as_dict['revenue_millions'] == 126.46
    assert movie_as_dict['meta_score'] == 65
Example #8
0
def movie_detail(rank):
    movie_obj = services.get_movie(rank, repo.repo_instance)
    reviews = services.get_reviews(rank, repo.repo_instance)
    all_genre = movie_obj.genres
    get_random_10_movies = services.get_10_movie(all_genre, repo.repo_instance)
    form = SearchForm()
    if form.validate_on_submit():
        # Successful POST, i.e. the search text has passed data validation.
        return redirect(
            url_for('movies_bp.movie_search', search_text=form.search.data))
    return render_template('Second/movie_info/movie_info.html',
                           title=movie_obj.title + ' (' + str(movie_obj.year) +
                           ')',
                           movie=movie_obj,
                           random_movie=get_random_10_movies,
                           reviews=reviews,
                           reviews_count=len(reviews),
                           form=form,
                           handler_url=url_for('movies_bp.movie_detail',
                                               rank=rank))
Example #9
0
def test_cannot_get_movie_with_non_existent_id(in_memory_repo):
    movie_id = 33

    # Call the service layer to attempt to retrieve the Movie
    with pytest.raises(movies_services.NonExistentMovieException):
        movies_services.get_movie(movie_id, in_memory_repo)
def test_can_get_movie_by_rank(in_memory_repo):
    rank = 1
    movie_obj = movies_services.get_movie(rank,in_memory_repo)
    assert movie_obj.rank == rank