Skip to content

LCORE-1028: unit tests for quota scheduler configuration model#827

Merged
tisnik merged 1 commit intolightspeed-core:mainfrom
tisnik:lcore-1028-unit-tests-for-quota-scheduler-configuration-model
Nov 23, 2025
Merged

LCORE-1028: unit tests for quota scheduler configuration model#827
tisnik merged 1 commit intolightspeed-core:mainfrom
tisnik:lcore-1028-unit-tests-for-quota-scheduler-configuration-model

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Nov 23, 2025

Description

LCORE-1028: unit tests for quota scheduler configuration model

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

Related Tickets & Documents

  • Related Issue #LCORE-1028

Summary by CodeRabbit

  • New Features

    • Added a public alias to access the RH identity configuration.
  • Bug Fixes

    • Clarified validation message for missing RH identity configuration.
    • Enforced scheduler period must be greater than zero.
  • Tests

    • Added tests for the identity alias and entitlement default behavior.
    • Added tests for invalid scheduler period values.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 23, 2025

Walkthrough

Adds a public alias AuthenticationConfiguration.rh_identity_configuration for RH Identity config, changes RHIdentityConfiguration.required_entitlements default to None, updates the missing-RH-Identity validation message, and adds tests asserting QuotaSchedulerConfiguration.period > 0.

Changes

