Resolves error response on successful Slack post (#196)

This commit is contained in:
Chris Caron 2020-01-17 18:16:45 -05:00 committed by GitHub
parent 2e6a996980
commit 384dd94b06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 18 deletions

View File

@ -525,6 +525,8 @@ class NotifySlack(NotifyBase):
'Response Details:\r\n{}'.format(r.content)) 'Response Details:\r\n{}'.format(r.content))
return False return False
elif attach:
# Attachment posts return a JSON string
try: try:
response = loads(r.content) response = loads(r.content)
@ -544,6 +546,8 @@ class NotifySlack(NotifyBase):
self.logger.debug( self.logger.debug(
'Response Details:\r\n{}'.format(r.content)) 'Response Details:\r\n{}'.format(r.content))
return False return False
else:
response = r.content
# Message Post Response looks like this: # Message Post Response looks like this:
# { # {

View File

@ -116,7 +116,7 @@ def test_slack_oauth_access_token(mock_post):
request.content = '{' request.content = '{'
# As a result, we'll fail to send our notification # As a result, we'll fail to send our notification
assert obj.send(body="test") is False assert obj.send(body="test", attach=attach) is False
request.content = dumps({ request.content = dumps({
'ok': False, 'ok': False,
@ -125,7 +125,7 @@ def test_slack_oauth_access_token(mock_post):
# A response from Slack (even with a 200 response) still # A response from Slack (even with a 200 response) still
# results in a failure: # results in a failure:
assert obj.send(body="test") is False assert obj.send(body="test", attach=attach) is False
# Handle exceptions reading our attachment from disk (should it happen) # Handle exceptions reading our attachment from disk (should it happen)
mock_post.side_effect = OSError("Attachment Error") mock_post.side_effect = OSError("Attachment Error")