예제 #1
0
def _test_get_region_error(mocker, capsys, response=None, error=None):
    if (response and error) or (not response and not error):
        raise ValueError('Invalid arguments')
    elif response:
        mocker.patch('mount_efs.urlopen', return_value=response)
    elif error:
        mocker.patch('mount_efs.urlopen', side_effect=error)

    with pytest.raises(SystemExit) as ex:
        mount_efs.get_region()

    assert 0 != ex.value.code

    out, err = capsys.readouterr()
    assert 'Error retrieving region' in err
예제 #2
0
def test_get_region_py3_no_charset(mocker):
    mocker.patch('mount_efs.get_aws_ec2_metadata_token', return_value=None)
    mocker.patch('mount_efs.urlopen',
                 return_value=MockUrlLibResponse(
                     data=bytearray(INSTANCE_DOCUMENT, 'us-ascii')))

    assert 'us-east-1' == mount_efs.get_region()
예제 #3
0
def test_get_region_py3_utf8_charset(mocker):
    charset = 'utf-8'
    mocker.patch('mount_efs.urlopen',
                 return_value=MockUrlLibResponse(
                     data=bytearray(INSTANCE_DOCUMENT, charset)),
                 headers=MockHeaders(content_charset=charset))

    assert 'us-east-1' == mount_efs.get_region()
예제 #4
0
def test_get_region(mocker):
    mocker.patch('mount_efs.urlopen', return_value=MockUrlLibResponse())

    assert 'us-east-1' == mount_efs.get_region()
예제 #5
0
def test_get_region_without_token(mocker):
    mocker.patch('mount_efs.get_aws_ec2_metadata_token', return_value=None)
    mocker.patch('mount_efs.urlopen', return_value=MockUrlLibResponse())
    assert 'us-east-1' == mount_efs.get_region()