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

[Feature] improved test coverage and added integration tests #44

Closed
wants to merge 52 commits into from

Conversation

PPeitsch
Copy link
Owner

@PPeitsch PPeitsch commented Dec 20, 2024

⚡ ⚡ Have you read the Contributing Guidelines?

Fixes #

Description

Clearly and concisely describe the changes in this pull request.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would break existing functionality)
  • Documentation update
  • Performance improvement
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • CI/CD related changes
  • Other (please describe):

Checklist

  • I have followed the project's coding style guidelines
  • I have added tests that prove my fix/feature works
  • All existing tests pass locally
  • I have updated the documentation accordingly
  • I have added appropriate type hints
  • I have updated the CHANGELOG.md
  • My changes generate no new warnings or errors
  • I have checked my code with black, isort, and mypy

The code coverage for bcra_connector.py was at 45%. This change adds:
- Complete test suite for BCRAConnector class
- Coverage for all main methods and functionality
- Error handling and edge cases
- Rate limiting and retry mechanism tests
- Translate docstrings to English
- Improve documentation for test data helper
- Maintain consistent language across codebase

See also: #31
- Add extensive test coverage for RateLimitConfig and RateLimiter
- Test concurrent access and thread safety
- Verify sliding window behavior
- Add edge cases and precision tests
- Improve test organization and readability

See also: #31
- Add extensive test coverage for RateLimitConfig and RateLimiter
- Test concurrent access and thread safety
- Verify sliding window behavior
- Add edge cases and precision tests
- Improve test organization and readability

See also: #31
- Add complete test coverage for TimeoutConfig class
- Test immutability and factory methods
- Add equality and hash tests
- Verify string representations
- Test error cases and validation

See also: #31
- Add complete test coverage for Cheque, ChequeDetalle and Entidad
- Include validation tests for all models
- Test API response models
- Add type hints for better code clarity
- Test error scenarios and edge cases

See also: #31
- Add test coverage for PrincipalesVariables and DatosVariable
- Add validation tests for data types and formats
- Test error handling scenarios
- Include type hints
- Test equality comparisons

See also: #31
- Add test coverage for currency and exchange rate models
- Test response models and metadata handling
- Add validation tests for all models
- Include type hints
- Test error responses and edge cases

See also: #31
- Add complete API integration test suite
- Test full workflows for variables and currencies
- Add rate limit testing
- Include comprehensive error handling tests
- Add type hints
- Add skippable tests for sensitive operations

See also: #31
- Add tests for various network errors
- Test timeout and rate limit scenarios
- Add validation for API responses
- Test HTTP error codes
- Include parameterized tests
- Add type hints
- Add specialized test fixtures

See also: #31
- Add complete type annotations to test data utilities
- Add type hints to pytest fixtures
- Improve docstrings with type information
- Ensure type safety in test infrastructure

See also: #31
- Add comprehensive type annotations
- Add generic types for containers
- Type thread-safe components
- Add return type hints for fixtures
- Improve type safety in test assertions

See also: #31
- Run isort on data importers to standardize import ordering
- Applied Black code formatter to standardize code style across all Python
files. This ensures consistent formatting and improves code readability.
- Add type annotations to all methods and parameters
- Add return type hints to fixtures and tests
- Specify types for mock objects and responses
- Fix pytest fixture implementation
- Maintain all existing test functionality

See also: #31
- Add return type hints to all test methods
- Add type annotations for TimeoutConfig instances
- Add type hints for tuples and dictionaries
- Add typing for test assertions
- Include type ignore for immutability tests

See also: #31
- Remove unnecessary type ignore comments
- Replace direct attribute assignments with setattr() in immutability tests
- Maintain consistent type hints throughout test file
- Improve test readability while keeping type safety
- Use proper type annotations for all variables and methods

See also: #31
- Rename duplicate delay variables to avoid redefinition
- Remove unnecessary type ignore comment in queue handling
- Add explicit type hints for queue results
- Fix unreachable code in concurrent access test
- Add specific type ignore comment for false positive in is_limited test
- Improve variable naming for better readability

