#NEWLINE# def test_post_message( self ) : #NEWLINE# #INDENT# '\n        Test to send a message to a Slack channel.\n        ' #NEWLINE# name = 'slack-message' #NEWLINE# channel = '#general' #NEWLINE# from_name = 'SuperAdmin' #NEWLINE# message = 'This state was executed successfully.' #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'result' : None , #NEWLINE# 'comment' : '' , #NEWLINE# #UNINDENT# } #NEWLINE# with patch . dict ( slack . __opts__ , { #NEWLINE# #INDENT# 'test' : True , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = 'The following message is to be sent to Slack: {0}' . format ( message ) #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( slack . post_message ( name , channel , from_name , message ) , ret ) #NEWLINE# #UNINDENT# with patch . dict ( slack . __opts__ , { #NEWLINE# #INDENT# 'test' : False , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = 'Slack channel is missing: None' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( slack . post_message ( name , None , from_name , message ) , ret ) #NEWLINE# comt = 'Slack from name is missing: None' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( slack . post_message ( name , channel , None , message ) , ret ) #NEWLINE# comt = 'Slack message is missing: None' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( slack . post_message ( name , channel , from_name , None ) , ret ) #NEWLINE# mock = MagicMock ( return_value = True ) #NEWLINE# with patch . dict ( slack . __salt__ , { #NEWLINE# #INDENT# 'slack.post_message' : mock , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# comt = 'Sent message: slack-message' #NEWLINE# ret . update ( { #NEWLINE# #INDENT# 'comment' : comt , #NEWLINE# 'result' : True , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( slack . post_message ( name , channel , from_name , message ) , ret )