def test_get_region_no_region():
    profiles = {
        'default': {
            'aws_access_key_id': 'AKIA...',
            'aws_secret_access_key': 'SECRET',
        },
        'myuser': {
            'aws_access_key_id': 'AKIA...',
            'aws_secret_access_key': 'SECRET',
        },
        'myrole': {
            'role_arn': 'arn:aws:iam:XXX:role/role_name',
        },
    }
    assert profile.get_region(
        profiles,
        argparse.Namespace(region=None,
                           role_arn=None,
                           source_profile=None,
                           target_profile_name='myrole')) == None
Exemple #2
0
def test_get_region_default_region():
    arguments = argparse.Namespace(region=None,
                                   role_arn=None,
                                   source_profile=None,
                                   target_profile_name='myrole')
    config = {}
    profiles = {
        'default': {
            'aws_access_key_id': 'AKIA...',
            'aws_secret_access_key': 'SECRET',
            'region': 'default-region'
        },
        'myuser': {
            'aws_access_key_id': 'AKIA...',
            'aws_secret_access_key': 'SECRET',
        },
        'myrole': {
            'role_arn': 'arn:aws:iam:XXX:role/role_name',
        },
    }
    assert profile.get_region(profiles, arguments,
                              config) == profiles['default']['region']
def test_get_region_cli_role_arn_and_source_profile():
    profiles = {
        'default': {
            'aws_access_key_id': 'AKIA...',
            'aws_secret_access_key': 'SECRET',
            'region': 'default-region',
        },
        'myuser': {
            'aws_access_key_id': 'AKIA...',
            'aws_secret_access_key': 'SECRET',
            'region': 'myuser-region',
        },
        'myrole': {
            'role_arn': 'arn:aws:iam:XXX:role/role_name',
            'region': 'myrole-region',
        },
    }
    assert profile.get_region(
        profiles,
        argparse.Namespace(
            region=None,
            role_arn='role-arn',
            source_profile='myuser',
            target_profile_name=None)) == profiles['myuser']['region']