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')
|
||||
|
||||
@@ -20,6 +20,7 @@ def pytest_configure(config:pytest.Config):
|
||||
("gemini", "marks tests that use Gemini model"),
|
||||
("ollama_gpt", "marks tests that use Ollama GPT model"),
|
||||
("ollama_qwen", "marks tests that use Ollama Qwen model"),
|
||||
("news", "marks tests that use news"),
|
||||
]
|
||||
for marker in markers:
|
||||
line = f"{marker[0]}: {marker[1]}"
|
||||
@@ -37,6 +38,7 @@ def pytest_collection_modifyitems(config, items):
|
||||
"gemini": pytest.mark.gemini,
|
||||
"ollama_gpt": pytest.mark.ollama_gpt,
|
||||
"ollama_qwen": pytest.mark.ollama_qwen,
|
||||
"news": pytest.mark.news,
|
||||
}
|
||||
|
||||
for item in items:
|
||||
|
||||
Reference in New Issue
Block a user