Skip to content

Commit

Permalink
Fix loading of NVD API results when there are none (#1039)
Browse files Browse the repository at this point in the history
* Fix: Loading NVD API results when there are none

* Add: Unit test to empty result behavior
  • Loading branch information
n-thumann authored Sep 3, 2024
1 parent 04eeac5 commit 213e94f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pontos/nvd/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions tests/nvd/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 213e94f

Please sign in to comment.