Cohort / File(s) Summary
Authentication configuration tests & API
tests/unit/models/config/test_authentication_configuration.py, .../models/config/*.py
Introduced public alias AuthenticationConfiguration.rh_identity_configuration that references rh_identity_config; changed RHIdentityConfiguration.required_entitlements default to None; updated validation error text to "RH Identity configuration must be specified"; tests updated to assert alias equality and new default/validation behavior.
Quota scheduler validation tests
tests/unit/models/config/test_quota_scheduler_config.py
Added tests asserting QuotaSchedulerConfiguration(period) raises ValidationError with message "Input should be greater than 0" for period values 0 and -10.

Sequence Diagram(s)

sequenceDiagram
  participant Tests as Tests
  participant AuthConfig as AuthenticationConfiguration
  participant RHConfig as RHIdentityConfiguration
  note right of AuthConfig `#E8F6FF`: Alias accessor
  Tests->>AuthConfig: access rh_identity_configuration
  AuthConfig->>RHConfig: return rh_identity_config (alias)
  Tests->>RHConfig: inspect required_entitlements
  RHConfig-->>Tests: returns None (when unspecified)

  rect rgba(200,255,200,0.25)
    note right of RHConfig: Validation for missing RH config
    Tests->>AuthConfig: validate presence of rh_identity_config
    AuthConfig-->>Tests: raise ValidationError: "RH Identity configuration must be specified"
  end
Loading
sequenceDiagram
  participant Tests as Tests
  participant QuotaCfg as QuotaSchedulerConfiguration
  note right of QuotaCfg `#FFF4E6`: Period validation (>0)
  Tests->>QuotaCfg: construct with period = 0 or -10
  QuotaCfg-->>Tests: raise ValidationError "Input should be greater than 0"
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Focus review on:
    • AuthenticationConfiguration accessor/alias implementation and any forwarding semantics.
    • RHIdentityConfiguration.required_entitlements default change and places that may rely on an iterable default.
    • QuotaSchedulerConfiguration.period validation logic and error message consistency.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding unit tests for the quota scheduler configuration model, which matches the primary focus of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/unit/models/config/test_quota_scheduler_config.py (2)

25-28: Consider improving the docstring for clarity.

The test correctly validates that period=0 raises a ValidationError. However, the docstring "Test the custom configuration." is generic and doesn't describe what this test specifically validates. Consider making it more descriptive.

Apply this diff to improve the docstring:

-def test_quota_scheduler_custom_configuration_zero_period() -> None:
-    """Test the custom configuration."""
+def test_quota_scheduler_custom_configuration_zero_period() -> None:
+    """Test that zero period value raises ValidationError."""

31-34: Consider improving the docstring for clarity.

The test correctly validates that negative period values raise a ValidationError. However, the docstring "Test the custom configuration." is generic and doesn't describe what this test specifically validates. Consider making it more descriptive.

Apply this diff to improve the docstring:

-def test_quota_scheduler_custom_configuration_negative_period() -> None:
-    """Test the custom configuration."""
+def test_quota_scheduler_custom_configuration_negative_period() -> None:
+    """Test that negative period value raises ValidationError."""
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8bc9a1 and 3cf0aef.

📒 Files selected for processing (2)
  • tests/unit/models/config/test_authentication_configuration.py (4 hunks)
  • tests/unit/models/config/test_quota_scheduler_config.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/unit/models/config/test_quota_scheduler_config.py (1)
src/models/config.py (1)
  • QuotaSchedulerConfiguration (605-608)
tests/unit/models/config/test_authentication_configuration.py (1)
src/models/config.py (1)
  • rh_identity_configuration (465-473)
⏰ 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). (4)
  • GitHub Check: build-pr
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
  • GitHub Check: e2e_tests (azure)
  • GitHub Check: e2e_tests (ci)
🔇 Additional comments (6)
tests/unit/models/config/test_quota_scheduler_config.py (1)

3-5: LGTM!

The imports are correctly added to support the new validation tests.

tests/unit/models/config/test_authentication_configuration.py (5)

67-68: LGTM!

The assertions correctly verify that rh_identity_configuration is a property alias that returns the same rh_identity_config object and that required_entitlements is set to an empty list as configured.


87-88: LGTM!

The assertions correctly verify the default behavior where required_entitlements is None when RHIdentityConfiguration is instantiated without arguments.


107-108: LGTM!

The assertions correctly verify that required_entitlements is set to ["foo"] when explicitly configured with a single entitlement.


129-134: LGTM!

The assertions correctly verify that required_entitlements is set to the configured list of multiple entitlements. The multi-line formatting improves readability.


140-142: LGTM!

The test correctly validates that a ValidationError is raised with the expected message when AUTH_MOD_RH_IDENTITY is specified without the required rh_identity_config. This appears to be testing Pydantic model-level validation.

@tisnik tisnik force-pushed the lcore-1028-unit-tests-for-quota-scheduler-configuration-model branch from 3cf0aef to 70bea89 Compare November 23, 2025 11:15
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unit/models/config/test_authentication_configuration.py (1)

67-68: Consider adding error case tests for rh_identity_configuration property.

The tests thoroughly cover the happy path for the new rh_identity_configuration alias, but error cases are missing. Based on the relevant code snippet and the pattern established for jwk_configuration (lines 44-48 and 200-217), consider adding tests for:

  1. Accessing rh_identity_configuration when module is not AUTH_MOD_RH_IDENTITY (should raise ValueError with message: "RH Identity configuration is only available for RH Identity authentication module")
  2. Accessing rh_identity_configuration when rh_identity_config is None but module is RH_IDENTITY (broken config scenario - should raise ValueError with message: "RH Identity configuration should not be None")

These tests would ensure the property's validation behavior is properly covered, similar to the JWK configuration tests.

Based on relevant code snippets showing the property implementation.

Example test for case 1:

def test_authentication_configuration_rh_identity_config_wrong_module() -> None:
    """Test accessing rh_identity_configuration with wrong module."""
    auth_config = AuthenticationConfiguration(
        module=AUTH_MOD_NOOP,
        skip_tls_verification=False,
        k8s_ca_cert_path=None,
        k8s_cluster_api=None,
    )
    
    with pytest.raises(
        ValueError,
        match="RH Identity configuration is only available for RH Identity authentication module",
    ):
        _ = auth_config.rh_identity_configuration

Example test for case 2:

def test_authentication_configuration_rh_identity_broken_config() -> None:
    """Test accessing rh_identity_configuration with None config."""
    auth_config = AuthenticationConfiguration(
        module=AUTH_MOD_RH_IDENTITY,
        skip_tls_verification=False,
        k8s_ca_cert_path=None,
        k8s_cluster_api=None,
        rh_identity_config=RHIdentityConfiguration(),
    )
    
    # Emulate broken config
    auth_config.rh_identity_config = None
    
    with pytest.raises(
        ValueError,
        match="RH Identity configuration should not be None",
    ):
        _ = auth_config.rh_identity_configuration
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3cf0aef and 70bea89.

📒 Files selected for processing (2)
  • tests/unit/models/config/test_authentication_configuration.py (4 hunks)
  • tests/unit/models/config/test_quota_scheduler_config.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unit/models/config/test_quota_scheduler_config.py
🧰 Additional context used
🧬 Code graph analysis (1)
tests/unit/models/config/test_authentication_configuration.py (1)
src/models/config.py (1)
  • rh_identity_configuration (465-473)
⏰ 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). (4)
  • GitHub Check: build-pr
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
  • GitHub Check: e2e_tests (azure)
  • GitHub Check: e2e_tests (ci)
🔇 Additional comments (4)
tests/unit/models/config/test_authentication_configuration.py (4)

67-68: LGTM! Correct alias verification.

The assertions properly verify that rh_identity_configuration is an alias (same object reference) and that explicitly provided empty entitlements are preserved.


87-88: LGTM! Correct default value verification.

The assertions properly test the new default behavior where required_entitlements is None when not explicitly specified.


107-108: LGTM! Single entitlement scenario covered.

The assertions properly verify that a single entitlement in the list is preserved.


129-134: LGTM! Multiple entitlements scenario covered.

The assertions properly verify that multiple entitlements are preserved. The multi-line formatting enhances readability.

Comment on lines +140 to +142
with pytest.raises(
ValidationError, match="RH Identity configuration must be specified"
):
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify error message format consistency.

The validation error test looks correct, but there's a potential inconsistency: the JWK validation error test on line 189 matches "Value error, JWK configuration must be specified..." with the "Value error, " prefix, while this test matches "RH Identity configuration must be specified" without that prefix.

If both validators are the same type (e.g., both using @model_validator), they should have consistent error message formats. Please verify this is intentional.


🏁 Script executed:

#!/bin/bash
# Description: Check how ValidationError messages are raised in the model code
# to verify if the "Value error, " prefix inconsistency is intentional

# Search for RH Identity validation logic
echo "=== RH Identity validation ==="
rg -n -A5 -B2 "RH Identity configuration must be specified" src/

# Search for JWK validation logic  
echo "=== JWK validation ==="
rg -n -A5 -B2 "JWK configuration must be specified" src/

# Check for model_validator or field_validator usage patterns
echo "=== Validator decorators in config.py ==="
rg -n -B2 -A8 "@(model_validator|field_validator)" src/models/config.py | head -100

Length of output: 5096


Fix error message match pattern to include Pydantic's "Value error, " prefix.

The test is checking for the wrong error message format. Both the RH Identity and JWK validators raise ValueError inside @model_validator methods. When Pydantic catches a ValueError in a model validator, it wraps it as a ValidationError and prefixes the message with "Value error, ".

The test at line 140-142 should match "Value error, RH Identity configuration must be specified" instead of just "RH Identity configuration must be specified". Without the prefix, the test will fail to catch the exception.

🤖 Prompt for AI Agents
In tests/unit/models/config/test_authentication_configuration.py around lines
140 to 142, the pytest.raises match string misses Pydantic's "Value error, "
prefix; update the match to "Value error, RH Identity configuration must be
specified" so the test matches the ValidationError message Pydantic produces
when a ValueError is raised in a model_validator.

@tisnik tisnik merged commit d8e504b into lightspeed-core:main Nov 23, 2025
21 of 23 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