#NEWLINE# def test_installed( self ) : #NEWLINE# #INDENT# '\n        Test to verify that the desired port is installed,\n        and that it was compiled with the desired options.\n        ' #NEWLINE# name = 'security/nmap' #NEWLINE# options = [ { #NEWLINE# #INDENT# 'IPV6' : 'on' , #NEWLINE# #UNINDENT# } ] #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'result' : None , #NEWLINE# 'comment' : '' , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# mock = MagicMock ( side_effect = SaltInvocationError ) #NEWLINE# with patch . dict ( ports . __salt__ , { #NEWLINE# #INDENT# 'ports.showconfig' : mock , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = 'Unable to get configuration for {0}. Port name may be invalid, or ports tree may need to be updated. Error message: ' . format ( name ) #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( ports . installed ( name ) , ret ) #NEWLINE# #UNINDENT# mock = MagicMock ( return_value = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# mock_lst = MagicMock ( return_value = { #NEWLINE# #INDENT# 'origin' : { #NEWLINE# #INDENT# 'origin' : name , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . dict ( ports . __salt__ , { #NEWLINE# #INDENT# 'ports.showconfig' : mock , #NEWLINE# 'pkg.list_pkgs' : mock_lst , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = 'security/nmap is already installed' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : True , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( ports . installed ( name ) , ret ) #NEWLINE# comt = 'security/nmap does not have any build options, yet options were specified' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( ports . installed ( name , options ) , ret ) #NEWLINE# mock_dict = MagicMock ( return_value = { #NEWLINE# #INDENT# 'origin' : { #NEWLINE# #INDENT# 'origin' : 'salt' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . dict ( ports . __salt__ , { #NEWLINE# #INDENT# 'pkg.list_pkgs' : mock_dict , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# with patch . dict ( ports . __opts__ , { #NEWLINE# #INDENT# 'test' : True , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = '{0} will be installed' . format ( name ) #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : None , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( ports . installed ( name ) , ret ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# mock = MagicMock ( return_value = { #NEWLINE# #INDENT# 'salt' : { #NEWLINE# #INDENT# 'salt' : 'salt' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# mock_dict = MagicMock ( return_value = { #NEWLINE# #INDENT# 'origin' : { #NEWLINE# #INDENT# 'origin' : 'salt' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# mock_f = MagicMock ( return_value = False ) #NEWLINE# mock_t = MagicMock ( return_value = True ) #NEWLINE# with patch . dict ( ports . __salt__ , { #NEWLINE# #INDENT# 'ports.showconfig' : mock , #NEWLINE# 'pkg.list_pkgs' : mock_dict , #NEWLINE# 'ports.config' : mock_f , #NEWLINE# 'ports.rmconfig' : mock_t , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# with patch . dict ( ports . __opts__ , { #NEWLINE# #INDENT# 'test' : True , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = 'The following options are not available for security/nmap: IPV6' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( ports . installed ( name , options ) , ret ) #NEWLINE# comt = 'security/nmap will be installed with the default build options' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : None , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( ports . installed ( name ) , ret ) #NEWLINE# #UNINDENT# with patch . dict ( ports . __opts__ , { #NEWLINE# #INDENT# 'test' : False , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = 'Unable to set options for security/nmap' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( ports . installed ( name , [ { #NEWLINE# #INDENT# 'salt' : 'salt' , #NEWLINE# #UNINDENT# } ] ) , ret ) #NEWLINE# with patch . object ( os . path , 'isfile' , mock_t ) : #NEWLINE# #INDENT# with patch . object ( os . path , 'isdir' , mock_t ) : #NEWLINE# #INDENT# comt = 'Unable to clear options for security/nmap' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( ports . installed ( name ) , ret ) #NEWLINE# #UNINDENT# #UNINDENT# with patch . dict ( ports . __salt__ , { #NEWLINE# #INDENT# 'ports.config' : mock_t , #NEWLINE# 'ports.install' : mock_t , #NEWLINE# 'test.ping' : MockModule ( ) , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = 'Failed to install security/nmap. Error message:\nsalt' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : False , #NEWLINE# 'changes' : True , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( ports . installed ( name , [ { #NEWLINE# #INDENT# 'salt' : 'salt' , #NEWLINE# #UNINDENT# } ] ) , ret )