From ca38235b8e0597b280bb9bd25ddc0b3981b1a00d Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 6 May 2022 04:07:40 -0400 Subject: [PATCH] Common: Set AWSInstance.is_instance to False if empty string --- monkey/common/aws/aws_instance.py | 2 +- monkey/tests/unit_tests/common/aws/test_aws_instance.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/monkey/common/aws/aws_instance.py b/monkey/common/aws/aws_instance.py index fd2eb696d..6ba8c40e7 100644 --- a/monkey/common/aws/aws_instance.py +++ b/monkey/common/aws/aws_instance.py @@ -34,7 +34,7 @@ class AWSInstance: @property def is_instance(self) -> bool: self._wait_for_initialization_to_complete() - return self._instance_id is not None + return self._instance_id @property def instance_id(self) -> str: diff --git a/monkey/tests/unit_tests/common/aws/test_aws_instance.py b/monkey/tests/unit_tests/common/aws/test_aws_instance.py index 3c1f22ab2..7cd785991 100644 --- a/monkey/tests/unit_tests/common/aws/test_aws_instance.py +++ b/monkey/tests/unit_tests/common/aws/test_aws_instance.py @@ -29,13 +29,20 @@ def test_is_instance__true(): assert aws_instance.is_instance -def test_is_instance__false(patch_fetch_metadata): +def test_is_instance__false_none(patch_fetch_metadata): patch_fetch_metadata(None, "", "") aws_instance = AWSInstance() assert not aws_instance.is_instance +def test_is_instance__false_empty_str(patch_fetch_metadata): + patch_fetch_metadata("", "", "") + aws_instance = AWSInstance() + + assert not aws_instance.is_instance + + def test_instance_id(): aws_instance = AWSInstance()