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

    articles_as_dict = news_services.get_all_movies(0,
                                                    in_memory_repo,
                                                    search="Zoo")
    assert len(articles_as_dict) == 2
    assert articles_as_dict[0]['id'] == '432'
    assert articles_as_dict[1]['title'] == 'Zootopia'
Exemplo n.º 2
0
def test_get_first_page_movies_with_search_and_filter(in_memory_repo):

    articles_as_dict = news_services.get_all_movies(0,
                                                    in_memory_repo,
                                                    search="Comedy",
                                                    tag="genres")
    assert len(articles_as_dict) == 5
    assert articles_as_dict[0]['id'] == '508'
    assert articles_as_dict[1]['title'] == '10 Years'
    assert articles_as_dict[2]['release_year'] == 2009
Exemplo n.º 3
0
def test_get_articles_by_filter_tag(in_memory_repo):
    articles_as_dict = news_services.get_all_movies(0,
                                                    in_memory_repo,
                                                    tag="genres")

    assert len(articles_as_dict) == 5
Exemplo n.º 4
0
def test_invalid_search_is_handled_elsewhere(in_memory_repo):

    articles_as_dict = news_services.get_all_movies(0,
                                                    in_memory_repo,
                                                    search="sdthgsd")
Exemplo n.º 5
0
def all_movies(page_number):
    # Read query parameters.
    search = request.args.get('search')
    tag = request.args.get('sort')
    #article_to_show_comments = request.args.get('view_comments_for')

    # Fetch the first and last articles in the series.
    first_article = services.get_first_article(repo.repo_instance)
    last_article = services.get_last_article(repo.repo_instance)

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

    # Fetch article(s) for the target date. This call also returns the previous and next dates for articles immediately
    # before and after the target date.
    try:
        articles = services.get_all_movies(page_number,
                                           repo.repo_instance,
                                           search=search,
                                           tag=tag)
        del session['no_results']
    except IndexError:
        session['no_results'] = "No Results Found"
        repo.repo_instance.split_movies()
        articles = services.get_all_movies(page_number, repo.repo_instance)
    except KeyError:
        pass

    first_article_url = None
    last_article_url = None
    next_article_url = None
    prev_article_url = None

    if articles:
        # There's at least one article for the target date.
        prev_article_url = url_for('news_bp.all_movies',
                                   page_number=int(page_number) - 1,
                                   sort=tag,
                                   search=search)
        first_article_url = url_for('news_bp.all_movies',
                                    page_number=0,
                                    sort=tag,
                                    search=search)

        # There are articles on a subsequent date, so generate URLs for the 'next' and 'last' navigation buttons.
        next_article_url = url_for('news_bp.all_movies',
                                   page_number=int(page_number) + 1,
                                   sort=tag,
                                   search=search)
        last_article_url = url_for('news_bp.all_movies',
                                   page_number=-1,
                                   sort=tag,
                                   search=search)

        # Construct urls for viewing article comments and adding comments.
        #for article in articles:
        #  article['view_comment_url'] = url_for('news_bp.all_movies')
        #  article['add_comment_url'] = url_for('news_bp.comment_on_article', article=article['id'])

        # Generate the webpage to display the articles.
        return render_template(
            'news/articles.html',
            title='Articles',
            articles_title="Movies",
            articles=articles,
            selected_articles=utilities.get_selected_articles(),
            tag_urls=utilities.get_tags_and_urls(),
            first_article_url=first_article_url,
            last_article_url=last_article_url,
            prev_article_url=prev_article_url,
            next_article_url=next_article_url,
            #show_comments_for_article=article_to_show_comments
        )

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