Add DuckDuckGo and Google News wrappers; refactor CryptoPanic and NewsAPI
- Implemented DuckDuckGoWrapper for news retrieval using DuckDuckGo tools. - Added GoogleNewsWrapper for accessing Google News RSS feed. - Refactored CryptoPanicWrapper to unify get_top_headlines and get_latest_news methods. - Updated NewsApiWrapper to simplify top headlines retrieval. - Added tests for DuckDuckGo and Google News wrappers. - Enhanced documentation for CryptoPanicWrapper and NewsApiWrapper. - Created base module for social media integrations.
This commit is contained in:
@@ -27,7 +27,7 @@ class TestCryptoPanicAPI:
|
||||
# Useless since both methods use the same endpoint
|
||||
# def test_crypto_panic_api_get_top_headlines(self):
|
||||
# crypto = CryptoPanicWrapper()
|
||||
# articles = crypto.get_top_headlines(query="crypto", total=2)
|
||||
# articles = crypto.get_top_headlines(total=2)
|
||||
# assert isinstance(articles, list)
|
||||
# assert len(articles) == 2
|
||||
# for article in articles:
|
||||
|
||||
35
tests/api/test_duckduckgo_news.py
Normal file
35
tests/api/test_duckduckgo_news.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import pytest
|
||||
from app.news import DuckDuckGoWrapper
|
||||
|
||||
|
||||
@pytest.mark.news
|
||||
@pytest.mark.api
|
||||
class TestDuckDuckGoNews:
|
||||
|
||||
def test_news_api_initialization(self):
|
||||
news = DuckDuckGoWrapper()
|
||||
assert news.tool is not None
|
||||
|
||||
def test_news_api_get_latest_news(self):
|
||||
news = DuckDuckGoWrapper()
|
||||
articles = news.get_latest_news(query="crypto", total=2)
|
||||
assert isinstance(articles, list)
|
||||
assert len(articles) == 2
|
||||
for article in articles:
|
||||
assert article.source is not None or article.source != ""
|
||||
assert article.time is not None or article.time != ""
|
||||
assert article.title is not None or article.title != ""
|
||||
assert article.description is not None or article.description != ""
|
||||
|
||||
|
||||
def test_news_api_get_top_headlines(self):
|
||||
news = DuckDuckGoWrapper()
|
||||
articles = news.get_top_headlines(total=2)
|
||||
assert isinstance(articles, list)
|
||||
assert len(articles) == 2
|
||||
for article in articles:
|
||||
assert article.source is not None or article.source != ""
|
||||
assert article.time is not None or article.time != ""
|
||||
assert article.title is not None or article.title != ""
|
||||
assert article.description is not None or article.description != ""
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import pytest
|
||||
from app.news import GnewsWrapper
|
||||
from app.news import GoogleNewsWrapper
|
||||
|
||||
|
||||
@pytest.mark.news
|
||||
@pytest.mark.api
|
||||
class TestGnewsAPI:
|
||||
class TestGoogleNews:
|
||||
|
||||
def test_gnews_api_initialization(self):
|
||||
gnews_api = GnewsWrapper()
|
||||
gnews_api = GoogleNewsWrapper()
|
||||
assert gnews_api is not None
|
||||
|
||||
def test_gnews_api_get_latest_news(self):
|
||||
gnews_api = GnewsWrapper()
|
||||
gnews_api = GoogleNewsWrapper()
|
||||
articles = gnews_api.get_latest_news(query="crypto", total=2)
|
||||
assert isinstance(articles, list)
|
||||
assert len(articles) == 2
|
||||
@@ -22,8 +22,8 @@ class TestGnewsAPI:
|
||||
assert article.description is not None or article.description != ""
|
||||
|
||||
def test_gnews_api_get_top_headlines(self):
|
||||
news_api = GnewsWrapper()
|
||||
articles = news_api.get_top_headlines(query="crypto", total=2)
|
||||
news_api = GoogleNewsWrapper()
|
||||
articles = news_api.get_top_headlines(total=2)
|
||||
assert isinstance(articles, list)
|
||||
assert len(articles) == 2
|
||||
for article in articles:
|
||||
@@ -26,7 +26,7 @@ class TestNewsAPI:
|
||||
|
||||
def test_news_api_get_top_headlines(self):
|
||||
news_api = NewsApiWrapper()
|
||||
articles = news_api.get_top_headlines(query="crypto", total=2)
|
||||
articles = news_api.get_top_headlines(total=2)
|
||||
assert isinstance(articles, list)
|
||||
# assert len(articles) > 0 # apparently it doesn't always return SOME articles
|
||||
for article in articles:
|
||||
|
||||
Reference in New Issue
Block a user