def test_ssh_execute(self, mock_ssh, mock_ssh_execute): mock_ssh.return_value = '<SSH object at 0x1024641d0>' mock_ssh_execute.return_value = {'return_code': 0, 'stderr': '', 'stdout': self.username + '\n'} remote_server = SSH(self.hostname, self.username, self.password) remote_server.execute(self.command) self.assertEqual( mock_ssh_execute.return_value, {'return_code': 0, 'stderr': '', 'stdout': '{0}\n' .format(self.username)} )
def test_ssh_execute_timeout(self, mock_ssh, mock_ssh_execute): mock_ssh.return_value = '<SSH object at 0x1024641d0>' mock_ssh_execute.return_exception = "ValueError('TimeOut)" instance = SSH(self.hostname, self.username, self.password, timeout=30) self.assertRaises(Exception, instance.execute(self.command))