Skip to content

Commit f8f67c9

Browse files
authored
✅ Extends test_EC2_INSTANCES_ALLOWED_TYPES_empty_not_allowed (#6705)
1 parent ec1e84e commit f8f67c9

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

services/autoscaling/tests/unit/test_core_settings.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import datetime
66
import json
7+
import os
78

89
import pytest
910
from faker import Faker
@@ -197,11 +198,42 @@ def test_EC2_INSTANCES_ALLOWED_TYPES_passing_valid_image_tags( # noqa: N802
197198
def test_EC2_INSTANCES_ALLOWED_TYPES_empty_not_allowed( # noqa: N802
198199
app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch
199200
):
201+
assert app_environment["AUTOSCALING_EC2_INSTANCES"] == "{}"
200202
monkeypatch.setenv("EC2_INSTANCES_ALLOWED_TYPES", "{}")
201203

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:
203222
ApplicationSettings.create_from_envs()
204223

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+
205237

206238
def test_invalid_instance_names(
207239
app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch, faker: Faker

0 commit comments

Comments
 (0)