See also: #31
- Remove access to private connector methods
- Replace base_url parameter with proper session configuration
- Fix malformed response test to use requests exceptions directly
- Simplify HTTP error code testing with raise_for_status()
- Add monkeypatch for session mocking
- Clean up test structure and improve type safety

See also: #31
- Replace to_dict tests with from_dict equivalents
- Fix date type handling in Cheque instantiation
- Use from_dict for invalid date format test
- Add proper type hints for all test methods
- Improve test coverage for model conversions

See also: #31
- Add required status_code parameter to mock_api_response calls
- Maintain proper type hints throughout test file
- Improve test response mocking consistency
- Ensure all mock responses include status code
- Fix type annotations for API response fixtures

See also: #31
- Add test_*.py pattern to python_files in pytest config
- Allow both naming conventions (*_tests.py and test_*.py)
- Maintain consistent list format in pyproject.toml

See also: #31
- Add from_dict classmethod to Entidad for proper data mapping
- Update get_entidades to use from_dict instead of direct kwargs
- Fix API response field mapping from 'codigoEntidad' to 'codigo_entidad'
- Maintain consistency with project's data model patterns
See also: #28
- Add frozen=True to TimeoutConfig dataclass for immutability
- Use field for better default value handling
- Ensure thread-safety through immutability
- Fix hash implementation for dict/set usage
See also: #31
- Add ID validation to prevent negative values
- Customize equality comparison to consider only ID and date
- Update documentation for comparison behavior
- Add post-init validation for data integrity
See also: #31
- Add from_dict and to_dict methods to all Cheques models
- Add data validation in post_init for data integrity
- Add sample check data fixture for response tests
- Fix API field mapping from camelCase to snake_case
See also: #31
- Add validation for empty currency codes in Divisa class
- Add sample_cotizacion_fecha_data fixture for response tests
- Fix fixture visibility in TestResponseModels
- Add post-init validation for data integrity
See also: #31
- Update get_cheque_denunciado to use Cheque.from_dict instead of manual attribute mapping
- Fix test_get_cheque_denunciado_success to verify all fields correctly
- Refactor test_rate_limiting to properly test burst and rate limiting behavior
- Add detailed assertions to verify rate limiter state
- Add detailed error handling for HTTP status codes
- Enhance timeout and connection error handling
- Improve JSON response validation
- Update error handling tests for better coverage
- Add specific error messages for different scenarios
- Update error handling to provide consistent error messages
- Improve HTTP error code handling with better error messages
- Fix rate limiting behavior and related tests
- Make concurrent tests more reliable
- Add specific handling for SSL verification errors
- Update tests to use appropriate mocks
- Add proper SSL error imports from ssl and urllib3
- Fix SSL error handling in request method
- Improve error messages consistency
- Maintain proper error propagation
- Implement uniform request spacing for consistent delays
- Calculate target times based on window position
- Add window expiration check for more accurate timing
- Ensure proportional delays for rate limited requests

Fixes test_rate_limit_precision failures by ensuring consistent spacing between rate limited requests and increasing the tolerance.
- Update RequestException error message to maintain consistency
- Ensure consistent "API request failed" prefix across error cases
- Added pytest-timeout>=2.1.0 to dev dependencies in pyproject.toml
- Enables automatic timeout handling in tests
- Updated development dependencies to support robust testing
- Added __init__.py to tests/, fixtures/, integration/, and unit/ paths
- Ensured modular structure for test suite
- Facilitates imports and execution of tests in structured paths
- Added explicit type annotation for results variable in test_concurrent_access
- Ensured compatibility with MyPy type checks
- Improved code clarity and thread safety testing
- Removed `libnode-dev` package to address the update conflict.
- Executed `sudo apt autoremove` to clean up unnecessary dependencies.
- Ran `sudo apt upgrade` to complete the update process without further issues.
- Ensured a stable and updated environment after resolving dependency conflicts.
- Updated RateLimiter.is_limited to align with config.calls
- Improved delay calculation logic in _get_delay for consistency
- Revised test_rate_limiting to correctly validate behavior against burst limit
- Ensured proper synchronization between RateLimiter and test expectations
The connector was raising an error when rate limited instead of
actually waiting, which prevented the rate limiter from tracking
requests correctly. This caused the rate limiter's state to remain
incorrect and tests to fail intermittently.

 - Removed premature error raising on rate limit
 - Added proper delay implementation with time.sleep()
 - Maintained request tracking for accurate rate limit state

