本文整理汇总了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")