Пример #1
0
def test_get_movies_by_date_with_non_existent_date(in_memory_repo):
    target_date = date.fromisoformat('2020-03-06')

    movies_as_dict, prev_date, next_date = news_services.get_movies_by_date(
        target_date, in_memory_repo)

    # Check that there are no movies dated 2020-03-06.
    assert len(movies_as_dict) == 0
Пример #2
0
def test_get_movies_by_date_with_one_date(in_memory_repo):
    target_date = date.fromisoformat('2020-02-28')

    movies_as_dict, prev_date, next_date = news_services.get_movies_by_date(
        target_date, in_memory_repo)

    assert prev_date is None
    assert next_date is None
Пример #3
0
def test_get_movies_by_date_with_multiple_dates(in_memory_repo):
    target_date = date.fromisoformat('2020-03-01')

    movies_as_dict, prev_date, next_date = news_services.get_movies_by_date(
        target_date, in_memory_repo)

    assert len(movies_as_dict) == 0

    # Check that the movie ids for the the movies returned are 3, 4 and 5.
    movie_ids = [movie['id'] for movie in movies_as_dict]

    # Check that the dates of movies surrounding the target_date are 2020-02-29 and 2020-03-05.
    assert prev_date is None
    assert next_date is None
Пример #4
0
def movies_by_date():
    # Read query parameters.
    target_date = request.args.get('date')
    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_date is None:
        # No date query parameter, so return movies from day 1 of the series.
        target_date = first_movie['date']
    else:
        # Convert target_date from string to date.
        target_date = date.fromisoformat(target_date)

    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 date. This call also returns the previous and next dates for movies immediately
    # before and after the target date.
    movies, previous_date, next_date = services.get_movies_by_date(
        target_date, 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 date.
        if previous_date is not None:
            # There are movies on a previous date, so generate URLs for the 'previous' and 'first' navigation buttons.
            prev_movie_url = url_for('news_bp.movies_by_date',
                                     date=previous_date.isoformat())
            first_movie_url = url_for('news_bp.movies_by_date',
                                      date=first_movie['date'].isoformat())

        # There are movies on a subsequent date, so generate URLs for the 'next' and 'last' navigation buttons.
        if next_date is not None:
            next_movie_url = url_for('news_bp.movies_by_date',
                                     date=next_date.isoformat())
            last_movie_url = url_for('news_bp.movies_by_date',
                                     date=last_movie['date'].isoformat())

        # Construct urls for viewing movie reviews and adding reviews.
        for movie in movies:
            movie['view_review_url'] = url_for('news_bp.movies_by_date',
                                               date=target_date,
                                               view_reviews_for=movie['id'])
            movie['add_review_url'] = url_for('news_bp.review_on_movie',
                                              movie=movie['id'])

        # Generate the webpage to display the movies.
        return render_template(
            'news/articles.html',
            title='Movies',
            movies_title='Movies made in ' + target_date.strftime('%Y'),
            movies=movies,
            selected_movies=utilities.get_selected_movies(len(movies) * 2),
            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)

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