|
4 | 4 |
|
5 | 5 | import datetime
|
6 | 6 | import json
|
| 7 | +import os |
7 | 8 |
|
8 | 9 | import pytest
|
9 | 10 | from faker import Faker
|
@@ -197,11 +198,42 @@ def test_EC2_INSTANCES_ALLOWED_TYPES_passing_valid_image_tags( # noqa: N802
|
197 | 198 | def test_EC2_INSTANCES_ALLOWED_TYPES_empty_not_allowed( # noqa: N802
|
198 | 199 | app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch
|
199 | 200 | ):
|
| 201 | + assert app_environment["AUTOSCALING_EC2_INSTANCES"] == "{}" |
200 | 202 | monkeypatch.setenv("EC2_INSTANCES_ALLOWED_TYPES", "{}")
|
201 | 203 |
|
202 |
| - with pytest.raises(ValidationError): |
| 204 | + # test child settings |
| 205 | + with pytest.raises(ValidationError) as err_info: |
| 206 | + EC2InstancesSettings.create_from_envs() |
| 207 | + |
| 208 | + assert err_info.value.errors()[0]["loc"] == ("EC2_INSTANCES_ALLOWED_TYPES",) |
| 209 | + |
| 210 | + |
| 211 | +def test_EC2_INSTANCES_ALLOWED_TYPES_empty_not_allowed_with_main_field_env_var( # noqa: N802 |
| 212 | + app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch |
| 213 | +): |
| 214 | + assert os.environ["AUTOSCALING_EC2_INSTANCES"] == "{}" |
| 215 | + monkeypatch.setenv("EC2_INSTANCES_ALLOWED_TYPES", "{}") |
| 216 | + |
| 217 | + # now as part of AUTOSCALING_EC2_INSTANCES: EC2InstancesSettings | None |
| 218 | + with pytest.raises(ValidationError) as exc_before: |
| 219 | + ApplicationSettings.create_from_envs(AUTOSCALING_EC2_INSTANCES={}) |
| 220 | + |
| 221 | + with pytest.raises(ValidationError) as exc_after: |
203 | 222 | ApplicationSettings.create_from_envs()
|
204 | 223 |
|
| 224 | + assert exc_before.value.errors() == exc_after.value.errors() |
| 225 | + |
| 226 | + |
| 227 | +def test_EC2_INSTANCES_ALLOWED_TYPES_empty_not_allowed_without_main_field_env_var( # noqa: N802 |
| 228 | + app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch |
| 229 | +): |
| 230 | + monkeypatch.delenv("AUTOSCALING_EC2_INSTANCES") |
| 231 | + monkeypatch.setenv("EC2_INSTANCES_ALLOWED_TYPES", "{}") |
| 232 | + |
| 233 | + # removing any value for AUTOSCALING_EC2_INSTANCES |
| 234 | + settings = ApplicationSettings.create_from_envs() |
| 235 | + assert settings.AUTOSCALING_EC2_INSTANCES is None |
| 236 | + |
205 | 237 |
|
206 | 238 | def test_invalid_instance_names(
|
207 | 239 | app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch, faker: Faker
|
|
0 commit comments