fix(org): close_account matches public API (#5072)
This commit is contained in:
parent
8ad121282f
commit
a79df7bc87
@ -95,19 +95,6 @@ class FakeAccount(BaseModel):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
|
||||||
def close_account_status(self):
|
|
||||||
return {
|
|
||||||
"CloseAccountStatus": {
|
|
||||||
"Id": self.create_account_status_id,
|
|
||||||
"AccountName": self.name,
|
|
||||||
"State": "SUCCEEDED",
|
|
||||||
"RequestedTimestamp": unix_time(datetime.datetime.utcnow()),
|
|
||||||
"CompletedTimestamp": unix_time(datetime.datetime.utcnow()),
|
|
||||||
"AccountId": self.id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def describe(self):
|
def describe(self):
|
||||||
return {
|
return {
|
||||||
"Id": self.id,
|
"Id": self.id,
|
||||||
@ -119,6 +106,11 @@ class FakeAccount(BaseModel):
|
|||||||
"JoinedTimestamp": unix_time(self.create_time),
|
"JoinedTimestamp": unix_time(self.create_time),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
# TODO: The CloseAccount spec allows the account to pass through a
|
||||||
|
# "PENDING_CLOSURE" state before reaching the SUSPNEDED state.
|
||||||
|
self.status = "SUSPENDED"
|
||||||
|
|
||||||
|
|
||||||
class FakeOrganizationalUnit(BaseModel):
|
class FakeOrganizationalUnit(BaseModel):
|
||||||
def __init__(self, organization, **kwargs):
|
def __init__(self, organization, **kwargs):
|
||||||
@ -459,14 +451,10 @@ class OrganizationsBackend(BaseBackend):
|
|||||||
return new_account.create_account_status
|
return new_account.create_account_status
|
||||||
|
|
||||||
def close_account(self, **kwargs):
|
def close_account(self, **kwargs):
|
||||||
for account_index in range(len(self.accounts)):
|
for account in self.accounts:
|
||||||
if kwargs["AccountId"] == self.accounts[account_index].id:
|
if account.id == kwargs["AccountId"]:
|
||||||
closed_account_status = self.accounts[
|
account.close()
|
||||||
account_index
|
return
|
||||||
].close_account_status
|
|
||||||
del self.accounts[account_index]
|
|
||||||
return closed_account_status
|
|
||||||
|
|
||||||
raise AccountNotFoundException
|
raise AccountNotFoundException
|
||||||
|
|
||||||
def get_account_by_id(self, account_id):
|
def get_account_by_id(self, account_id):
|
||||||
|
@ -135,17 +135,3 @@ def validate_service_control_policy(org, response):
|
|||||||
response.should.have.key("PolicySummary").should.be.a(dict)
|
response.should.have.key("PolicySummary").should.be.a(dict)
|
||||||
response.should.have.key("Content").should.be.a(str)
|
response.should.have.key("Content").should.be.a(str)
|
||||||
validate_policy_summary(org, response["PolicySummary"])
|
validate_policy_summary(org, response["PolicySummary"])
|
||||||
|
|
||||||
|
|
||||||
def validate_account_created(accounts_list, account_id):
|
|
||||||
account_created = False
|
|
||||||
for account in accounts_list:
|
|
||||||
if account_id == account["Id"]:
|
|
||||||
account_created = True
|
|
||||||
assert account_created
|
|
||||||
|
|
||||||
|
|
||||||
def validate_account_closed(accounts_list, account_id):
|
|
||||||
for account in accounts_list:
|
|
||||||
if account_id == account["Id"]:
|
|
||||||
assert False
|
|
||||||
|
@ -27,8 +27,6 @@ from .organizations_test_utils import (
|
|||||||
validate_create_account_status,
|
validate_create_account_status,
|
||||||
validate_service_control_policy,
|
validate_service_control_policy,
|
||||||
validate_policy_summary,
|
validate_policy_summary,
|
||||||
validate_account_created,
|
|
||||||
validate_account_closed,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -176,30 +174,38 @@ def test_create_account():
|
|||||||
|
|
||||||
|
|
||||||
@mock_organizations
|
@mock_organizations
|
||||||
def test_close_account():
|
def test_close_account_returns_nothing():
|
||||||
client = boto3.client("organizations", region_name="us-east-1")
|
client = boto3.client("organizations", region_name="us-east-1")
|
||||||
client.create_organization(FeatureSet="ALL")
|
client.create_organization(FeatureSet="ALL")
|
||||||
create_status = client.create_account(AccountName=mockname, Email=mockemail)[
|
create_status = client.create_account(AccountName=mockname, Email=mockemail)[
|
||||||
"CreateAccountStatus"
|
"CreateAccountStatus"
|
||||||
]
|
]
|
||||||
created_account_id = create_status["AccountId"]
|
created_account_id = create_status["AccountId"]
|
||||||
accounts_list_before = client.list_accounts()["Accounts"]
|
|
||||||
validate_account_created(
|
|
||||||
accounts_list=accounts_list_before,
|
|
||||||
account_id=created_account_id,
|
|
||||||
)
|
|
||||||
|
|
||||||
client.close_account(AccountId=created_account_id)
|
resp = client.close_account(AccountId=created_account_id)
|
||||||
|
|
||||||
accounts_list_after = client.list_accounts()["Accounts"]
|
del resp["ResponseMetadata"]
|
||||||
validate_account_closed(accounts_list_after, created_account_id)
|
|
||||||
number_accounts_before = len(accounts_list_before)
|
assert resp == {}
|
||||||
number_accounts_after = len(accounts_list_after)
|
|
||||||
(number_accounts_before - number_accounts_after).should.equal(1)
|
|
||||||
|
|
||||||
|
|
||||||
@mock_organizations
|
@mock_organizations
|
||||||
def test_close_account_exception():
|
def test_close_account_puts_account_in_suspended_status():
|
||||||
|
client = boto3.client("organizations", region_name="us-east-1")
|
||||||
|
client.create_organization(FeatureSet="ALL")
|
||||||
|
create_status = client.create_account(AccountName=mockname, Email=mockemail)[
|
||||||
|
"CreateAccountStatus"
|
||||||
|
]
|
||||||
|
created_account_id = create_status["AccountId"]
|
||||||
|
|
||||||
|
client.close_account(AccountId=created_account_id)
|
||||||
|
|
||||||
|
account = client.describe_account(AccountId=created_account_id)["Account"]
|
||||||
|
account["Status"].should.equal("SUSPENDED")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_organizations
|
||||||
|
def test_close_account_id_not_in_org_raises_exception():
|
||||||
client = boto3.client("organizations", region_name="us-east-1")
|
client = boto3.client("organizations", region_name="us-east-1")
|
||||||
client.create_organization(FeatureSet="ALL")
|
client.create_organization(FeatureSet="ALL")
|
||||||
uncreated_fake_account_id = "123456789101"
|
uncreated_fake_account_id = "123456789101"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user