#NEWLINE# def test_image_present_and_force( self ) : #NEWLINE# #INDENT# '\n        According following sls,\n\n        .. code-block:: yaml\n\n            image:latest:\n              dockerng.image_present:\n                - force: true\n\n        if ``image:latest`` is not downloaded and force is true\n        should pull a new image successfuly.\n        ' #NEWLINE# dockerng_inspect_image = Mock ( side_effect = CommandExecutionError ( 'Error 404: No such image/container: image:latest' ) ) #NEWLINE# dockerng_pull = Mock ( return_value = { #NEWLINE# #INDENT# 'Layers' : { #NEWLINE# #INDENT# 'Already_Pulled' : [ 'abcdefghijk' ] , #NEWLINE# 'Pulled' : [ 'abcdefghijk' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# 'Status' : "Image 'image:latest' was pulled" , #NEWLINE# 'Time_Elapsed' : 1.1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# dockerng_list_tags = Mock ( side_effect = [ [ ] , [ 'image:latest' ] ] ) #NEWLINE# __salt__ = { #NEWLINE# #INDENT# 'dockerng.list_tags' : dockerng_list_tags , #NEWLINE# 'dockerng.pull' : dockerng_list_tags , #NEWLINE# 'dockerng.inspect_image' : dockerng_inspect_image , #NEWLINE# #UNINDENT# } #NEWLINE# with patch . dict ( dockerng_state . __dict__ , { #NEWLINE# #INDENT# '__salt__' : __salt__ , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# ret = dockerng_state . image_present ( 'image:latest' , force = True ) #NEWLINE# #UNINDENT# self . assertEqual ( ret , { #NEWLINE# #INDENT# 'changes' : { #NEWLINE# #INDENT# 'Layers' : { #NEWLINE# #INDENT# 'Already_Pulled' : [ 'abcdefghijk' ] , #NEWLINE# 'Pulled' : [ 'abcdefghijk' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# 'Status' : "Image 'image:latest' was pulled" , #NEWLINE# 'Time_Elapsed' : 1.1 , #NEWLINE# #UNINDENT# } , #NEWLINE# 'result' : True , #NEWLINE# 'comment' : "Image 'image:latest' was pulled" , #NEWLINE# 'name' : 'image:latest' , #NEWLINE# #UNINDENT# } )