From 031f6776cc17baa2310f13ffb90046f3ea9d6b24 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sun, 27 Oct 2019 14:32:51 -0400 Subject: [PATCH] better fullpath support in XML and JSON services --- apprise/plugins/NotifyJSON.py | 7 +++++-- apprise/plugins/NotifyNotica.py | 2 +- apprise/plugins/NotifyXML.py | 4 ++-- test/test_rest_plugins.py | 24 ++++++++++++++---------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/apprise/plugins/NotifyJSON.py b/apprise/plugins/NotifyJSON.py index 2858e18c..ad772ca8 100644 --- a/apprise/plugins/NotifyJSON.py +++ b/apprise/plugins/NotifyJSON.py @@ -68,7 +68,9 @@ class NotifyJSON(NotifyBase): '{schema}://{user}:{password}@{host}:{port}', ) - # Define our tokens + # Define our tokens; these are the minimum tokens required required to + # be passed into this function (as arguments). The syntax appends any + # previously defined in the base package and builds onto them template_tokens = dict(NotifyBase.template_tokens, **{ 'host': { 'name': _('Hostname'), @@ -151,12 +153,13 @@ class NotifyJSON(NotifyBase): default_port = 443 if self.secure else 80 - return '{schema}://{auth}{hostname}{port}/?{args}'.format( + return '{schema}://{auth}{hostname}{port}{fullpath}/?{args}'.format( schema=self.secure_protocol if self.secure else self.protocol, auth=auth, hostname=NotifyJSON.quote(self.host, safe=''), port='' if self.port is None or self.port == default_port else ':{}'.format(self.port), + fullpath=NotifyJSON.quote(self.fullpath, safe='/'), args=NotifyJSON.urlencode(args), ) diff --git a/apprise/plugins/NotifyNotica.py b/apprise/plugins/NotifyNotica.py index 10debdf7..038c421d 100644 --- a/apprise/plugins/NotifyNotica.py +++ b/apprise/plugins/NotifyNotica.py @@ -210,7 +210,7 @@ class NotifyNotica(NotifyBase): notify_url += ':%d' % self.port notify_url += '{fullpath}?token={token}'.format( - fullpath=self.fullpath.strip('/'), + fullpath=self.fullpath, token=self.token) self.logger.debug('Notica POST URL: %s (cert_verify=%r)' % ( diff --git a/apprise/plugins/NotifyXML.py b/apprise/plugins/NotifyXML.py index 5ff78a71..340446c1 100644 --- a/apprise/plugins/NotifyXML.py +++ b/apprise/plugins/NotifyXML.py @@ -58,7 +58,6 @@ class NotifyXML(NotifyBase): # local anyway request_rate_per_sec = 0 - # Define object templates # Define object templates templates = ( '{schema}://{host}', @@ -169,12 +168,13 @@ class NotifyXML(NotifyBase): default_port = 443 if self.secure else 80 - return '{schema}://{auth}{hostname}{port}/?{args}'.format( + return '{schema}://{auth}{hostname}{port}{fullpath}/?{args}'.format( schema=self.secure_protocol if self.secure else self.protocol, auth=auth, hostname=NotifyXML.quote(self.host, safe=''), port='' if self.port is None or self.port == default_port else ':{}'.format(self.port), + fullpath=NotifyXML.quote(self.fullpath, safe='/'), args=NotifyXML.urlencode(args), ) diff --git a/test/test_rest_plugins.py b/test/test_rest_plugins.py index 448871de..bbe12ae8 100644 --- a/test/test_rest_plugins.py +++ b/test/test_rest_plugins.py @@ -813,6 +813,9 @@ TEST_URLS = ( ################################## # NotifyJSON ################################## + ('json://:@/', { + 'instance': None, + }), ('json://', { 'instance': None, }), @@ -845,6 +848,8 @@ TEST_URLS = ( }), ('jsons://localhost:8080/path/', { 'instance': plugins.NotifyJSON, + # Our expected url(privacy=True) startswith() response: + 'privacy_url': 'jsons://localhost:8080/path/', }), ('jsons://user:password@localhost:8080', { 'instance': plugins.NotifyJSON, @@ -852,8 +857,8 @@ TEST_URLS = ( # Our expected url(privacy=True) startswith() response: 'privacy_url': 'jsons://user:****@localhost:8080', }), - ('json://:@/', { - 'instance': None, + ('json://localhost:8080/path?-HeaderKey=HeaderValue', { + 'instance': plugins.NotifyJSON, }), ('json://user:pass@localhost:8081', { 'instance': plugins.NotifyJSON, @@ -873,9 +878,6 @@ 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 @@ -3283,6 +3285,9 @@ TEST_URLS = ( ################################## # NotifyXML ################################## + ('xml://:@/', { + 'instance': None, + }), ('xml://', { 'instance': None, }), @@ -3318,12 +3323,14 @@ TEST_URLS = ( }), ('xmls://localhost:8080/path/', { 'instance': plugins.NotifyXML, + # Our expected url(privacy=True) startswith() response: + 'privacy_url': 'xmls://localhost:8080/path/', }), ('xmls://user:pass@localhost:8080', { 'instance': plugins.NotifyXML, }), - ('xml://:@/', { - 'instance': None, + ('xml://localhost:8080/path?-HeaderKey=HeaderValue', { + 'instance': plugins.NotifyXML, }), ('xml://user:pass@localhost:8081', { 'instance': plugins.NotifyXML, @@ -3343,9 +3350,6 @@ TEST_URLS = ( # is set and tests that we gracfully handle them 'test_requests_exceptions': True, }), - ('xml://localhost:8080/path?-HeaderKey=HeaderValue', { - 'instance': plugins.NotifyXML, - }), ################################## # NotifyZulip