<s> import unittest <EOL> from mock import patch , MagicMock <EOL> from ncclient import manager <EOL> class TestManager ( unittest . TestCase ) : <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_ssh ( self , mock_ssh ) : <EOL> m = MagicMock ( ) <EOL> mock_ssh . return_value = m <EOL> conn = self . _mock_manager ( ) <EOL> self . assertEqual ( conn . _session , m ) <EOL> self . assertEqual ( conn . _timeout , <NUM_LIT:10> ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_connect_ssh ( self , mock_ssh ) : <EOL> manager . connect ( host = '<STR_LIT:host>' ) <EOL> mock_ssh . assert_called_once_with ( host = '<STR_LIT:host>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_connect_ioproc ( self , mock_ssh ) : <EOL> manager . connect ( host = '<STR_LIT:localhost>' , device_params = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True } ) <EOL> mock_ssh . assert_called_once_with ( host = '<STR_LIT:localhost>' , <EOL> device_params = { '<STR_LIT>' : True , '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_ssh2 ( self , mock_session , mock_hex , mock_trans , mock_socket ) : <EOL> conn = self . _mock_manager ( ) <EOL> self . assertEqual ( mock_trans . called , <NUM_LIT:1> ) <EOL> self . assertEqual ( conn . _timeout , <NUM_LIT:10> ) <EOL> self . assertEqual ( conn . _device_handler . device_params , { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( <EOL> conn . _device_handler . __class__ . __name__ , <EOL> "<STR_LIT>" ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_ioproc ( self , mock_connect , mock_ioproc ) : <EOL> conn = manager . connect ( host = '<STR_LIT:localhost>' , <EOL> port = <NUM_LIT> , <EOL> username = '<STR_LIT:user>' , <EOL> password = '<STR_LIT:password>' , <EOL> timeout = <NUM_LIT:10> , <EOL> device_params = { '<STR_LIT>' : True , '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> hostkey_verify = False ) <EOL> self . assertEqual ( mock_connect . called , <NUM_LIT:1> ) <EOL> self . assertEqual ( conn . _timeout , <NUM_LIT:10> ) <EOL> self . assertEqual ( conn . _device_handler . device_params , { '<STR_LIT>' : True , '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( <EOL> conn . _device_handler . __class__ . __name__ , <EOL> "<STR_LIT>" ) <EOL> def test_make_device_handler ( self ) : <EOL> device_handler = manager . make_device_handler ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( <EOL> device_handler . __class__ . __name__ , <EOL> "<STR_LIT>" ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_manager_locked ( self , mock_lock ) : <EOL> conn = manager . Manager ( None , None , timeout = <NUM_LIT:20> ) <EOL> conn . locked ( None ) <EOL> mock_lock . assert_called_once_with ( None , None , None ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_manager_client_capability ( <EOL> self , mock_session , mock_hex , mock_trans , mock_socket ) : <EOL> conn = self . _mock_manager ( ) <EOL> self . assertEqual ( <EOL> conn . client_capabilities , <EOL> conn . _session . client_capabilities ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_manager_server_capability ( <EOL> self , mock_session , mock_hex , mock_trans , mock_socket ) : <EOL> conn = self . _mock_manager ( ) <EOL> self . assertEqual ( <EOL> conn . server_capabilities , <EOL> conn . _session . server_capabilities ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_manager_channel_id ( <EOL> self , mock_session , mock_hex , mock_trans , mock_socket ) : <EOL> conn = self . _mock_manager ( ) <EOL> self . assertEqual ( conn . channel_id , conn . _session . _channel_id ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_manager_channel_name ( <EOL> self , mock_session , mock_hex , mock_trans , mock_socket ) : <EOL> conn = self . _mock_manager ( ) <EOL> self . assertEqual ( conn . channel_name , conn . _session . _channel_name ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_manager_channel_session_id ( <EOL> self , mock_session , mock_hex , mock_trans , mock_socket ) : <EOL> conn = self . _mock_manager ( ) <EOL> self . assertEqual ( conn . session_id , conn . _session . id ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_manager_connected ( <EOL> self , mock_session , mock_hex , mock_trans , mock_socket ) : <EOL> conn = self . _mock_manager ( ) <EOL> self . assertEqual ( conn . connected , True ) <EOL> def _mock_manager ( self ) : <EOL> conn = manager . connect ( host = '<STR_LIT>' , <EOL> port = <NUM_LIT> , <EOL> username = '<STR_LIT:user>' , <EOL> password = '<STR_LIT:password>' , <EOL> timeout = <NUM_LIT:10> , <EOL> device_params = { '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> hostkey_verify = False , allow_agent = False ) <EOL> return conn <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> suite = unittest . TestLoader ( ) . loadTestsFromTestCase ( TestManager ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( suite ) </s>
