IAM: get_role should thrown when role is unexisting

This commit is contained in:
Simon-Pierre Gingras 2015-06-29 10:46:05 -04:00
parent 20306c9b24
commit db7d7a9330
2 changed files with 8 additions and 0 deletions

View File

@ -249,6 +249,7 @@ class IAMBackend(BaseBackend):
for role in self.get_roles():
if role.name == role_name:
return role
raise BotoServerError(404, 'Not Found')
def get_roles(self):
return self.roles.values()

View File

@ -6,6 +6,7 @@ from nose.tools import assert_raises, assert_equals, assert_not_equals
from boto.exception import BotoServerError
import base64
from moto import mock_iam
from nose.tools import raises
@mock_iam()
@ -39,6 +40,12 @@ def test_upload_server_cert():
cert.server_certificate_name.should.equal("certname")
cert.arn.should.equal("arn:aws:iam::123456789012:server-certificate/certname")
@mock_iam()
@raises(BotoServerError)
def test_get_role__should_throw__when_role_does_not_exist():
conn = boto.connect_iam()
conn.get_role('unexisting_role')
@mock_iam()
def test_create_role_and_instance_profile():