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 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 = [