Skip to content

test(test_fetch_json_db.py): improve test coverage for fetch_json_db #4932

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JigyasuRajput
Copy link
Contributor

Description:

Fixes #4876

This PR adds unit tests for the fetch_json_db.py module, increasing test coverage and ensuring better reliability. The following test cases have been implemented:

1. get_failed_downloads

  • Ensures that missing JSON files are correctly identified when only some files are present.

2. verify_signature

  • Tests signature verification using mock public keys and signature files.
  • Covers cases for:
    • Valid signatures.
    • Invalid signatures.
    • Invalid public keys.
    • Missing public key scenarios (ensuring correct error handling).

3. verify_signature_missing_signature_file

  • Ensures proper error handling when the signature file is missing.

4. cleanup_directory

  • Tests that temporary files and directories are correctly removed while preserving the main directory.

5. handle_download

  • Covers different download scenarios:
    • Unsigned Data: Ensures early exit with a signing error when ignore_signature=False.
    • Signed Data with Invalid Signature: Checks correct error handling for invalid signatures.
    • Successful Download with Retry: Validates the retry mechanism for failed downloads.
    • Max Retries Exceeded: Ensures the function respects the retry limit and performs proper cleanup.

Additional Details:

  • Mocks are used for aiohttp.ClientSession and gnupg.GPG to simulate real-world conditions.
  • A MockResponse class is implemented to handle HTTP responses in test cases.

@JigyasuRajput
Copy link
Contributor Author

fixed the flake8 and black which was failing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test: Imporve Test Coverage for fetch_json_db.py
1 participant