@@ -13,11 +13,13 @@ def test_local_exec_command(self, local_command):
1313 host .exec_command ('ls' )
1414 inspector .local_command .assert_called_once_with ('ls' )
1515
16+ @patch ('hwinfo.tools.inspector.get_ssh_client' )
1617 @patch ('hwinfo.tools.inspector.remote_command' )
17- def test_remote_exec_command (self , remote_command ):
18+ def test_remote_exec_command (self , remote_command , get_ssh_client ):
19+ mclient = get_ssh_client .return_value = mock .MagicMock ()
1820 host = inspector .Host ('mymachine' , 'root' , 'pass' )
1921 host .exec_command ('ls' )
20- inspector .remote_command .assert_called_once_with ('mymachine' , 'root' , 'pass' , 'ls' )
22+ inspector .remote_command .assert_called_once_with (mclient , 'ls' )
2123
2224 @patch ('hwinfo.tools.inspector.Host.exec_command' )
2325 def test_get_pci_devices (self , exec_command ):
@@ -35,6 +37,15 @@ def test_get_info(self, mock_exec_command, mock_dmidecode_parser_cls):
3537 rec = host .get_info ()
3638 self .assertEqual (rec , {'key' :'value' })
3739
40+ def test_is_not_remote (self ):
41+ host = inspector .Host ()
42+ self .assertEqual (host .is_remote (), False )
43+
44+ @patch ('hwinfo.tools.inspector.get_ssh_client' )
45+ def test_is_remote (self , get_ssh_client ):
46+ get_ssh_client .return_value = mock .MagicMock ()
47+ host = inspector .Host ('test' , 'user' , 'pass' )
48+ self .assertEqual (host .is_remote (), True )
3849
3950class RemoteCommandTests (unittest .TestCase ):
4051
@@ -47,15 +58,15 @@ def setUp(self):
4758 def test_ssh_connect (self , ssh_client_cls ):
4859 client = ssh_client_cls .return_value = mock .Mock ()
4960 client .exec_command .return_value = self .stdout , self .stdin , self .stderr
50- inspector .remote_command ('test' , 'user' , 'pass' , 'ls ' )
61+ inspector .get_ssh_client ('test' , 'user' , 'pass' )
5162 client .connect .assert_called_with ('test' , password = 'pass' , username = 'user' , timeout = 10 )
5263
5364 @patch ('paramiko.SSHClient' )
5465 def test_ssh_connect_error (self , ssh_client_cls ):
5566 client = ssh_client_cls .return_value = mock .Mock ()
5667 client .exec_command .return_value = self .stdout , self .stdin , StringIO ("Error" )
5768 with self .assertRaises (Exception ) as context :
58- inspector .remote_command ('test' , 'user' , 'pass' , 'ls' )
69+ inspector .remote_command (client , 'ls' )
5970 self .assertEqual (context .exception .message , "stderr: ['Error']" )
6071
6172class LocalCommandTests (unittest .TestCase ):
0 commit comments