class TestSshConnection(unittest.TestCase): """Testing SshConnection.""" def setUp(self): """Setup test env.""" self.connection = SshConnection( 'fake', 'fake', 'fake', 'fake', 'fake', 'fake') self.connection._connected = True def test_run_command_exception_eof(self): """Testing exception in run_command.""" from pexpect import exceptions self.connection._ssh = mock.Mock() self.connection._ssh.sendline = mock.Mock() self.connection._ssh.sendline.side_effect = exceptions.EOF('except') self.connection.run_command('test') self.assertFalse(self.connection._connected) self.assertIsNone(self.connection._ssh) def test_run_command_exception_pxssh(self): """Testing exception in run_command.""" from pexpect import pxssh self.connection._ssh = mock.Mock() self.connection._ssh.sendline = mock.Mock() self.connection._ssh.sendline.side_effect = pxssh.ExceptionPxssh( 'except') self.connection.run_command('test') self.assertFalse(self.connection._connected) self.assertIsNone(self.connection._ssh) def test_run_command_assertion_error(self): """Testing exception in run_command.""" self.connection._ssh = mock.Mock() self.connection._ssh.sendline = mock.Mock() self.connection._ssh.sendline.side_effect = AssertionError('except') self.connection.run_command('test') self.assertFalse(self.connection._connected) self.assertIsNone(self.connection._ssh)
def setUp(self): """Setup test env.""" self.connection = SshConnection('fake', 'fake', 'fake', 'fake', 'fake') self.connection._connected = True
def setUp(self): """Setup test env.""" self.connection = SshConnection( 'fake', 'fake', 'fake', 'fake', 'fake', 'fake') self.connection._connected = True