本文整理匯總了Python中moto.mock_iam方法的典型用法代碼示例。如果您正苦於以下問題:Python moto.mock_iam方法的具體用法?Python moto.mock_iam怎麽用?Python moto.mock_iam使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類moto
的用法示例。
在下文中一共展示了moto.mock_iam方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_create_service_role
# 需要導入模塊: import moto [as 別名]
# 或者: from moto import mock_iam [as 別名]
def test_create_service_role(self):
"""Test create service role."""
role_name = "ecsServiceRole"
policy_name = "AmazonEC2ContainerServiceRolePolicy"
with mock_iam():
client = boto3.client("iam", region_name=REGION)
with self.assertRaises(ClientError):
client.get_role(RoleName=role_name)
self.assertTrue(
create_ecs_service_role(
context=self.context,
provider=self.provider,
)
)
role = client.get_role(RoleName=role_name)
self.assertIn("Role", role)
self.assertEqual(role_name, role["Role"]["RoleName"])
client.get_role_policy(
RoleName=role_name,
PolicyName=policy_name
)
示例2: test_create_service_role
# 需要導入模塊: import moto [as 別名]
# 或者: from moto import mock_iam [as 別名]
def test_create_service_role(self):
role_name = "ecsServiceRole"
policy_name = "AmazonEC2ContainerServiceRolePolicy"
with mock_iam():
client = boto3.client("iam", region_name=REGION)
with self.assertRaises(ClientError):
client.get_role(RoleName=role_name)
self.assertTrue(
create_ecs_service_role(
context=self.context,
provider=self.provider,
)
)
role = client.get_role(RoleName=role_name)
self.assertIn("Role", role)
self.assertEqual(role_name, role["Role"]["RoleName"])
client.get_role_policy(
RoleName=role_name,
PolicyName=policy_name
)
示例3: test_create_service_role_already_exists
# 需要導入模塊: import moto [as 別名]
# 或者: from moto import mock_iam [as 別名]
def test_create_service_role_already_exists(self):
role_name = "ecsServiceRole"
policy_name = "AmazonEC2ContainerServiceRolePolicy"
with mock_iam():
client = boto3.client("iam", region_name=REGION)
client.create_role(
RoleName=role_name,
AssumeRolePolicyDocument=get_ecs_assumerole_policy().to_json()
)
self.assertTrue(
create_ecs_service_role(
context=self.context,
provider=self.provider,
)
)
role = client.get_role(RoleName=role_name)
self.assertIn("Role", role)
self.assertEqual(role_name, role["Role"]["RoleName"])
client.get_role_policy(
RoleName=role_name,
PolicyName=policy_name
)
示例4: sh
# 需要導入模塊: import moto [as 別名]
# 或者: from moto import mock_iam [as 別名]
def sh(self):
with moto.mock_iam():
sh = security_hub_rules.SecurityHubRules(logging)
yield sh
示例5: iam_client
# 需要導入模塊: import moto [as 別名]
# 或者: from moto import mock_iam [as 別名]
def iam_client(aws_region):
with mock_iam():
yield boto3.client("iam", region_name=aws_region)
示例6: iam
# 需要導入模塊: import moto [as 別名]
# 或者: from moto import mock_iam [as 別名]
def iam(sts, conn_dict):
with mock_iam():
yield boto3_cached_conn("iam", **conn_dict)
示例7: test_create_service_role_already_exists
# 需要導入模塊: import moto [as 別名]
# 或者: from moto import mock_iam [as 別名]
def test_create_service_role_already_exists(self):
"""Test create service role already exists."""
role_name = "ecsServiceRole"
policy_name = "AmazonEC2ContainerServiceRolePolicy"
with mock_iam():
client = boto3.client("iam", region_name=REGION)
client.create_role(
RoleName=role_name,
AssumeRolePolicyDocument=get_ecs_assumerole_policy().to_json()
)
self.assertTrue(
create_ecs_service_role(
context=self.context,
provider=self.provider,
)
)
role = client.get_role(RoleName=role_name)
self.assertIn("Role", role)
self.assertEqual(role_name, role["Role"]["RoleName"])
client.get_role_policy(
RoleName=role_name,
PolicyName=policy_name
)
示例8: iam
# 需要導入模塊: import moto [as 別名]
# 或者: from moto import mock_iam [as 別名]
def iam():
with mock_iam():
yield boto3.client("iam", region_name="us-east-1")