LCORE-2297: test quota handlers config#1846
Conversation
WalkthroughThis PR extends test coverage for ChangesQuotaHandlersConfiguration Parametrized Testing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unit/models/config/test_quota_handlers_config.py`:
- Around line 741-750: The negative test
test_quota_handlers_from_dict_negative_cases is too broad because it only
matches the top-level ValidationError message; update the parametrization
(incorrect_configurations) to pair each invalid config with an expected error
fragment (e.g., a field path or specific error text) and change the test
signature to accept both (config_dict, expected_error); then inside the test,
use pytest.raises(ValidationError, match=expected_error) or capture excinfo and
assert the expected field/path appears in str(excinfo.value) so each case
verifies the failing field for QuotaHandlersConfiguration initialization rather
than just the model-level message.
- Around line 521-527: The test_quota_handlers_from_dict currently only
constructs QuotaHandlersConfiguration(**config_dict) and should assert the model
parsed values; update the test to create an instance (e.g., cfg =
QuotaHandlersConfiguration(**config_dict)) and add assertions that key fields
from config_dict (for example handler names, limits, enabled flags or other
unique keys present in correct_configurations) are equal to the corresponding
attributes on cfg (use exact attribute names from QuotaHandlersConfiguration) to
validate parsing rather than only ensuring no exception.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 9de60327-f8f3-4d35-b748-8213b1121a28
📒 Files selected for processing (1)
tests/unit/models/config/test_quota_handlers_config.py
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: mypy
- GitHub Check: Pylinter
- GitHub Check: spectral
- GitHub Check: check_dependencies
- GitHub Check: bandit
- GitHub Check: build-pr
- GitHub Check: unit_tests (3.12)
- GitHub Check: E2E: library mode / ci / group 2
- GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
- GitHub Check: E2E Tests for Lightspeed Evaluation job
🧰 Additional context used
📓 Path-based instructions (1)
tests/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
tests/**/*.py: Use pytest for all unit and integration tests; do not use unittest
Usepytest.mark.asynciomarker for async tests
Files:
tests/unit/models/config/test_quota_handlers_config.py
🔇 Additional comments (1)
tests/unit/models/config/test_quota_handlers_config.py (1)
4-4: LGTM!Also applies to: 230-518, 529-738
| @pytest.mark.parametrize("config_dict", correct_configurations) | ||
| def test_quota_handlers_from_dict(config_dict: dict[str, Any]) -> None: | ||
| """Test the configuration initialization from dictionary with config values.""" | ||
| # try to initialize the app config and load configuration from a Python | ||
| # dictionary | ||
| QuotaHandlersConfiguration(**config_dict) | ||
|
|
There was a problem hiding this comment.
Positive parametrized test needs value assertions, not only constructor execution.
This currently verifies only “no exception.” It does not prove key fields from config_dict were parsed into the model as expected.
Suggested fix
`@pytest.mark.parametrize`("config_dict", correct_configurations)
def test_quota_handlers_from_dict(config_dict: dict[str, Any]) -> None:
"""Test the configuration initialization from dictionary with config values."""
- # try to initialize the app config and load configuration from a Python
- # dictionary
- QuotaHandlersConfiguration(**config_dict)
+ cfg = QuotaHandlersConfiguration(**config_dict)
+
+ assert cfg.enable_token_history == config_dict["enable_token_history"]
+ assert cfg.scheduler.period == config_dict["scheduler"]["period"]
+ assert (
+ cfg.scheduler.database_reconnection_count
+ == config_dict["scheduler"]["database_reconnection_count"]
+ )
+ assert (
+ cfg.scheduler.database_reconnection_delay
+ == config_dict["scheduler"]["database_reconnection_delay"]
+ )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/unit/models/config/test_quota_handlers_config.py` around lines 521 -
527, The test_quota_handlers_from_dict currently only constructs
QuotaHandlersConfiguration(**config_dict) and should assert the model parsed
values; update the test to create an instance (e.g., cfg =
QuotaHandlersConfiguration(**config_dict)) and add assertions that key fields
from config_dict (for example handler names, limits, enabled flags or other
unique keys present in correct_configurations) are equal to the corresponding
attributes on cfg (use exact attribute names from QuotaHandlersConfiguration) to
validate parsing rather than only ensuring no exception.
| @pytest.mark.parametrize("config_dict", incorrect_configurations) | ||
| def test_quota_handlers_from_dict_negative_cases(config_dict: dict[str, Any]) -> None: | ||
| """Test the configuration initialization from dictionary with config values.""" | ||
| with pytest.raises( | ||
| ValidationError, | ||
| match=" validation error for QuotaHandlersConfiguration", | ||
| ): | ||
| # try to initialize the app config and load configuration from a Python | ||
| # dictionary | ||
| QuotaHandlersConfiguration(**config_dict) |
There was a problem hiding this comment.
Negative parametrized test is too broad; assert the failing field/path per case.
Matching only the model-level error text lets unrelated validation failures pass, weakening the negative-case guarantees.
Suggested fix
-@pytest.mark.parametrize("config_dict", incorrect_configurations)
-def test_quota_handlers_from_dict_negative_cases(config_dict: dict[str, Any]) -> None:
+@pytest.mark.parametrize(("config_dict", "expected_loc"), incorrect_configurations)
+def test_quota_handlers_from_dict_negative_cases(
+ config_dict: dict[str, Any], expected_loc: tuple[str, ...]
+) -> None:
"""Test the configuration initialization from dictionary with config values."""
- with pytest.raises(
- ValidationError,
- match=" validation error for QuotaHandlersConfiguration",
- ):
- # try to initialize the app config and load configuration from a Python
- # dictionary
+ with pytest.raises(ValidationError) as exc_info:
QuotaHandlersConfiguration(**config_dict)
+ assert any(tuple(err["loc"]) == expected_loc for err in exc_info.value.errors())🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/unit/models/config/test_quota_handlers_config.py` around lines 741 -
750, The negative test test_quota_handlers_from_dict_negative_cases is too broad
because it only matches the top-level ValidationError message; update the
parametrization (incorrect_configurations) to pair each invalid config with an
expected error fragment (e.g., a field path or specific error text) and change
the test signature to accept both (config_dict, expected_error); then inside the
test, use pytest.raises(ValidationError, match=expected_error) or capture
excinfo and assert the expected field/path appears in str(excinfo.value) so each
case verifies the failing field for QuotaHandlersConfiguration initialization
rather than just the model-level message.
Description
LCORE-2297: test quota handlers config
Type of change
Tools used to create PR
Related Tickets & Documents
Summary by CodeRabbit