Exemplo n.º 1
0
def test_listar_as_top_cinco_noticias():
    db.news.delete_many({})

    # é possível buscar as cinco top 5 notícias
    db.news.insert_many([
        NEW_NOTICE_1,
        NEW_NOTICE_2,
        NEW_NOTICE_3,
        NEW_NOTICE_4,
        NEW_NOTICE_5,
        NEW_NOTICE_6,
    ])
    assert top_5_news() == LIST_FIVE_NOTICES

    # caso houver menos de 5 notícias, serão retornadas quantas houverem
    db.news.delete_many({})
    db.news.insert_many([
        NEW_NOTICE_1,
        NEW_NOTICE_2,
        NEW_NOTICE_3,
    ])
    assert top_5_news() == LIST_FIVE_NOTICES[:3]

    # retornar vazio caso nao exista noticias
    db.news.delete_many({})
    assert top_5_news() == []
def test_listar_as_top_cinco_noticias():
    db.news.delete_many({})
    db.news.insert_many([
        NEW_NOTICE_1, NEW_NOTICE_2, NEW_NOTICE_3, NEW_NOTICE_4, NEW_NOTICE_5,
        NEW_NOTICE_6
    ])
    assert top_5_news() == LIST_FIVE_NOTICES
Exemplo n.º 3
0
        result = scrape(fetcher=fetch_content, pages=1)
        create_news(result)
    elif answer == "4":
        result = "Encerrando script"
    else:
        print(result, file=sys.stderr)
    print(result)


menu_of_analyzer = {
    "1": lambda: wrapper("Digite o título:", func=search_by_title),
    "2": lambda: wrapper(
        "Digite a data no formato aaaa-mm-dd:", func=search_by_date
    ),
    "3": lambda: wrapper("Digite a fonte:", func=search_by_source),
    "4": lambda: wrapper("Digite a categoria:", func=search_by_category),
    "5": lambda: top_5_news(),
    "6": lambda: top_5_categories(),
    "7": lambda: "Encerrando script",
}


def analyzer_menu():
    answer = input(message_analyzer)
    result = "Opção inválida"
    if answer in menu_of_analyzer.keys():
        result = menu_of_analyzer[answer]()
    else:
        print(result, file=sys.stderr)
    print(result)
Exemplo n.º 4
0
def test_buscar_top_noticias_retornar_vazio_caso_nao_exista_noticias():
    db.news.delete_many({})
    assert top_5_news() == []