test_HPELeftHandClient_MockSSH.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:deb-python-hplefthandclient 作者: openstack 项目源码 文件源码
def test_run_ssh_with_exception(self):
        ssh_client = ssh.HPELeftHandSSHClient(ip, user, password,
                                              known_hosts_file=None,
                                              missing_key_policy=paramiko.
                                              AutoAddPolicy)

        ssh_client.check_ssh_injection = mock.Mock()
        ssh_client.check_ssh_injection.return_value = True
        ssh_client._ssh_execute = mock.Mock()
        ssh_client._ssh_execute.side_effect = Exception('End this here')
        ssh_client._create_ssh = mock.Mock()
        ssh_client._create_ssh.return_value = True
        ssh_client.ssh = mock.Mock()
        ssh_client.ssh.get_transport.is_alive.return_value = True

        command = ['fake']
        self.assertRaises(exceptions.SSHException, ssh_client._run_ssh,
                          command, attempts=1)
        ssh_client.check_ssh_injection.assert_called_once()
        ssh_client._ssh_execute.assert_called_once()
        ssh_client._create_ssh.assert_not_called()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号