From 9b6fbe3446d92cc9d45975e80da9d53e4a8a1d98 Mon Sep 17 00:00:00 2001 From: Nicolas Thumann Date: Tue, 13 Aug 2024 13:31:45 +0200 Subject: [PATCH 1/2] Fix: Loading NVD API results when there are none --- pontos/nvd/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pontos/nvd/api.py b/pontos/nvd/api.py index c5c112d16..783ae0640 100644 --- a/pontos/nvd/api.py +++ b/pontos/nvd/api.py @@ -267,7 +267,7 @@ def __await__(self) -> Generator[Any, None, "NVDResults"]: async def _load_next_data(self) -> None: if ( - not self._current_request_results + self._current_request_results is None or self._downloaded_results < self._current_request_results ): params = self._params From 4cc4d1750b1072693c104b96b1e4dcfe3b26c682 Mon Sep 17 00:00:00 2001 From: Nicolas Thumann Date: Tue, 13 Aug 2024 13:32:16 +0200 Subject: [PATCH 2/2] Add: Unit test to empty result behavior --- tests/nvd/test_api.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/nvd/test_api.py b/tests/nvd/test_api.py index eedef8ed9..56f2bd1b8 100644 --- a/tests/nvd/test_api.py +++ b/tests/nvd/test_api.py @@ -186,6 +186,29 @@ async def test_items(self): with self.assertRaises(StopAsyncIteration): await anext(it) + async def test_items_no_results(self): + response_mock = MagicMock(spec=Response) + response_mock.json.side_effect = [ + { + "values": [], + "total_results": 0, + "results_per_page": 0, + }, + ] + api_mock = AsyncMock(spec=NVDApi) + api_mock._get.return_value = response_mock + + results: NVDResults[Result] = NVDResults( + api_mock, + {}, + result_func, + ) + + it = aiter(results.items()) + + with self.assertRaises(StopAsyncIteration): + await anext(it) + async def test_aiter(self): response_mock = MagicMock(spec=Response) response_mock.json.side_effect = [