Resolves: Rate limiting test failures in test_bcra_connector.py
Updates rate limiter implementation to maintain accurate state when
handling requests that exceed limits. Fixes intermittent test failures
by ensuring proper state tracking in the rate limiter.

 - Update timestamp tracking before applying delays
 - Improve is_limited check to consider both burst and base limits
 - Ensure consistent state with proper lock usage

Resolves: Test failures in test_rate_limiting
Added test cases to improve coverage of model validations and edge cases:

- Add validation tests for empty Divisa fields
- Add tests for CotizacionFecha serialization with null dates

Test coverage for estadisticas_cambiarias.py is now at 100%
Added serialization test cases for data model classes:

- Add to_dict() test for PrincipalesVariables
- Add to_dict() test for DatosVariable

Test coverage for principales_variables.py is now at 97%
Added serialization test cases for data model classes:

- Add to_dict() test for Cheque
- Add to_dict() test for ChequeDetalle

Test coverage for cheques.py is now at 95%
Fixed type annotation issues:
- Add explicit bool return in RateLimiter.is_limited
- Add type hints for test functions and variables in test_estadisticas_cambiarias.py
- Maintain consistent type hinting across test suite

Format code with black:
- Fix line lengths in rate_limiter.py
- Adjust indentation in test_estadisticas_cambiarias.py
- Clean up formatting in test_principales_variables.py

Resolved all mypy validation errors
- Add deterministic rate limiter state in test_rate_limit_exceeded
- Remove time.sleep() dependency
- Set explicit window timestamps
- Add test assertions for error message

Resolves test failures in GitHub Actions
- Replace timing assertions with request counting
- Verify rate limiting through current_usage and remaining_calls
- Add error message validation for rate limit exceeded
- Reset rate limiter state explicitly before tests

Fixes inconsistent test behavior in CI and local environments
- Add initial request to consume burst limit
- Keep explicit rate limit state control
- Retain error message validation
@PPeitsch PPeitsch force-pushed the feature/improved-test-coverage branch from 973fdf5 to d6a8fb4 Compare December 26, 2024 19:13
- Add multiple timestamps to force rate limited state
- Add explicit state verification before API call
- Remove dependency on initial API call
- Ensure consistent behavior across different environments

Fixes flaky test behavior in GitHub Actions
Modifies rate limiter to throw BCRAApiError when burst limit is exceeded rather
than just delaying requests. This provides better control over rate limiting
and fixes failing integration tests.

 - Updates acquire() to check burst limit before processing
 - Adds explicit error handling in _make_request
 - Ensures consistent exception propagation

This change makes rate limiting behavior more predictable and testable while
maintaining backward compatibility with existing delay-based limiting.
Fixes circular import error in tests by using relative import for BCRAApiError
and removes unused ssl import. Keeps the codebase clean while fixing the CI
pipeline.

 - Changes 'from bcra_connector import BCRAApiError' to relative import
 - Removes unused ssl import from bcra_connector.py
@PPeitsch PPeitsch force-pushed the feature/improved-test-coverage branch from 26147bd to 502f0c5 Compare December 28, 2024 22:53
Repository owner deleted a comment from codecov bot Dec 28, 2024
@PPeitsch PPeitsch closed this Dec 28, 2024
@PPeitsch PPeitsch deleted the feature/improved-test-coverage branch December 28, 2024 23:02
@PPeitsch PPeitsch restored the feature/improved-test-coverage branch December 28, 2024 23:04
@PPeitsch PPeitsch deleted the feature/improved-test-coverage branch December 28, 2024 23:10
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.

1 participant