diff --git a/IMPLEMENTATION_COVERAGE.md b/IMPLEMENTATION_COVERAGE.md index 2e5f055b9..b8688a365 100644 --- a/IMPLEMENTATION_COVERAGE.md +++ b/IMPLEMENTATION_COVERAGE.md @@ -4723,7 +4723,7 @@ - [ ] update_server_engine_attributes ## organizations -41% implemented +43% implemented - [ ] accept_handshake - [X] attach_policy - [ ] cancel_handshake @@ -4737,7 +4737,7 @@ - [ ] delete_organizational_unit - [ ] delete_policy - [X] describe_account -- [ ] describe_create_account_status +- [X] describe_create_account_status - [ ] describe_handshake - [X] describe_organization - [X] describe_organizational_unit diff --git a/moto/organizations/models.py b/moto/organizations/models.py index 37f8bdeb9..d558616d2 100644 --- a/moto/organizations/models.py +++ b/moto/organizations/models.py @@ -269,10 +269,32 @@ class OrganizationsBackend(BaseBackend): ) return account + def get_account_by_attr(self, attr, value): + account = next( + ( + account + for account in self.accounts + if hasattr(account, attr) and getattr(account, attr) == value + ), + None, + ) + if account is None: + raise RESTError( + "AccountNotFoundException", + "You specified an account that doesn't exist.", + ) + return account + def describe_account(self, **kwargs): account = self.get_account_by_id(kwargs["AccountId"]) return account.describe() + def describe_create_account_status(self, **kwargs): + account = self.get_account_by_attr( + "create_account_status_id", kwargs["CreateAccountRequestId"] + ) + return account.create_account_status + def list_accounts(self): return dict( Accounts=[account.describe()["Account"] for account in self.accounts] diff --git a/moto/organizations/responses.py b/moto/organizations/responses.py index 673bf5adb..f9e0b2e04 100644 --- a/moto/organizations/responses.py +++ b/moto/organizations/responses.py @@ -65,6 +65,13 @@ class OrganizationsResponse(BaseResponse): self.organizations_backend.describe_account(**self.request_params) ) + def describe_create_account_status(self): + return json.dumps( + self.organizations_backend.describe_create_account_status( + **self.request_params + ) + ) + def list_accounts(self): return json.dumps(self.organizations_backend.list_accounts()) diff --git a/tests/test_organizations/test_organizations_boto3.py b/tests/test_organizations/test_organizations_boto3.py index f8eb1328e..3b4a51557 100644 --- a/tests/test_organizations/test_organizations_boto3.py +++ b/tests/test_organizations/test_organizations_boto3.py @@ -159,6 +159,17 @@ def test_create_account(): create_status["AccountName"].should.equal(mockname) +@mock_organizations +def test_describe_create_account_status(): + client = boto3.client("organizations", region_name="us-east-1") + client.create_organization(FeatureSet="ALL")["Organization"] + request_id = client.create_account(AccountName=mockname, Email=mockemail)[ + "CreateAccountStatus" + ]["Id"] + response = client.describe_create_account_status(CreateAccountRequestId=request_id) + validate_create_account_status(response["CreateAccountStatus"]) + + @mock_organizations def test_describe_account(): client = boto3.client("organizations", region_name="us-east-1")