From f8f67c9609bfa7a701d2f60f421d81a9d6ea1688 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:49:27 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Extends=20test=5FEC2=5FINSTANCES=5F?= =?UTF-8?q?ALLOWED=5FTYPES=5Fempty=5Fnot=5Fallowed=20(#6705)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/unit/test_core_settings.py | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/services/autoscaling/tests/unit/test_core_settings.py b/services/autoscaling/tests/unit/test_core_settings.py index 9315c8fcfd1..e975d944f0b 100644 --- a/services/autoscaling/tests/unit/test_core_settings.py +++ b/services/autoscaling/tests/unit/test_core_settings.py @@ -4,6 +4,7 @@ import datetime import json +import os import pytest from faker import Faker @@ -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