Skip to content

Commit ba46ad3

Browse files
committed
Codereview comments
1 parent a8f4b7f commit ba46ad3

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

src/lambda_codebase/account_processing/get_account_regions.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,26 @@
1616
ADF_ROLE_NAME = os.getenv("ADF_ROLE_NAME")
1717
AWS_PARTITION = os.getenv("AWS_PARTITION")
1818

19+
1920
def get_default_regions_for_account(ec2_client):
20-
default_regions = [
21-
region["RegionName"]
22-
for region in ec2_client.describe_regions(
21+
filtered_regions = ec2_client.describe_regions(
2322
AllRegions=False,
2423
Filters=[
2524
{
2625
"Name": "opt-in-status",
2726
"Values": [
2827
"opt-in-not-required",
29-
"opted-in"
28+
"opted-in",
3029
],
31-
}
30+
},
3231
],
3332
)["Regions"]
34-
]
33+
default_regions = [region["RegionName"] for region in filtered_regions]
3534
return default_regions
3635

3736

3837
def lambda_handler(event, _):
39-
LOGGER.info("Fetching Default regions %s", event.get('account_full_name'))
38+
LOGGER.info("Fetching Default regions %s", event.get("account_full_name"))
4039
sts = STS()
4140
account_id = event.get("account_id")
4241
role = sts.assume_cross_account_role(

src/lambda_codebase/account_processing/tests/test_account_tags.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212

1313
global_sdk_config.set_sdk_enabled(False)
1414

15-
# pylint: disable=W0106
15+
# pylint: disable=W0106,R0201
1616
class SuccessTestCase(unittest.TestCase):
17-
@staticmethod
18-
def test_account_tag_creation():
17+
def test_account_tag_creation(self):
1918
test_event = {"account_id": "123456789012", "tags": [{"CreatedBy": "ADF"}]}
2019
ou_client = boto3.client("organizations")
2120
stubber = Stubber(ou_client)
@@ -31,3 +30,33 @@ def test_account_tag_creation():
3130
create_account_tags(
3231
test_event.get("account_id"), test_event.get("tags"), ou_client
3332
)
33+
stubber.assert_no_pending_responses()
34+
35+
def test_account_tag_creation_multiple_tags(self):
36+
test_event = {
37+
"account_id": "123456789012",
38+
"tags": [
39+
{
40+
"CreatedBy": "ADF",
41+
"TagName": "TagValue",
42+
}
43+
],
44+
}
45+
ou_client = boto3.client("organizations")
46+
stubber = Stubber(ou_client)
47+
stubber.add_response(
48+
"tag_resource",
49+
{},
50+
{
51+
"Tags": [
52+
{"Key": "CreatedBy", "Value": "ADF"},
53+
{"Key": "TagName", "Value": "TagValue"},
54+
],
55+
"ResourceId": "123456789012",
56+
},
57+
),
58+
stubber.activate()
59+
create_account_tags(
60+
test_event.get("account_id"), test_event.get("tags"), ou_client
61+
)
62+
stubber.assert_no_pending_responses()

0 commit comments

Comments
 (0)