Organizations: Add delete_organizational_unit (#5635)

This commit is contained in:
David 2022-11-03 17:13:06 +01:00 committed by GitHub
parent 7eb925839e
commit 79aaf2bc03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

@ -405,6 +405,13 @@ class OrganizationsBackend(BaseBackend):
self.attach_policy(PolicyId=utils.DEFAULT_POLICY_ID, TargetId=new_ou.id)
return new_ou.describe()
def delete_organizational_unit(self, **kwargs):
ou_to_delete = self.get_organizational_unit_by_id(
kwargs["OrganizationalUnitId"]
)
self.ou.remove(ou_to_delete)
return {}
def update_organizational_unit(self, **kwargs):
for ou in self.ou:
if ou.name == kwargs["Name"]:

View File

@ -41,6 +41,11 @@ class OrganizationsResponse(BaseResponse):
self.organizations_backend.create_organizational_unit(**self.request_params)
)
def delete_organizational_unit(self):
return json.dumps(
self.organizations_backend.delete_organizational_unit(**self.request_params)
)
def update_organizational_unit(self):
return json.dumps(
self.organizations_backend.update_organizational_unit(**self.request_params)

View File

@ -110,6 +110,31 @@ def test_create_organizational_unit():
response["OrganizationalUnit"]["Name"].should.equal(ou_name)
@mock_organizations
def test_delete_organizational_unit():
client = boto3.client("organizations", region_name="us-east-1")
org = client.create_organization(FeatureSet="ALL")["Organization"]
root_id = client.list_roots()["Roots"][0]["Id"]
ou_name = "ou01"
response = client.create_organizational_unit(ParentId=root_id, Name=ou_name)
validate_organizational_unit(org, response)
# delete organizational unit
ou_id = response["OrganizationalUnit"]["Id"]
response = client.delete_organizational_unit(OrganizationalUnitId=ou_id)
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
# verify the deletion
with pytest.raises(ClientError) as e:
client.describe_organizational_unit(OrganizationalUnitId=ou_id)
ex = e.value
ex.operation_name.should.equal("DescribeOrganizationalUnit")
ex.response["Error"]["Code"].should.equal("400")
ex.response["Error"]["Message"].should.contain(
"OrganizationalUnitNotFoundException"
)
@mock_organizations
def test_describe_organizational_unit():
client = boto3.client("organizations", region_name="us-east-1")