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:
2025-09-29 15:15:18 +02:00
parent 2be9e0f319
commit badd3e2a6c
8 changed files with 91 additions and 1 deletions

View 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')

View File

@@ -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: