Skip to content

Commit

Permalink
✅ Extends test_EC2_INSTANCES_ALLOWED_TYPES_empty_not_allowed (#6705)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored Nov 12, 2024
1 parent ec1e84e commit f8f67c9
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion services/autoscaling/tests/unit/test_core_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import datetime
import json
import os

import pytest
from faker import Faker
Expand Down Expand Up @@ -197,11 +198,42 @@ def test_EC2_INSTANCES_ALLOWED_TYPES_passing_valid_image_tags( # noqa: N802
def test_EC2_INSTANCES_ALLOWED_TYPES_empty_not_allowed( # noqa: N802
app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch
):
assert app_environment["AUTOSCALING_EC2_INSTANCES"] == "{}"
monkeypatch.setenv("EC2_INSTANCES_ALLOWED_TYPES", "{}")

with pytest.raises(ValidationError):
# test child settings
with pytest.raises(ValidationError) as err_info:
EC2InstancesSettings.create_from_envs()

assert err_info.value.errors()[0]["loc"] == ("EC2_INSTANCES_ALLOWED_TYPES",)


def test_EC2_INSTANCES_ALLOWED_TYPES_empty_not_allowed_with_main_field_env_var( # noqa: N802
app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch
):
assert os.environ["AUTOSCALING_EC2_INSTANCES"] == "{}"
monkeypatch.setenv("EC2_INSTANCES_ALLOWED_TYPES", "{}")

# now as part of AUTOSCALING_EC2_INSTANCES: EC2InstancesSettings | None
with pytest.raises(ValidationError) as exc_before:
ApplicationSettings.create_from_envs(AUTOSCALING_EC2_INSTANCES={})

with pytest.raises(ValidationError) as exc_after:
ApplicationSettings.create_from_envs()

assert exc_before.value.errors() == exc_after.value.errors()


def test_EC2_INSTANCES_ALLOWED_TYPES_empty_not_allowed_without_main_field_env_var( # noqa: N802
app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch
):
monkeypatch.delenv("AUTOSCALING_EC2_INSTANCES")
monkeypatch.setenv("EC2_INSTANCES_ALLOWED_TYPES", "{}")

# removing any value for AUTOSCALING_EC2_INSTANCES
settings = ApplicationSettings.create_from_envs()
assert settings.AUTOSCALING_EC2_INSTANCES is None


def test_invalid_instance_names(
app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch, faker: Faker
Expand Down

0 comments on commit f8f67c9

Please sign in to comment.