Skip to content

LCORE-2297: test quota handlers config#1846

Merged
tisnik merged 2 commits into
lightspeed-core:mainfrom
tisnik:lcore-2297-test-quota-handlers-config
Jun 4, 2026
Merged

LCORE-2297: test quota handlers config#1846
tisnik merged 2 commits into
lightspeed-core:mainfrom
tisnik:lcore-2297-test-quota-handlers-config

Conversation

@tisnik

@tisnik tisnik commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Description

LCORE-2297: test quota handlers config

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement
  • Benchmarks improvement

Tools used to create PR

  • Assisted-by: N/A
  • Generated by: N/A

Related Tickets & Documents

  • Related Issue #LCORE-2297

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for quota handlers configuration validation, including parametrized test suites for both valid and invalid configuration scenarios to ensure proper validation error handling.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR extends test coverage for QuotaHandlersConfiguration by adding two parametrized test functions that validate configuration construction from dictionary inputs. The tests cover both valid and invalid configuration scenarios, with the negative test cases expecting pydantic validation errors with specific message patterns.

Changes

QuotaHandlersConfiguration Parametrized Testing

Layer / File(s) Summary
Parametrized test suite with correct and negative case datasets
tests/unit/models/config/test_quota_handlers_config.py
Adds Any type import and introduces correct_configurations and incorrect_configurations datasets. Two parametrized test functions validate QuotaHandlersConfiguration construction: positive test asserts successful instantiation from valid inputs; negative test asserts pydantic ValidationError is raised from invalid inputs with specified error message substrings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change as adding tests for quota handlers configuration, matching the changeset's focus of introducing two new parametrized test suites.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f1c6cec and 4df1c42.

📒 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
Use pytest.mark.asyncio marker 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

Comment on lines +521 to +527
@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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Comment on lines +741 to +750
@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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

@tisnik tisnik merged commit 1fc5b18 into lightspeed-core:main Jun 4, 2026
26 of 31 checks passed
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