#NEWLINE# def test_set_file( self ) : #NEWLINE# #INDENT# '\n        Test to set debconf selections from a file or a template\n        ' #NEWLINE# name = 'nullmailer' #NEWLINE# source = 'salt://pathto/pkg.selections' #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'result' : False , #NEWLINE# 'comment' : '' , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# comt = 'Context must be formed as a dict' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( debconfmod . set_file ( name , source , context = 'salt' ) , ret ) #NEWLINE# comt = 'Defaults must be formed as a dict' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( debconfmod . set_file ( name , source , defaults = 'salt' ) , ret ) #NEWLINE# with patch . dict ( debconfmod . __opts__ , { #NEWLINE# #INDENT# 'test' : True , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = 'Debconf selections would have been set.' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : None , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( debconfmod . set_file ( name , source ) , ret ) #NEWLINE# with patch . dict ( debconfmod . __opts__ , { #NEWLINE# #INDENT# 'test' : False , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# mock = MagicMock ( return_value = True ) #NEWLINE# with patch . dict ( debconfmod . __salt__ , { #NEWLINE# #INDENT# 'debconf.set_file' : mock , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = 'Debconf selections were set.' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : ret , #NEWLINE# 'result' : True , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( debconfmod . set_file ( name , source ) , ret )