#NEWLINE# @ patch ( 'socket.socket' ) #NEWLINE# def test_connect( self , mock_socket ) : #NEWLINE# #INDENT# '\n        Test for Test connectivity to a host using a particular\n        port from the minion.\n        ' #NEWLINE# self . assertDictEqual ( network . connect ( False , 'port' ) , { #NEWLINE# #INDENT# 'comment' : 'Required argument, host, is missing.' , #NEWLINE# 'result' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( network . connect ( 'host' , False ) , { #NEWLINE# #INDENT# 'comment' : 'Required argument, port, is missing.' , #NEWLINE# 'result' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# ret = 'Unable to connect to host (0) on tcp port port' #NEWLINE# mock_socket . side_effect = Exception ( 'foo' ) #NEWLINE# with patch . object ( salt . utils . network , 'sanitize_host' , return_value = 'A' ) : #NEWLINE# #INDENT# with patch . object ( socket , 'getaddrinfo' , return_value = [ [ 'ipv4' , 'A' , 6 , 'B' , '0.0.0.0' ] ] ) : #NEWLINE# #INDENT# self . assertDictEqual ( network . connect ( 'host' , 'port' ) , { #NEWLINE# #INDENT# 'comment' : mock_socket , #NEWLINE# 'result' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# ret = 'Successfully connected to host (0) on tcp port port' #NEWLINE# mock_socket . side_effect = MagicMock ( ) #NEWLINE# mock_socket . settimeout ( ) . return_value = None #NEWLINE# mock_socket . connect ( ) . return_value = None #NEWLINE# mock_socket . shutdown ( ) . return_value = None #NEWLINE# with patch . object ( salt . utils . network , 'sanitize_host' , return_value = 'A' ) : #NEWLINE# #INDENT# with patch . object ( socket , 'getaddrinfo' , return_value = [ [ 'ipv4' , 'A' , 6 , 'B' , '0.0.0.0' ] ] ) : #NEWLINE# #INDENT# self . assertDictEqual ( network . connect ( 'host' , 'port' ) , { #NEWLINE# #INDENT# 'comment' : ret , #NEWLINE# 'result' : True , #NEWLINE# #UNINDENT# } )