-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding in additional tests for account processing * Adding in unit tests for organisations abstraction * Adding in unit tests for organisations abstraction * Initial commit - Now optionally resolves children OUs * Linting * starting exclusion work * Adding in unit tests for schema validation * Adding in an example config to user-guide.md * Codereview comments * Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/organizations.py Co-authored-by: Simon Kok * Apply suggestions from code review * Remove redundant pylint disable line --------- Co-authored-by: Stewart Wallace Co-authored-by: Simon Kok
- Loading branch information
Showing
12 changed files
with
1,284 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ isort==5.12.0 | |
mock==5.1.0 | ||
pylint==2.17.4 | ||
pytest~=7.4.0 | ||
pytest-cov==3.0.0 | ||
tox==3.28.0 | ||
yamllint==1.32.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
[pytest] | ||
testpaths = tests | ||
addopts = --cov=./src/lambda_codebase/account_processing/ --cov-fail-under=50 --cov-report term | ||
|
||
[coverage:run] | ||
omit = tests/ | ||
|
62 changes: 62 additions & 0 deletions
62
src/lambda_codebase/account_processing/tests/test_account_tags.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
Tests the account tag configuration lambda | ||
""" | ||
|
||
import unittest | ||
import boto3 | ||
from botocore.stub import Stubber | ||
from aws_xray_sdk import global_sdk_config | ||
from ..configure_account_tags import ( | ||
create_account_tags, | ||
) | ||
|
||
global_sdk_config.set_sdk_enabled(False) | ||
|
||
# pylint: disable=W0106 | ||
class SuccessTestCase(unittest.TestCase): | ||
def test_account_tag_creation(self): | ||
test_event = {"account_id": "123456789012", "tags": [{"CreatedBy": "ADF"}]} | ||
ou_client = boto3.client("organizations") | ||
stubber = Stubber(ou_client) | ||
stubber.add_response( | ||
"tag_resource", | ||
{}, | ||
{ | ||
"Tags": [{"Key": "CreatedBy", "Value": "ADF"}], | ||
"ResourceId": "123456789012", | ||
}, | ||
), | ||
stubber.activate() | ||
create_account_tags( | ||
test_event.get("account_id"), test_event.get("tags"), ou_client | ||
) | ||
stubber.assert_no_pending_responses() | ||
|
||
def test_account_tag_creation_multiple_tags(self): | ||
test_event = { | ||
"account_id": "123456789012", | ||
"tags": [ | ||
{ | ||
"CreatedBy": "ADF", | ||
"TagName": "TagValue", | ||
} | ||
], | ||
} | ||
ou_client = boto3.client("organizations") | ||
stubber = Stubber(ou_client) | ||
stubber.add_response( | ||
"tag_resource", | ||
{}, | ||
{ | ||
"Tags": [ | ||
{"Key": "CreatedBy", "Value": "ADF"}, | ||
{"Key": "TagName", "Value": "TagValue"}, | ||
], | ||
"ResourceId": "123456789012", | ||
}, | ||
), | ||
stubber.activate() | ||
create_account_tags( | ||
test_event.get("account_id"), test_event.get("tags"), ou_client | ||
) | ||
stubber.assert_no_pending_responses() |
62 changes: 62 additions & 0 deletions
62
src/lambda_codebase/account_processing/tests/test_get_default_regions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
Tests the account tag configuration lambda | ||
""" | ||
|
||
import unittest | ||
import boto3 | ||
from botocore.stub import Stubber | ||
from aws_xray_sdk import global_sdk_config | ||
from ..get_account_regions import ( | ||
get_default_regions_for_account, | ||
) | ||
|
||
global_sdk_config.set_sdk_enabled(False) | ||
|
||
# pylint: disable=W0106 | ||
class SuccessTestCase(unittest.TestCase): | ||
@staticmethod | ||
def test_get_default_regions_for_account(): | ||
ec2_client = boto3.client("ec2") | ||
stubber = Stubber(ec2_client) | ||
stubber.add_response( | ||
"describe_regions", | ||
{ | ||
"Regions": [ | ||
{ | ||
"Endpoint": "blah", | ||
"RegionName": "us-east-1", | ||
"OptInStatus": "opt-in-not-required", | ||
}, | ||
{ | ||
"Endpoint": "blah", | ||
"RegionName": "us-east-2", | ||
"OptInStatus": "opt-in-not-required", | ||
}, | ||
{ | ||
"Endpoint": "blah", | ||
"RegionName": "us-east-3", | ||
"OptInStatus": "opted-in", | ||
}, | ||
{ | ||
"Endpoint": "blah", | ||
"RegionName": "us-east-4", | ||
"OptInStatus": "opted-in", | ||
}, | ||
] | ||
}, | ||
{ | ||
"AllRegions": False, | ||
"Filters": [ | ||
{ | ||
"Values": [ | ||
"opt-in-not-required", | ||
"opted-in", | ||
], | ||
"Name": "opt-in-status", | ||
}, | ||
], | ||
}, | ||
), | ||
stubber.activate() | ||
regions = get_default_regions_for_account(ec2_client) | ||
assert regions == ["us-east-1", "us-east-2", "us-east-3", "us-east-4"] |
Oops, something went wrong.