#2163 - Delete IAM group; Add test case and align error message with AWS
This commit is contained in:
parent
876ff476f1
commit
cd5b64b0c5
@ -1225,7 +1225,9 @@ class IAMBackend(BaseBackend):
|
|||||||
try:
|
try:
|
||||||
del self.groups[group_name]
|
del self.groups[group_name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise IAMNotFoundException("Group {0} not found".format(group_name))
|
raise IAMNotFoundException(
|
||||||
|
"The group with name {0} cannot be found.".format(group_name)
|
||||||
|
)
|
||||||
|
|
||||||
def create_user(self, user_name, path="/"):
|
def create_user(self, user_name, path="/"):
|
||||||
if user_name in self.users:
|
if user_name in self.users:
|
||||||
|
@ -429,10 +429,10 @@ class IamResponse(BaseResponse):
|
|||||||
return template.render(name="GetGroupPolicyResponse", **policy_result)
|
return template.render(name="GetGroupPolicyResponse", **policy_result)
|
||||||
|
|
||||||
def delete_group(self):
|
def delete_group(self):
|
||||||
group_name = self._get_param('GroupName')
|
group_name = self._get_param("GroupName")
|
||||||
iam_backend.delete_group(group_name)
|
iam_backend.delete_group(group_name)
|
||||||
template = self.response_template(GENERIC_EMPTY_TEMPLATE)
|
template = self.response_template(GENERIC_EMPTY_TEMPLATE)
|
||||||
return template.render(name='DeleteGroup')
|
return template.render(name="DeleteGroup")
|
||||||
|
|
||||||
def create_user(self):
|
def create_user(self):
|
||||||
user_name = self._get_param("UserName")
|
user_name = self._get_param("UserName")
|
||||||
|
@ -8,6 +8,7 @@ import sure # noqa
|
|||||||
|
|
||||||
from nose.tools import assert_raises
|
from nose.tools import assert_raises
|
||||||
from boto.exception import BotoServerError
|
from boto.exception import BotoServerError
|
||||||
|
from botocore.exceptions import ClientError
|
||||||
from moto import mock_iam, mock_iam_deprecated
|
from moto import mock_iam, mock_iam_deprecated
|
||||||
|
|
||||||
MOCK_POLICY = """
|
MOCK_POLICY = """
|
||||||
@ -186,10 +187,21 @@ def test_list_group_policies():
|
|||||||
|
|
||||||
@mock_iam
|
@mock_iam
|
||||||
def test_delete_group():
|
def test_delete_group():
|
||||||
conn = boto3.client('iam', region_name='us-east-1')
|
conn = boto3.client("iam", region_name="us-east-1")
|
||||||
conn.create_group(GroupName='my-group')
|
conn.create_group(GroupName="my-group")
|
||||||
groups = conn.list_groups()
|
groups = conn.list_groups()
|
||||||
assert groups['Groups'][0]['GroupName'] == 'my-group'
|
assert groups["Groups"][0]["GroupName"] == "my-group"
|
||||||
assert len(groups['Groups']) == 1
|
assert len(groups["Groups"]) == 1
|
||||||
conn.delete_group(GroupName='my-group')
|
conn.delete_group(GroupName="my-group")
|
||||||
conn.list_groups()['Groups'].should.be.empty
|
conn.list_groups()["Groups"].should.be.empty
|
||||||
|
|
||||||
|
|
||||||
|
@mock_iam
|
||||||
|
def test_delete_unknown_group():
|
||||||
|
conn = boto3.client("iam", region_name="us-east-1")
|
||||||
|
with assert_raises(ClientError) as err:
|
||||||
|
conn.delete_group(GroupName="unknown-group")
|
||||||
|
err.exception.response["Error"]["Code"].should.equal("NoSuchEntity")
|
||||||
|
err.exception.response["Error"]["Message"].should.equal(
|
||||||
|
"The group with name unknown-group cannot be found."
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user