Browse Source

bugfix: slack:// webhook to return success when message sent (#777)

pull/776/head
Chris Caron 2 years ago committed by GitHub
parent
commit
9a9703c582
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      apprise/plugins/NotifySlack.py
  2. 62
      test/helpers/rest.py
  3. 4
      test/test_plugin_slack.py

2
apprise/plugins/NotifySlack.py

@ -826,7 +826,7 @@ class NotifySlack(NotifyBase):
# The text 'ok' is returned if this is a Webhook request
# So the below captures that as well.
status_okay = (response and response.get('ok', False)) \
if self.mode is SlackMode.BOT else r.content == 'ok'
if self.mode is SlackMode.BOT else r.content == b'ok'
if r.status_code != requests.codes.ok or not status_okay:
# We had a problem

62
test/helpers/rest.py

@ -122,9 +122,6 @@ class AppriseURLTester:
# Our expected server objects
_self = meta.get('self', None)
# Our expected Query response (True, False, or exception type)
response = meta.get('response', True)
# Our expected privacy url
# Don't set this if don't need to check it's value
privacy_url = meta.get('privacy_url')
@ -132,20 +129,6 @@ class AppriseURLTester:
# Our regular expression
url_matches = meta.get('url_matches')
# Allow us to force the server response code to be something other then
# the defaults
requests_response_code = meta.get(
'requests_response_code',
requests.codes.ok if response else requests.codes.not_found,
)
# Allow us to force the server response text to be something other then
# the defaults
requests_response_text = meta.get('requests_response_text')
if not isinstance(requests_response_text, str):
# Convert to string
requests_response_text = dumps(requests_response_text)
# Whether or not we should include an image with our request; unless
# otherwise specified, we assume that images are to be included
include_image = meta.get('include_image', True)
@ -158,35 +141,12 @@ class AppriseURLTester:
asset = AppriseAsset(image_path_mask=False, image_url_mask=False)
asset.image_url_logo = None
test_requests_exceptions = meta.get(
'test_requests_exceptions', False)
# Mock our request object
robj = mock.Mock()
robj.content = u''
mock_get.return_value = robj
mock_post.return_value = robj
if test_requests_exceptions is False:
# Handle our default response
mock_post.return_value.status_code = requests_response_code
mock_get.return_value.status_code = requests_response_code
# Handle our default text response
mock_get.return_value.content = requests_response_text
mock_post.return_value.content = requests_response_text
mock_get.return_value.text = requests_response_text
mock_post.return_value.text = requests_response_text
# Ensure there is no side effect set
mock_post.side_effect = None
mock_get.side_effect = None
else:
# Handle exception testing; first we turn the boolean flag
# into a list of exceptions
test_requests_exceptions = self.req_exceptions
try:
# We can now instantiate our object:
obj = Apprise.instantiate(
@ -338,9 +298,19 @@ class AppriseURLTester:
# Allow us to force the server response text to be something other then
# the defaults
requests_response_text = meta.get('requests_response_text')
if not isinstance(requests_response_text, str):
requests_response_content = None
if isinstance(requests_response_text, str):
requests_response_content = requests_response_text.encode('utf-8')
elif isinstance(requests_response_text, bytes):
requests_response_content = requests_response_text
requests_response_text = requests_response_text.decode('utf-8')
elif not isinstance(requests_response_text, str):
# Convert to string
requests_response_text = dumps(requests_response_text)
requests_response_content = requests_response_text.encode('utf-8')
# A request
robj = mock.Mock()
@ -360,11 +330,11 @@ class AppriseURLTester:
mock_get.return_value.status_code = requests_response_code
# Handle our default text response
mock_get.return_value.content = requests_response_text
mock_post.return_value.content = requests_response_text
mock_del.return_value.content = requests_response_text
mock_put.return_value.content = requests_response_text
mock_head.return_value.content = requests_response_text
mock_get.return_value.content = requests_response_content
mock_post.return_value.content = requests_response_content
mock_del.return_value.content = requests_response_content
mock_put.return_value.content = requests_response_content
mock_head.return_value.content = requests_response_content
mock_get.return_value.text = requests_response_text
mock_post.return_value.text = requests_response_text

4
test/test_plugin_slack.py

@ -394,7 +394,7 @@ def test_plugin_slack_webhook_mode(mock_post):
# Prepare Mock
mock_post.return_value = requests.Request()
mock_post.return_value.status_code = requests.codes.ok
mock_post.return_value.content = 'ok'
mock_post.return_value.content = b'ok'
mock_post.return_value.text = 'ok'
# Initialize some generic (but valid) tokens
@ -653,7 +653,7 @@ def test_plugin_slack_markdown(mock_get, mock_post):
"""
request = mock.Mock()
request.content = 'ok'
request.content = b'ok'
request.status_code = requests.codes.ok
# Prepare Mock

Loading…
Cancel
Save