-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Organizations: list_roots() now returns roots for requests made by ot…
…her accounts within the organization
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -189,6 +189,42 @@ def test_list_roots(): | |
validate_roots(org, response) | ||
|
||
|
||
@mock_aws | ||
def test_list_roots_for_new_account_in_organization(): | ||
if not settings.TEST_DECORATOR_MODE: | ||
raise SkipTest("Involves changing account using env variable") | ||
client = boto3.client("organizations", region_name="us-east-1") | ||
org = client.create_organization()["Organization"] | ||
org_roots = client.list_roots() | ||
new_account_id = client.create_account( | ||
AccountName="test_account", | ||
Email="[email protected]", | ||
RoleName="CustomOrganizationRole", | ||
)["CreateAccountStatus"]["AccountId"] | ||
|
||
with mock.patch.dict(os.environ, {"MOTO_ACCOUNT_ID": new_account_id}): | ||
client_for_new_account = boto3.client("organizations", "us-east-1") | ||
new_account_roots = client_for_new_account.list_roots() | ||
validate_roots(org, new_account_roots) | ||
assert len(new_account_roots["Roots"]) == 1 | ||
assert len(org_roots["Roots"]) == len(new_account_roots["Roots"]) | ||
assert org_roots["Roots"][0] == new_account_roots["Roots"][0] | ||
|
||
|
||
@mock_aws | ||
def test_list_roots_for_account_without_organization_exception(): | ||
client = boto3.client("organizations", region_name="us-east-1") | ||
with pytest.raises(ClientError) as e: | ||
client.list_roots() | ||
ex = e.value | ||
assert ex.operation_name == "ListRoots" | ||
assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 | ||
assert "AWSOrganizationsNotInUseException" in ex.response["Error"]["Code"] | ||
assert ex.response["Error"]["Message"] == ( | ||
"Your account is not a member of an organization." | ||
) | ||
|
||
|
||
@mock_aws | ||
def test_create_organizational_unit(): | ||
client = boto3.client("organizations", region_name="us-east-1") | ||
|