diff --git a/asknews_sdk/api/news.py b/asknews_sdk/api/news.py index 30298ff..dccb1b8 100644 --- a/asknews_sdk/api/news.py +++ b/asknews_sdk/api/news.py @@ -139,6 +139,7 @@ def search_news( geo_radius: Optional[float] = None, geo_polygon: Optional[str] = None, sort_by: Optional[Literal["relevance", "pub_date"]] = None, + podcasts: Literal["include", "only", "none"] = "include", *, http_headers: Optional[Dict] = None, ) -> SearchResponse: @@ -197,6 +198,10 @@ def search_news( :type domain_url: Optional[str] :param page_rank: Page rank, defaults to None :type page_rank: Optional[int] + :param podcasts: Control whether podcasts are included in search results. 'include' + searches news and podcasts, 'only' searches podcasts only, and 'none' + excludes podcasts. Defaults to 'include'. + :type podcasts: Literal["include", "only", "none"] :param http_headers: Additional HTTP headers. :type http_headers: Optional[Dict] :return: The search response. @@ -223,6 +228,7 @@ def search_news( "reporting_voice": reporting_voice, "domain_url": domain_url, "bad_domain_url": bad_domain_url, + "podcasts": podcasts, "page_rank": page_rank, "diversify_sources": diversify_sources, "strategy": strategy, @@ -627,13 +633,19 @@ async def search_news( geo_radius: Optional[float] = None, geo_polygon: Optional[str] = None, sort_by: Optional[Literal["relevance", "pub_date"]] = None, + podcasts: Literal["include", "only", "none"] = "include", *, http_headers: Optional[Dict] = None, ) -> SearchResponse: """ - Get time-series counts for a filter + Search for news articles given a query. - https://docs.asknews.app/en/reference#get-/v1/index_counts + https://docs.asknews.app/en/reference#get-/v1/news/search + + :param podcasts: Control whether podcasts are included in search results. 'include' + searches news and podcasts, 'only' searches podcasts only, and 'none' + excludes podcasts. Defaults to 'include'. + :type podcasts: Literal["include", "only", "none"] """ response = await self.client.request( method="GET", @@ -656,6 +668,7 @@ async def search_news( "reporting_voice": reporting_voice, "domain_url": domain_url, "bad_domain_url": bad_domain_url, + "podcasts": podcasts, "page_rank": page_rank, "diversify_sources": diversify_sources, "strategy": strategy, diff --git a/tests/api/test_news.py b/tests/api/test_news.py index be152ba..11a71e1 100644 --- a/tests/api/test_news.py +++ b/tests/api/test_news.py @@ -120,7 +120,10 @@ async def test_async_news_api_get_article(async_news_api: AsyncNewsAPI, response assert mock_route.calls.last.response.status_code == 404 -def test_sync_news_api_search_news(sync_news_api: NewsAPI, response_mock: MockRouter): +@pytest.mark.parametrize("podcasts", ["include", "only", "none"]) +def test_sync_news_api_search_news( + sync_news_api: NewsAPI, response_mock: MockRouter, podcasts: str +): mock_search_response = MockSearchResponse.build() mock_route = response_mock.get("/v1/news/search").respond( @@ -129,6 +132,7 @@ def test_sync_news_api_search_news(sync_news_api: NewsAPI, response_mock: MockRo response = sync_news_api.search_news( "query", + podcasts=podcasts, http_headers={ "custom-header": "custom-value", } @@ -140,13 +144,17 @@ def test_sync_news_api_search_news(sync_news_api: NewsAPI, response_mock: MockRo assert mock_route.called assert mock_route.calls.last.request.url.path == "/v1/news/search" + assert mock_route.calls.last.request.url.params["podcasts"] == podcasts assert mock_route.calls.last.request.method == "GET" assert mock_route.calls.last.request.headers["accept"] == SearchResponse.__content_type__ assert mock_route.calls.last.request.headers["custom-header"] == "custom-value" assert mock_route.calls.last.response.status_code == 200 -async def test_async_news_api_search_news(async_news_api: AsyncNewsAPI, response_mock: MockRouter): +@pytest.mark.parametrize("podcasts", ["include", "only", "none"]) +async def test_async_news_api_search_news( + async_news_api: AsyncNewsAPI, response_mock: MockRouter, podcasts: str +): mock_search_response = MockSearchResponse.build() mock_route = response_mock.get("/v1/news/search").respond( @@ -155,6 +163,7 @@ async def test_async_news_api_search_news(async_news_api: AsyncNewsAPI, response response = await async_news_api.search_news( "query", + podcasts=podcasts, http_headers={ "custom-header": "custom-value", } @@ -166,6 +175,7 @@ async def test_async_news_api_search_news(async_news_api: AsyncNewsAPI, response assert mock_route.called assert mock_route.calls.last.request.url.path == "/v1/news/search" + assert mock_route.calls.last.request.url.params["podcasts"] == podcasts assert mock_route.calls.last.request.method == "GET" assert mock_route.calls.last.request.headers["accept"] == SearchResponse.__content_type__ assert mock_route.calls.last.request.headers["custom-header"] == "custom-value"