def test_unix_set_prompt_expection2(self): uobject = MagicMock(spec=UnixHost) uobject.execute = MagicMock(return_value=1) uobject.prompt = MagicMock(return_value="TOBY") type(uobject).response = PropertyMock(side_effect=['vsh $']) self.assertRaises(Exception, lambda: UnixHost.set_prompt(uobject, prompt='TOBY'))
def test_unix_su_user_password(self): uobject = MagicMock(spec=UnixHost) uobject.execute = MagicMock(return_value=1) uobject.prompt = '$ ' uobject.set_prompt = MagicMock uobject.shell.return_value.response.return_value = "root" self.assertTrue(UnixHost.su(uobject, password='******'))
def test_unix_disconnect(self): uobject = MagicMock(spec=UnixHost) uobject.connect_mode = 'ssh' uobject.handle = MagicMock() uobject.log_handle = MagicMock() uobject.close_obj = MagicMock() self.assertTrue(UnixHost.close(uobject))
def test_unix_execute(self): uobject = MagicMock(spec=UnixHost) uobject.handle = MagicMock() uobject.prompt = MagicMock(return_value='%') uobject.handle.execute = MagicMock(return_value='regress') uobject.shell_timeout = 60 self.assertEqual(UnixHost.execute(uobject, command='ls'), 'regress')
def test_unix_reboot(self, patch1): uobject = MagicMock(spec=UnixHost) uobject.su = MagicMock() uobject.shell = MagicMock(return_value=-1) uobject.is_alive = MagicMock(return_value=False) uobject.host = 'dummy' uobject.reconnect = MagicMock() self.assertTrue(UnixHost.reboot(uobject))
def test_unix_su_exception(self): uobject = MagicMock(spec=UnixHost) uobject.execute = MagicMock(side_effect=[1, 1]) uobject.prompt = '$ ' uobject.set_prompt = MagicMock uobject.shell = MagicMock(return_value=-1) print('toto') self.assertRaises(Exception, lambda: UnixHost.su(uobject, password='******'))
def test_unix_su(self): uobject = MagicMock(spec=UnixHost) uobject.execute = MagicMock(return_value=1) uobject.get_su_credentials = MagicMock(return_value=('root', 'Embe1mpls')) uobject.prompt = '$ ' uobject.set_prompt = MagicMock uobject.shell.return_value.response.return_value = "root" self.assertTrue(UnixHost.su(uobject))
def test_unix_set_prompt_csh(self): uobject = MagicMock(spec=UnixHost) uobject.execute = MagicMock(return_value=1) uobject.prompt = MagicMock(return_value="TOBY") type(uobject).response = PropertyMock(side_effect=['csh $']) self.assertTrue(UnixHost.set_prompt(uobject, prompt='TOBY'))
def test_unix_close2(self): self.test_unix_disconnect2() uobject = MagicMock(spec=UnixHost) self.assertTrue(UnixHost.close(uobject))