From 761291e65cd5295612888b59b5e9a2f323f971a0 Mon Sep 17 00:00:00 2001 From: Kaustubh Phatak Date: Fri, 15 Feb 2019 14:37:55 -0800 Subject: [PATCH] Issue 69: Tests for Headers support --- apprise/plugins/NotifyBase.py | 3 ++- apprise/plugins/NotifyDiscord.py | 4 ++-- apprise/plugins/NotifySNS.py | 4 ++-- test/test_notify_base.py | 6 ++++++ test/test_rest_plugins.py | 7 +++++++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apprise/plugins/NotifyBase.py b/apprise/plugins/NotifyBase.py index 3dc6cd0d..a8471f83 100644 --- a/apprise/plugins/NotifyBase.py +++ b/apprise/plugins/NotifyBase.py @@ -425,5 +425,6 @@ class NotifyBase(object): if 'user' in results['qsd']: results['user'] = results['qsd']['user'] - results['headers'] = {k[1:]: v for k, v in results['qsd'].items() if re.match(r'^-.', k)} + results['headers'] = {k[1:]: v for k, v in results['qsd'].items() + if re.match(r'^-.', k)} return results diff --git a/apprise/plugins/NotifyDiscord.py b/apprise/plugins/NotifyDiscord.py index 4d80f613..7cdf283c 100644 --- a/apprise/plugins/NotifyDiscord.py +++ b/apprise/plugins/NotifyDiscord.py @@ -181,7 +181,7 @@ class NotifyDiscord(NotifyBase): else: # not markdown payload['content'] = body if not title \ - else "{}\r\n{}".format(title, body) + else "{}\r\n{}".format(title, body) if self.avatar and image_url: payload['avatar_url'] = image_url @@ -298,7 +298,7 @@ class NotifyDiscord(NotifyBase): """ regex = re.compile( r'^\s*#+\s*(?P[^#\n]+)([ \r\t\v#])?' - r'(?P([^ \r\t\v#].+?)(\n(?!\s#))|\s*$)', flags=re.S|re.M) + r'(?P([^ \r\t\v#].+?)(\n(?!\s#))|\s*$)', flags=re.S | re.M) common = regex.finditer(markdown) fields = list() diff --git a/apprise/plugins/NotifySNS.py b/apprise/plugins/NotifySNS.py index 64071d45..abc46f42 100644 --- a/apprise/plugins/NotifySNS.py +++ b/apprise/plugins/NotifySNS.py @@ -58,8 +58,8 @@ LIST_DELIM = re.compile(r'[ \t\r\n,\\/]+') # region as a delimiter. This is a bit hacky; but it's much easier than having # users of this product search though this Access Key Secret and escape all # of the forward slashes! -IS_REGION = re.compile( - r'^\s*(?P[a-z]{2})-(?P[a-z]+)-(?P[0-9]+)\s*$', re.I) +IS_REGION = re.compile(r'^\s*(?P[a-z]{2})-' + r'(?P[a-z]+)-(?P[0-9]+)\s*$', re.I) # Extend HTTP Error Messages AWS_HTTP_ERROR_MAP = HTTP_ERROR_MAP.copy() diff --git a/test/test_notify_base.py b/test/test_notify_base.py index 01d809b9..dc3ee937 100644 --- a/test/test_notify_base.py +++ b/test/test_notify_base.py @@ -166,6 +166,12 @@ def test_notify_base_urls(): assert 'password' in results assert results['password'] == "newpassword" + # pass headers + results = NotifyBase.parse_url( + 'https://localhost:8080?-HeaderKey=HeaderValue') + assert 'headerkey' in results['headers'] + assert results['headers']['headerkey'] == 'HeaderValue' + # User Handling # user keyword over-rides default password diff --git a/test/test_rest_plugins.py b/test/test_rest_plugins.py index 2984973d..bee5fbea 100644 --- a/test/test_rest_plugins.py +++ b/test/test_rest_plugins.py @@ -431,6 +431,10 @@ TEST_URLS = ( # is set and tests that we gracfully handle them 'test_requests_exceptions': True, }), + ('json://localhost:8080/path?-HeaderKey=HeaderValue', { + 'instance': plugins.NotifyJSON, + }), + ################################## # NotifyKODI @@ -1470,6 +1474,9 @@ TEST_URLS = ( # is set and tests that we gracfully handle them 'test_requests_exceptions': True, }), + ('xml://localhost:8080/path?-HeaderKey=HeaderValue', { + 'instance': plugins.NotifyXML, + }), )