#NEWLINE# def test_absent( self ) : #NEWLINE# #INDENT# '\n        Test to ensure a container is not present, destroying it if present.\n        ' #NEWLINE# name = 'web01' #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'result' : True , #NEWLINE# 'comment' : '' , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# mock = MagicMock ( side_effect = [ False , True , True ] ) #NEWLINE# mock_des = MagicMock ( return_value = { #NEWLINE# #INDENT# 'state' : True , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . dict ( lxc . __salt__ , { #NEWLINE# #INDENT# 'lxc.exists' : mock , #NEWLINE# 'lxc.destroy' : mock_des , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = "Container '{0}' does not exist" . format ( name ) #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( lxc . absent ( name ) , ret ) #NEWLINE# with patch . dict ( lxc . __opts__ , { #NEWLINE# #INDENT# 'test' : True , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = "Container '{0}' would be destroyed" . format ( name ) #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : None , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( lxc . absent ( mock ) , ret ) #NEWLINE# #UNINDENT# with patch . dict ( lxc . __opts__ , { #NEWLINE# #INDENT# 'test' : False , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = "Container '{0}' was destroyed" . format ( name ) #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : True , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# 'state' : True , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( lxc . absent ( name ) , ret )