|
1 | 1 | """Unit tests for QuotaSchedulerConfig model.""" |
2 | 2 |
|
| 3 | +from typing import Any |
| 4 | + |
3 | 5 | import pytest |
4 | 6 | from pydantic import ValidationError |
5 | 7 |
|
@@ -77,3 +79,95 @@ def test_quota_scheduler_custom_configuration_negative_reconnection_delay() -> N |
77 | 79 | QuotaSchedulerConfiguration( |
78 | 80 | database_reconnection_delay=-10 |
79 | 81 | ) # 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