def test_ensure_key_pair_nonexist_local_public(runner, fake_ec2_resource, fake_ec2_client, fake_ssh_path_function, fake_key_pair_info):
fake_ec2_client.create_key_pair.return_value = {
'KeyMaterial': 'test key'
}
assert not os.system('touch {}.pub'.format(fake_ssh_path_function('test')))
with mock.patch('boto3.resource') as mocked_resource, mock.patch('boto3.client') as mocked_client, mock.patch('deploy.utils.decorators._ssh_path', new=fake_ssh_path_function):
mocked_resource.return_value = fake_ec2_resource
mocked_client.return_value = fake_ec2_client
result = runner.invoke(dummy, input='\n')
assert result.exit_code == exit_codes.SUCCESS
fake_ec2_resource.KeyPair.assert_called_once_with('test')
fake_key_pair_info.delete.assert_called_once_with()
fake_ec2_client.create_key_pair.assert_called_once_with(KeyName='test')
with open(fake_ssh_path_function('test'), 'r') as f:
assert f.read() == 'test key'
s = os.stat(fake_ssh_path_function('test')).st_mode
# owner
assert bool(s & stat.S_IRUSR)
assert bool(s & stat.S_IWUSR)
assert not bool(s & stat.S_IXUSR)
# group
assert not bool(s & stat.S_IRWXG)
# others
assert not bool(s & stat.S_IRWXO)
test_decorators_ensure_key_pair.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录