adding list_create_account_status to organization #3691 (#3692)

* adding list_create_account_status to organization #3691

* removing todo comment

Co-authored-by: Chris Walters <chriskwalters@hotmail.com>
This commit is contained in:
chrisw-dev 2021-02-15 03:39:23 -08:00 committed by GitHub
parent f64532ed40
commit def46b5130
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 2 deletions

View File

@ -6416,7 +6416,7 @@
## organizations
<details>
<summary>70% implemented</summary>
<summary>72% implemented</summary>
- [ ] accept_handshake
- [X] attach_policy
@ -6450,7 +6450,7 @@
- [X] list_accounts_for_parent
- [X] list_aws_service_access_for_organization
- [X] list_children
- [ ] list_create_account_status
- [X] list_create_account_status
- [X] list_delegated_administrators
- [X] list_delegated_services_for_account
- [ ] list_handshakes_for_account

View File

@ -459,6 +459,27 @@ class OrganizationsBackend(BaseBackend):
)
return account.create_account_status
def list_create_account_status(self, **kwargs):
requested_states = kwargs.get("States")
if not requested_states:
requested_states = ["IN_PROGRESS", "SUCCEEDED", "FAILED"]
accountStatuses = []
for account in self.accounts:
create_account_status = account.create_account_status["CreateAccountStatus"]
if create_account_status["State"] in requested_states:
accountStatuses.append(create_account_status)
token = kwargs.get("NextToken")
if token:
start = int(token)
else:
start = 0
max_results = int(kwargs.get("MaxResults", 123))
accounts_resp = accountStatuses[start : start + max_results]
next_token = None
if max_results and len(accountStatuses) > (start + max_results):
next_token = str(len(accounts_resp))
return dict(CreateAccountStatuses=accounts_resp, NextToken=next_token)
def list_accounts(self):
return dict(Accounts=[account.describe() for account in self.accounts])

View File

@ -77,6 +77,11 @@ class OrganizationsResponse(BaseResponse):
)
)
def list_create_account_status(self):
return json.dumps(
self.organizations_backend.list_create_account_status(**self.request_params)
)
def list_accounts(self):
return json.dumps(self.organizations_backend.list_accounts())

View File

@ -352,6 +352,69 @@ def test_list_children_exception():
ex.response["Error"]["Message"].should.equal("You specified an invalid value.")
@mock_organizations
def test_list_create_account_status():
client = boto3.client("organizations", region_name="us-east-1")
client.create_organization(FeatureSet="ALL")["Organization"]
response = client.list_create_account_status()
createAccountStatuses = response["CreateAccountStatuses"]
createAccountStatuses.should.have.length_of(1)
validate_create_account_status(createAccountStatuses[0])
request_id = client.create_account(AccountName=mockname, Email=mockemail)[
"CreateAccountStatus"
]["Id"]
response = client.list_create_account_status()
createAccountStatuses = response["CreateAccountStatuses"]
createAccountStatuses.should.have.length_of(2)
for createAccountStatus in createAccountStatuses:
validate_create_account_status(createAccountStatus)
@mock_organizations
def test_list_create_account_status_succeeded():
client = boto3.client("organizations", region_name="us-east-1")
client.create_organization(FeatureSet="ALL")["Organization"]
requiredStates = ["SUCCEEDED"]
response = client.list_create_account_status(States=requiredStates)
createAccountStatuses = response["CreateAccountStatuses"]
createAccountStatuses.should.have.length_of(1)
validate_create_account_status(createAccountStatuses[0])
@mock_organizations
def test_list_create_account_status_in_progress():
client = boto3.client("organizations", region_name="us-east-1")
client.create_organization(FeatureSet="ALL")["Organization"]
requiredStates = ["IN_PROGRESS"]
response = client.list_create_account_status(States=requiredStates)
createAccountStatuses = response["CreateAccountStatuses"]
createAccountStatuses.should.have.length_of(0)
@mock_organizations
def test_get_paginated_list_create_account_status():
client = boto3.client("organizations", region_name="us-east-1")
client.create_organization(FeatureSet="ALL")["Organization"]
for i in range(5):
request_id = client.create_account(AccountName=mockname, Email=mockemail)[
"CreateAccountStatus"
]["Id"]
response = client.list_create_account_status(MaxResults=2)
createAccountStatuses = response["CreateAccountStatuses"]
createAccountStatuses.should.have.length_of(2)
for createAccountStatus in createAccountStatuses:
validate_create_account_status(createAccountStatus)
next_token = response["NextToken"]
next_token.should_not.be.none
response2 = client.list_create_account_status(NextToken=next_token)
createAccountStatuses.extend(response2["CreateAccountStatuses"])
createAccountStatuses.should.have.length_of(6)
assert "NextToken" not in response2.keys()
for createAccountStatus in createAccountStatuses:
validate_create_account_status(createAccountStatus)
# Service Control Policies
policy_doc01 = dict(
Version="2012-10-17",