Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions tests/unit/models/config/test_quota_scheduler_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Unit tests for QuotaSchedulerConfig model."""

from typing import Any

import pytest
from pydantic import ValidationError

Expand Down Expand Up @@ -77,3 +79,95 @@ def test_quota_scheduler_custom_configuration_negative_reconnection_delay() -> N
QuotaSchedulerConfiguration(
database_reconnection_delay=-10
) # pyright: ignore[reportCallIssue]


correct_configurations = [
{
"period": 959,
"database_reconnection_count": 125,
"database_reconnection_delay": 94,
},
{
"period": 1,
"database_reconnection_count": 125,
"database_reconnection_delay": 94,
},
{
"period": 959,
"database_reconnection_count": 1,
"database_reconnection_delay": 94,
},
{
"period": 959,
"database_reconnection_count": 125,
"database_reconnection_delay": 1,
},
]


@pytest.mark.parametrize("config_dict", correct_configurations)
def test_configure_quota_scheduler_from_dict(
config_dict: dict[str, Any],
) -> None:
"""Test the configuration initialization from dictionary with config values."""
QuotaSchedulerConfiguration(**config_dict)


incorrect_configurations = [
{
"period": -1,
"database_reconnection_count": 125,
"database_reconnection_delay": 94,
},
{
"period": 1,
"database_reconnection_count": -1,
"database_reconnection_delay": 94,
},
{
"period": 959,
"database_reconnection_count": 1,
"database_reconnection_delay": -1,
},
{
"period": None,
"database_reconnection_count": 125,
"database_reconnection_delay": 94,
},
{
"period": 1,
"database_reconnection_count": None,
"database_reconnection_delay": 94,
},
{
"period": 959,
"database_reconnection_count": 1,
"database_reconnection_delay": None,
},
{
"period": "not a number",
"database_reconnection_count": 125,
"database_reconnection_delay": 94,
},
{
"period": 1,
"database_reconnection_count": "not a number",
"database_reconnection_delay": 94,
},
{
"period": 959,
"database_reconnection_count": 1,
"database_reconnection_delay": "not a number",
},
]


@pytest.mark.parametrize("config_dict", incorrect_configurations)
def test_configure_quota_scheduler_from_dict_negative_cases(
config_dict: dict[str, Any],
) -> None:
"""Test the configuration initialization from dictionary with config values."""
with pytest.raises(ValueError, match="validation error"):
# try to initialize the app config and load configuration from a Python
# dictionary
QuotaSchedulerConfiguration(**config_dict)
Loading