Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading of NVD API results when there are none #1039

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading