Refactor news API integration to use NewsApiWrapper and GnewsWrapper; add tests for Gnews API functionality
This commit is contained in:
34
tests/api/test_gnews_api.py
Normal file
34
tests/api/test_gnews_api.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import pytest
|
||||
from app.news import GnewsWrapper
|
||||
|
||||
|
||||
@pytest.mark.news
|
||||
@pytest.mark.api
|
||||
class TestGnewsAPI:
|
||||
|
||||
def test_gnews_api_initialization(self):
|
||||
gnews_api = GnewsWrapper()
|
||||
assert gnews_api is not None
|
||||
|
||||
def test_gnews_api_get_latest_news(self):
|
||||
gnews_api = GnewsWrapper()
|
||||
articles = gnews_api.get_latest_news(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')
|
||||
|
||||
def test_gnews_api_get_top_headlines(self):
|
||||
news_api = GnewsWrapper()
|
||||
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')
|
||||
|
||||
@@ -1,13 +1,29 @@
|
||||
from app.news import NewsAPI
|
||||
import pytest
|
||||
from app.news import NewsApiWrapper
|
||||
|
||||
|
||||
@pytest.mark.news
|
||||
@pytest.mark.api
|
||||
class TestNewsAPI:
|
||||
|
||||
def test_news_api_initialization(self):
|
||||
news_api = NewsAPI()
|
||||
news_api = NewsApiWrapper()
|
||||
assert news_api.client is not None
|
||||
|
||||
def test_news_api_get_latest_news(self):
|
||||
news_api = NewsApiWrapper()
|
||||
articles = news_api.get_latest_news(query="crypto", total=2)
|
||||
assert isinstance(articles, list)
|
||||
assert len(articles) > 0 # Ensure we got some articles (apparently it doesn't always return the requested number)
|
||||
for article in articles:
|
||||
assert hasattr(article, 'source')
|
||||
assert hasattr(article, 'time')
|
||||
assert hasattr(article, 'title')
|
||||
assert hasattr(article, 'description')
|
||||
|
||||
|
||||
def test_news_api_get_top_headlines(self):
|
||||
news_api = NewsAPI()
|
||||
news_api = NewsApiWrapper()
|
||||
articles = news_api.get_top_headlines(query="crypto", total=2)
|
||||
assert isinstance(articles, list)
|
||||
assert len(articles) > 0 # Ensure we got some articles (apparently it doesn't always return the requested number)
|
||||
|
||||
Reference in New Issue
Block a user