Skip to content

Commit

Permalink
Merge pull request #54577 from garethgreenaway/2019_2_1_port_52715
Browse files Browse the repository at this point in the history
[master] Porting #52715 to master
  • Loading branch information
dwoz authored Jan 2, 2020
2 parents 4dd05be + 8914513 commit 4d8ccf3
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions tests/unit/states/test_slack.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: Jayesh Kariya <[email protected]>
:codeauthor: Gareth J. Greenaway <[email protected]>
'''
# Import Python libs
from __future__ import absolute_import, unicode_literals, print_function
Expand Down Expand Up @@ -42,8 +43,7 @@ def test_post_message_apikey(self):
'comment': ''}

with patch.dict(slack.__opts__, {'test': True}):
comt = ('The following message is to be sent to Slack: {0}'
.format(message))
comt = 'The following message is to be sent to Slack: {0}'.format(message)
ret.update({'comment': comt})
self.assertDictEqual(slack.post_message(name,
channel=channel,
Expand All @@ -52,31 +52,31 @@ def test_post_message_apikey(self):
api_key=api_key), ret)

with patch.dict(slack.__opts__, {'test': False}):
comt = ('Please specify api_key or webhook.')
comt = 'Please specify api_key or webhook.'
ret.update({'comment': comt, 'result': False})
self.assertDictEqual(slack.post_message(name,
channel=None,
from_name=from_name,
message=message,
api_key=None), ret)

comt = ('Slack channel is missing.')
comt = 'Slack channel is missing.'
ret.update({'comment': comt, 'result': False})
self.assertDictEqual(slack.post_message(name,
channel=None,
from_name=from_name,
message=message,
api_key=api_key), ret)

comt = ('Slack from name is missing.')
comt = 'Slack from name is missing.'
ret.update({'comment': comt, 'result': False})
self.assertDictEqual(slack.post_message(name,
channel=channel,
from_name=None,
message=message,
api_key=api_key), ret)

comt = ('Slack message is missing.')
comt = 'Slack message is missing.'
ret.update({'comment': comt, 'result': False})
self.assertDictEqual(slack.post_message(name,
channel=channel,
Expand All @@ -86,7 +86,7 @@ def test_post_message_apikey(self):

mock = MagicMock(return_value=True)
with patch.dict(slack.__salt__, {'slack.post_message': mock}):
comt = ('Sent message: slack-message')
comt = 'Sent message: slack-message'
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(slack.post_message(name,
channel=channel,
Expand All @@ -112,8 +112,7 @@ def test_post_message_webhook(self):
'comment': ''}

with patch.dict(slack.__opts__, {'test': True}):
comt = ('The following message is to be sent to Slack: {0}'
.format(message))
comt = 'The following message is to be sent to Slack: {0}'.format(message)
ret.update({'comment': comt})
self.assertDictEqual(slack.post_message(name,
channel=channel,
Expand All @@ -122,15 +121,15 @@ def test_post_message_webhook(self):
webhook=webhook), ret)

with patch.dict(slack.__opts__, {'test': False}):
comt = ('Please specify api_key or webhook.')
comt = 'Please specify api_key or webhook.'
ret.update({'comment': comt, 'result': False})
self.assertDictEqual(slack.post_message(name,
channel=channel,
username=username,
message=None,
webhook=None), ret)

comt = ('Please specify only either api_key or webhook.')
comt = 'Please specify only either api_key or webhook.'
ret.update({'comment': comt, 'result': False})
self.assertDictEqual(slack.post_message(name,
channel=channel,
Expand All @@ -139,7 +138,7 @@ def test_post_message_webhook(self):
api_key=api_key,
webhook=webhook), ret)

comt = ('Slack message is missing.')
comt = 'Slack message is missing.'
ret.update({'comment': comt, 'result': False})
self.assertDictEqual(slack.post_message(name,
channel=channel,
Expand All @@ -149,7 +148,7 @@ def test_post_message_webhook(self):

mock = MagicMock(return_value=True)
with patch.dict(slack.__salt__, {'slack.call_hook': mock}):
comt = ('Sent message: slack-message')
comt = 'Sent message: slack-message'
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(slack.post_message(name,
channel=channel,
Expand Down

0 comments on commit 4d8ccf3

Please sign in to comment.