Пример #1
0
def test_create_iam_role_failures(make_stubber, make_unique_name, fail_at):
    iam_stubber = make_stubber(batch_versioning.iam.meta.client)
    role_name = make_unique_name('role')
    policy_name = f'{role_name}-policy'
    policy_arn = f'aws:arn:EXAMPLE:{policy_name}'
    error_code = 'TestException'

    if fail_at == 'role':
        iam_stubber.stub_create_role(role_name, error_code=error_code)
    else:
        iam_stubber.stub_create_role(role_name)
        iam_stubber.stub_get_role(role_name)
        if fail_at == 'policy':
            iam_stubber.stub_create_policy(policy_name,
                                           policy_arn,
                                           error_code=error_code)
        else:
            iam_stubber.stub_create_policy(policy_name, policy_arn)
            iam_stubber.stub_get_policy(policy_arn)
            if fail_at == 'attach':
                iam_stubber.stub_attach_role_policy(role_name,
                                                    policy_arn,
                                                    error_code=error_code)
            else:
                iam_stubber.stub_attach_role_policy(role_name, policy_arn)

    with pytest.raises(ClientError) as exc_info:
        batch_versioning.create_iam_role(role_name)
    assert exc_info.value.response['Error']['Code'] == error_code
Пример #2
0
def test_create_iam_role_failures(make_stubber, make_unique_name, stub_runner,
                                  error_code, stop_on_method):
    iam_stubber = make_stubber(batch_versioning.iam.meta.client)
    role_name = make_unique_name('role')
    policy_name = f'{role_name}-policy'
    policy_arn = f'aws:arn:EXAMPLE:{policy_name}'

    with stub_runner(error_code, stop_on_method) as runner:
        runner.add(iam_stubber.stub_create_role, role_name)
        runner.add(iam_stubber.stub_get_role, role_name)
        runner.add(iam_stubber.stub_create_policy, policy_name, policy_arn)
        runner.add(iam_stubber.stub_get_policy, policy_arn)
        runner.add(iam_stubber.stub_attach_role_policy, role_name, policy_arn)

    if error_code is None:
        got_role = batch_versioning.create_iam_role(role_name)
        assert got_role.name == role_name
    else:
        with pytest.raises(ClientError) as exc_info:
            batch_versioning.create_iam_role(role_name)
        assert exc_info.value.response['Error']['Code'] == error_code
Пример #3
0
def test_create_iam_role(make_stubber, make_unique_name):
    iam_stubber = make_stubber(batch_versioning.iam.meta.client)
    role_name = make_unique_name('role')
    policy_name = f'{role_name}-policy'
    policy_arn = f'aws:arn:EXAMPLE:{policy_name}'

    iam_stubber.stub_create_role(role_name)
    iam_stubber.stub_get_role(role_name)
    iam_stubber.stub_create_policy(policy_name, policy_arn)
    iam_stubber.stub_get_policy(policy_arn)
    iam_stubber.stub_attach_role_policy(role_name, policy_arn)

    role = batch_versioning.create_iam_role(role_name)
    assert role.name == role_name