#NEWLINE# def test_install( self ) : #NEWLINE# #INDENT# '\n        Test to install new alternative for defined <name>\n        ' #NEWLINE# name = 'pager' #NEWLINE# link = '/usr/bin/pager' #NEWLINE# path = '/usr/bin/less' #NEWLINE# priority = 5 #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'link' : link , #NEWLINE# 'path' : path , #NEWLINE# 'priority' : priority , #NEWLINE# 'result' : None , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'comment' : '' , #NEWLINE# #UNINDENT# } #NEWLINE# mock = MagicMock ( side_effect = [ True , False , False ] ) #NEWLINE# mock_bool = MagicMock ( return_value = True ) #NEWLINE# with patch . dict ( alternatives . __salt__ , { #NEWLINE# #INDENT# 'alternatives.check_installed' : mock , #NEWLINE# 'alternatives.install' : mock_bool , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = 'Alternatives for {0} is already set to {1}' . format ( name , path ) #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : True , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( alternatives . install ( name , link , path , priority ) , ret ) #NEWLINE# comt = 'Alternative will be set for {0} to {1} with priority {2}' . format ( name , path , priority ) #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : None , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . dict ( alternatives . __opts__ , { #NEWLINE# #INDENT# 'test' : True , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertDictEqual ( alternatives . install ( name , link , self , priority ) , ret ) #NEWLINE# #UNINDENT# comt = 'Setting alternative for {0} to {1} with priority {2}' . format ( name , path , priority ) #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : True , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'link' : link , #NEWLINE# 'path' : path , #NEWLINE# 'priority' : priority , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . dict ( alternatives . __opts__ , { #NEWLINE# #INDENT# 'test' : False , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertDictEqual ( alternatives . install ( name , link , path , priority ) , ret )