Add news API integration and related configurations
- Update .env.example to include NEWS_API_KEY configuration - Add newsapi-python dependency in pyproject.toml - Implement NewsAPI class for fetching news articles - Create Article model for structured news data - Add tests for NewsAPI functionality in test_news_api.py - Update pytest configuration to include news marker
This commit is contained in:
19
tests/api/test_news_api.py
Normal file
19
tests/api/test_news_api.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from app.news import NewsAPI
|
||||
|
||||
class TestNewsAPI:
|
||||
|
||||
def test_news_api_initialization(self):
|
||||
news_api = NewsAPI()
|
||||
assert news_api.client is not None
|
||||
|
||||
def test_news_api_get_top_headlines(self):
|
||||
news_api = NewsAPI()
|
||||
articles = news_api.get_top_headlines(query="crypto", total=2)
|
||||
assert isinstance(articles, list)
|
||||
assert len(articles) == 2
|
||||
for article in articles:
|
||||
assert hasattr(article, 'source')
|
||||
assert hasattr(article, 'time')
|
||||
assert hasattr(article, 'title')
|
||||
assert hasattr(article, 'description')
|
||||
|
||||
Reference in New Issue
Block a user