#NEWLINE# def test_stopped( self ) : #NEWLINE# #INDENT# '\n        Test to ensure that a container is stopped.\n        ' #NEWLINE# name = 'web01' #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'result' : False , #NEWLINE# 'comment' : '' , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# mock = MagicMock ( return_value = { #NEWLINE# #INDENT# 'state' : { #NEWLINE# #INDENT# 'new' : 'stop' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# mock_t = MagicMock ( side_effect = [ None , 'stopped' , 'frozen' , 'frozen' ] ) #NEWLINE# with patch . dict ( lxc . __salt__ , { #NEWLINE# #INDENT# 'lxc.stop' : mock , #NEWLINE# 'lxc.state' : mock_t , #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 . stopped ( name ) , ret ) #NEWLINE# comt = "Container '{0}' is already stopped" . format ( name ) #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : True , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( lxc . stopped ( name ) , ret ) #NEWLINE# with patch . dict ( lxc . __opts__ , { #NEWLINE# #INDENT# 'test' : True , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = "Container 'web01' would be stopped" #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : None , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( lxc . stopped ( name ) , ret ) #NEWLINE# #UNINDENT# with patch . dict ( lxc . __opts__ , { #NEWLINE# #INDENT# 'test' : False , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = "Unable to stop container 'web01'" #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : False , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# 'state' : { #NEWLINE# #INDENT# 'new' : 'stop' , #NEWLINE# 'old' : 'frozen' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( lxc . stopped ( name ) , ret )