Skip to content

Commit ba755d6

Browse files
authored
Merge pull request #1840 from tisnik/lcore-2296-quota-scheduler-config-unit-tests
LCORE-2296: quota scheduler config unit tests
2 parents fee0f77 + c6fe801 commit ba755d6

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

tests/unit/models/config/test_quota_scheduler_config.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Unit tests for QuotaSchedulerConfig model."""
22

3+
from typing import Any
4+
35
import pytest
46
from pydantic import ValidationError
57

@@ -77,3 +79,95 @@ def test_quota_scheduler_custom_configuration_negative_reconnection_delay() -> N
7779
QuotaSchedulerConfiguration(
7880
database_reconnection_delay=-10
7981
) # pyright: ignore[reportCallIssue]
82+
83+
84+
correct_configurations = [
85+
{
86+
"period": 959,
87+
"database_reconnection_count": 125,
88+
"database_reconnection_delay": 94,
89+
},
90+
{
91+
"period": 1,
92+
"database_reconnection_count": 125,
93+
"database_reconnection_delay": 94,
94+
},
95+
{
96+
"period": 959,
97+
"database_reconnection_count": 1,
98+
"database_reconnection_delay": 94,
99+
},
100+
{
101+
"period": 959,
102+
"database_reconnection_count": 125,
103+
"database_reconnection_delay": 1,
104+
},
105+
]
106+
107+
108+
@pytest.mark.parametrize("config_dict", correct_configurations)
109+
def test_configure_quota_scheduler_from_dict(
110+
config_dict: dict[str, Any],
111+
) -> None:
112+
"""Test the configuration initialization from dictionary with config values."""
113+
QuotaSchedulerConfiguration(**config_dict)
114+
115+
116+
incorrect_configurations = [
117+
{
118+
"period": -1,
119+
"database_reconnection_count": 125,
120+
"database_reconnection_delay": 94,
121+
},
122+
{
123+
"period": 1,
124+
"database_reconnection_count": -1,
125+
"database_reconnection_delay": 94,
126+
},
127+
{
128+
"period": 959,
129+
"database_reconnection_count": 1,
130+
"database_reconnection_delay": -1,
131+
},
132+
{
133+
"period": None,
134+
"database_reconnection_count": 125,
135+
"database_reconnection_delay": 94,
136+
},
137+
{
138+
"period": 1,
139+
"database_reconnection_count": None,
140+
"database_reconnection_delay": 94,
141+
},
142+
{
143+
"period": 959,
144+
"database_reconnection_count": 1,
145+
"database_reconnection_delay": None,
146+
},
147+
{
148+
"period": "not a number",
149+
"database_reconnection_count": 125,
150+
"database_reconnection_delay": 94,
151+
},
152+
{
153+
"period": 1,
154+
"database_reconnection_count": "not a number",
155+
"database_reconnection_delay": 94,
156+
},
157+
{
158+
"period": 959,
159+
"database_reconnection_count": 1,
160+
"database_reconnection_delay": "not a number",
161+
},
162+
]
163+
164+
165+
@pytest.mark.parametrize("config_dict", incorrect_configurations)
166+
def test_configure_quota_scheduler_from_dict_negative_cases(
167+
config_dict: dict[str, Any],
168+
) -> None:
169+
"""Test the configuration initialization from dictionary with config values."""
170+
with pytest.raises(ValueError, match="validation error"):
171+
# try to initialize the app config and load configuration from a Python
172+
# dictionary
173+
QuotaSchedulerConfiguration(**config_dict)

0 commit comments

Comments
 (0)