Esempio n. 1
0
def test_get_movies_by_id_with_non_existent_id(in_memory_repo):
    target_id = 1100

    movies_as_dict, prev_date, next_date = movie_library_services.get_movies_by_rank(
        target_id, in_memory_repo)

    assert len(movies_as_dict) == 0
Esempio n. 2
0
def test_get_movies_by_rank_with_one_rank(in_memory_repo):
    target_id = 50
    movies_as_dict, prev_id, next_id = movie_library_services.get_movies_by_rank(
        target_id, in_memory_repo)
    assert len(movies_as_dict) == 1
    assert movies_as_dict[0]['id'] == 50
    assert prev_id == 49
    assert next_id == 51
Esempio n. 3
0
def movies_by_rank():
    # Read query parameters.
    target_id = request.args.get('id')
    movie_to_show_reviews = request.args.get('view_reviews_for')

    # Fetch the first and last movies in the series.
    first_movie = services.get_first_movie(repo.repo_instance)
    last_movie = services.get_last_movie(repo.repo_instance)

    if target_id is None:
        # No id query parameter, so return movies from day 1 of the series.
        target_id = first_movie['id']
    else:
        # Convert target_year from string to int.
        target_id = int(target_id)

    if movie_to_show_reviews is None:
        # No view-reviews query parameter, so set to a non-existent movie id.
        movie_to_show_reviews = -1
    else:
        # Convert movie_to_show_reviews from string to int.
        movie_to_show_reviews = int(movie_to_show_reviews)

    # Fetch movie(s) for the target id. This call also returns the previous and next ids for movies immediately
    # before and after the target.
    movies, previous_id, next_id = services.get_movies_by_rank(
        target_id, repo.repo_instance)

    first_movie_url = None
    last_movie_url = None
    next_movie_url = None
    prev_movie_url = None

    if len(movies) > 0:
        # There's at least one movie for the target id.
        if previous_id is not None:
            # There are movie on a previous id, so generate URLs for the 'previous' and 'first' navigation buttons.
            prev_movie_url = url_for('movie_library_bp.movies_by_rank',
                                     id=previous_id)
            first_movie_url = url_for('movie_library_bp.movies_by_rank',
                                      id=first_movie['id'])

        # There are movies subsequent, so generate URLs for the 'next' and 'last' navigation buttons.
        if next_id is not None:
            next_movie_url = url_for('movie_library_bp.movies_by_rank',
                                     id=next_id)
            last_movie_url = url_for('movie_library_bp.movies_by_rank',
                                     id=last_movie['id'])

        # Construct urls for viewing movie reviews and adding reviews.
        for movie in movies:
            movie['view_review_url'] = url_for(
                'movie_library_bp.movies_by_rank',
                id=target_id,
                view_reviews_for=movie['id'])
            movie['add_review_url'] = url_for(
                'movie_library_bp.write_review_on_movie', movie=movie['id'])
            movie['add_to_watchlist_url'] = url_for(
                'movie_library_bp.add_to_watchlist', movie=movie['id'])
        # Generate the webpage to display the movies.
        return render_template(
            'movie_library/movies.html',
            title='Movies',
            movies_title="Ranked: " + str(target_id),
            movies=movies,
            selected_movies=utilities.get_selected_movies(3),
            actor_urls=utilities.get_actors_and_urls(),
            director_urls=utilities.get_directors_and_urls(),
            genre_urls=utilities.get_genres_and_urls(),
            first_movie_url=first_movie_url,
            last_movie_url=last_movie_url,
            prev_movie_url=prev_movie_url,
            next_movie_url=next_movie_url,
            show_reviews_for_movie=movie_to_show_reviews,
            is_watchlist=False)

    # No movies to show, so return the homepage.
    return redirect(url_for('home_bp.home'))