Exemplo n.º 1
0
def test_get_movies_by_release_year_with_non_existent_release_year(
        in_memory_repo):

    target_year = 2010

    movies_as_dict, prev_year, next_year = movies_services.get_movies_by_release_year(
        target_year, in_memory_repo)

    assert len(movies_as_dict) == 0
Exemplo n.º 2
0
def test_get_movies_by_release_year_with_one_movie_in_the_year(in_memory_repo):
    target_year = 2012

    movies_as_dict, prev_year, next_year = movies_services.get_movies_by_release_year(
        target_year, in_memory_repo)
    assert len(movies_as_dict) == 1
    assert movies_as_dict[0]['id'] == 2

    assert prev_year is None
    assert next_year == 2014
Exemplo n.º 3
0
def test_get_movies_by_release_year_with_multiple_movies_in_the_year(
        in_memory_repo):
    target_year = 2016

    movies_as_dict, prev_year, next_year = movies_services.get_movies_by_release_year(
        target_year, in_memory_repo)

    # Check that there are 8 movies released in 2016 in the repository
    assert len(movies_as_dict) == 8

    # Check that the movie ids for the movies returned are 3, 4, 5, 6, 7, 8, 9, 10
    movie_ids = [movie['id'] for movie in movies_as_dict]
    assert set([3, 4, 5, 6, 7, 8, 9, 10]).issubset(movie_ids)

    # Check that the dates of movies surrounding the target year are 2014 and None
    assert prev_year == 2014
    assert next_year is None
Exemplo n.º 4
0
def movies_by_release_year():
    # Read query parameters
    target_year = request.args.get('year')
    movie_to_show_reviews = request.args.get('view_reviews_for')

    earliest_year = services.get_earliest_year(repo=repo.repo_instance)
    latest_year = services.get_latest_year(repo=repo.repo_instance)

    if target_year is None:
        # No year query parameter, so return movies from the latest release year of the series
        target_year = latest_year
    else:
        # Convert target_year from string to int
        target_year = int(target_year)

    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) from the target year. This call also returns the previous and next release year for movies
    # immediately before and after the target year
    movies, previous_year, next_year = services.get_movies_by_release_year(
        target_year, repo.repo_instance)

    num_of_movies_found = len(movies)
    first_page_url = None
    # last_page_url = None
    previous_page_url = None
    next_page_url = None
    last_page_url = url_for(
        'movies_bp.movies_by_release_year',
        year=earliest_year)  # year=int(oldest_movie['release_year'])
    first_page_url = url_for(
        'movies_bp.movies_by_release_year',
        year=latest_year)  # int(latest_movie['release_year'])

    if num_of_movies_found > 0:
        previous_year = int(movies[0]['release_year']) - 1
        next_year = int(movies[0]['release_year']) + 1

        next_page_url = url_for('movies_bp.movies_by_release_year',
                                year=previous_year)  # previous_year

        previous_page_url = url_for('movies_bp.movies_by_release_year',
                                    year=next_year)

        if previous_year < earliest_year:
            next_page_url = None

        if next_year > latest_year:
            previous_page_url = None

        # Construct urls for viewing movie reviews and adding reviews
        for movie in movies:
            movie['view_review_url'] = url_for(
                'movies_bp.movies_by_release_year',
                year=target_year,
                view_reviews_for=movie['id'])
            movie['add_review_url'] = url_for('movies_bp.review_on_movie',
                                              movie=movie['id'])

        # Generate the webpage to display the movie
        return render_template(
            'movies/movies.html',
            title='Movies',
            movies_title='Movies released in ' + str(target_year) + " - (" +
            str(num_of_movies_found) + " results found)",
            movies=movies,
            form=SearchForm(),
            handler_url=url_for('movies_bp.search'),
            selected_movies=utilities.get_selected_movies(len(movies) * 2),
            genre_urls=utilities.get_genres_and_urls(),
            first_page_url=first_page_url,
            last_page_url=last_page_url,
            previous_page_url=previous_page_url,
            next_page_url=next_page_url,
            show_reviews_for_movie=movie_to_show_reviews,
            title_form=SearchByTitleForm(),
            handler_url_title=url_for('movies_bp.search_by_title'),
        )

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