Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces comprehensive unit tests for critical functions in
nvd_api.py
, ensuring better test coverage without adding stress to the NVD API. All tests are mocked and avoid real API calls, adhering to the project's guidelines on minimizing external resource usage.Changes
New Unit Tests:
convert_date_to_nvd_date_api2
,get_reject_count_api2
,nvd_count_metadata
,validate_nvd_api
, andload_nvd_request
.AsyncMock
andFakeResponse
to simulate various scenarios (e.g., invalid API keys, rejected CVEs).Preserved Existing Tests:
test_nvd_incremental_update
) remain unchanged and are conditionally skipped unlessEXTERNAL_SYSTEM=1
is set.No Breaking Changes:
Why This Matters
Testing
New Tests:
test_convert_date_to_nvd_date_api2
: Validates date formatting for NVD API compliance.test_get_reject_count_api2
: Ensures rejected CVEs are correctly counted.test_nvd_count_metadata
: Verifies metadata parsing from mocked API responses.test_validate_nvd_api
: Tests API key removal on invalid responses.test_load_nvd_request
: Checks pagination logic and total result calculation.Existing Tests:
Steps to test
EXTERNAL_SYSTEM=1 pytest -v test/test_nvd_api.py
Related Issues
Fixes #4877