Python moto.mock_iam() Examples

The following are 17 code examples of moto.mock_iam(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module moto , or try the search function .
Example #1
Source File: test_iam.py    From stacker with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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
            ) 
Example #2
Source File: test_iam.py    From stacker with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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
            ) 
Example #3
Source File: test_iam.py    From runway with Apache License 2.0 6 votes vote down vote up
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
            ) 
Example #4
Source File: test_securityhub_iam.py    From aws-auto-remediate with GNU General Public License v3.0 5 votes vote down vote up
def sh(self):
        with moto.mock_ec2(), moto.mock_s3(), moto.mock_iam(), moto.mock_kms():
            sh = security_hub_rules.SecurityHubRules(logging)
            yield sh 
Example #5
Source File: conftest.py    From diffy with Apache License 2.0 5 votes vote down vote up
def iam():
    with mock_iam():
        yield boto3.client("iam", region_name="us-east-1") 
Example #6
Source File: test_iam.py    From runway with Apache License 2.0 5 votes vote down vote up
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
            ) 
Example #7
Source File: conftest.py    From cloudaux with Apache License 2.0 5 votes vote down vote up
def iam(sts, conn_dict):
    with mock_iam():
        yield boto3_cached_conn("iam", **conn_dict) 
Example #8
Source File: test_batch_waiters.py    From airflow with Apache License 2.0 5 votes vote down vote up
def iam_client(aws_region):
    with mock_iam():
        yield boto3.client("iam", region_name=aws_region) 
Example #9
Source File: test_securityhub_iam.py    From aws-auto-remediate with GNU General Public License v3.0 5 votes vote down vote up
def sh(self):
        with moto.mock_iam():
            sh = security_hub_rules.SecurityHubRules(logging)
            yield sh 
Example #10
Source File: test_securityhub_iam.py    From aws-auto-remediate with GNU General Public License v3.0 5 votes vote down vote up
def sh(self):
        with moto.mock_iam():
            sh = security_hub_rules.SecurityHubRules(logging)
            yield sh 
Example #11
Source File: test_securityhub_iam.py    From aws-auto-remediate with GNU General Public License v3.0 5 votes vote down vote up
def sh(self):
        with moto.mock_iam():
            sh = security_hub_rules.SecurityHubRules(logging)
            yield sh 
Example #12
Source File: test_securityhub_iam.py    From aws-auto-remediate with GNU General Public License v3.0 5 votes vote down vote up
def sh(self):
        with moto.mock_iam():
            sh = security_hub_rules.SecurityHubRules(logging)
            yield sh 
Example #13
Source File: test_securityhub_iam.py    From aws-auto-remediate with GNU General Public License v3.0 5 votes vote down vote up
def sh(self):
        with moto.mock_iam():
            sh = security_hub_rules.SecurityHubRules(logging)
            yield sh 
Example #14
Source File: test_securityhub_iam.py    From aws-auto-remediate with GNU General Public License v3.0 5 votes vote down vote up
def sh(self):
        with moto.mock_iam():
            sh = security_hub_rules.SecurityHubRules(logging)
            yield sh 
Example #15
Source File: test_securityhub_iam.py    From aws-auto-remediate with GNU General Public License v3.0 5 votes vote down vote up
def sh(self):
        with moto.mock_iam():
            sh = security_hub_rules.SecurityHubRules(logging)
            yield sh 
Example #16
Source File: test_securityhub_iam.py    From aws-auto-remediate with GNU General Public License v3.0 5 votes vote down vote up
def sh(self):
        with moto.mock_iam():
            sh = security_hub_rules.SecurityHubRules(logging)
            yield sh 
Example #17
Source File: test_securityhub_iam.py    From aws-auto-remediate with GNU General Public License v3.0 5 votes vote down vote up
def sh(self):
        with moto.mock_iam():
            sh = security_hub_rules.SecurityHubRules(logging)
            yield sh