better fullpath support in XML and JSON services

pull/175/head
Chris Caron 2019-10-27 14:32:51 -04:00
parent 5ec5414261
commit 031f6776cc
4 changed files with 22 additions and 15 deletions

View File

@ -68,7 +68,9 @@ class NotifyJSON(NotifyBase):
'{schema}://{user}:{password}@{host}:{port}', '{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, **{ template_tokens = dict(NotifyBase.template_tokens, **{
'host': { 'host': {
'name': _('Hostname'), 'name': _('Hostname'),
@ -151,12 +153,13 @@ class NotifyJSON(NotifyBase):
default_port = 443 if self.secure else 80 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, schema=self.secure_protocol if self.secure else self.protocol,
auth=auth, auth=auth,
hostname=NotifyJSON.quote(self.host, safe=''), hostname=NotifyJSON.quote(self.host, safe=''),
port='' if self.port is None or self.port == default_port port='' if self.port is None or self.port == default_port
else ':{}'.format(self.port), else ':{}'.format(self.port),
fullpath=NotifyJSON.quote(self.fullpath, safe='/'),
args=NotifyJSON.urlencode(args), args=NotifyJSON.urlencode(args),
) )

View File

@ -210,7 +210,7 @@ class NotifyNotica(NotifyBase):
notify_url += ':%d' % self.port notify_url += ':%d' % self.port
notify_url += '{fullpath}?token={token}'.format( notify_url += '{fullpath}?token={token}'.format(
fullpath=self.fullpath.strip('/'), fullpath=self.fullpath,
token=self.token) token=self.token)
self.logger.debug('Notica POST URL: %s (cert_verify=%r)' % ( self.logger.debug('Notica POST URL: %s (cert_verify=%r)' % (

View File

@ -58,7 +58,6 @@ class NotifyXML(NotifyBase):
# local anyway # local anyway
request_rate_per_sec = 0 request_rate_per_sec = 0
# Define object templates
# Define object templates # Define object templates
templates = ( templates = (
'{schema}://{host}', '{schema}://{host}',
@ -169,12 +168,13 @@ class NotifyXML(NotifyBase):
default_port = 443 if self.secure else 80 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, schema=self.secure_protocol if self.secure else self.protocol,
auth=auth, auth=auth,
hostname=NotifyXML.quote(self.host, safe=''), hostname=NotifyXML.quote(self.host, safe=''),
port='' if self.port is None or self.port == default_port port='' if self.port is None or self.port == default_port
else ':{}'.format(self.port), else ':{}'.format(self.port),
fullpath=NotifyXML.quote(self.fullpath, safe='/'),
args=NotifyXML.urlencode(args), args=NotifyXML.urlencode(args),
) )

View File

@ -813,6 +813,9 @@ TEST_URLS = (
################################## ##################################
# NotifyJSON # NotifyJSON
################################## ##################################
('json://:@/', {
'instance': None,
}),
('json://', { ('json://', {
'instance': None, 'instance': None,
}), }),
@ -845,6 +848,8 @@ TEST_URLS = (
}), }),
('jsons://localhost:8080/path/', { ('jsons://localhost:8080/path/', {
'instance': plugins.NotifyJSON, 'instance': plugins.NotifyJSON,
# Our expected url(privacy=True) startswith() response:
'privacy_url': 'jsons://localhost:8080/path/',
}), }),
('jsons://user:password@localhost:8080', { ('jsons://user:password@localhost:8080', {
'instance': plugins.NotifyJSON, 'instance': plugins.NotifyJSON,
@ -852,8 +857,8 @@ TEST_URLS = (
# Our expected url(privacy=True) startswith() response: # Our expected url(privacy=True) startswith() response:
'privacy_url': 'jsons://user:****@localhost:8080', 'privacy_url': 'jsons://user:****@localhost:8080',
}), }),
('json://:@/', { ('json://localhost:8080/path?-HeaderKey=HeaderValue', {
'instance': None, 'instance': plugins.NotifyJSON,
}), }),
('json://user:pass@localhost:8081', { ('json://user:pass@localhost:8081', {
'instance': plugins.NotifyJSON, 'instance': plugins.NotifyJSON,
@ -873,9 +878,6 @@ TEST_URLS = (
# is set and tests that we gracfully handle them # is set and tests that we gracfully handle them
'test_requests_exceptions': True, 'test_requests_exceptions': True,
}), }),
('json://localhost:8080/path?-HeaderKey=HeaderValue', {
'instance': plugins.NotifyJSON,
}),
################################## ##################################
# NotifyKODI # NotifyKODI
@ -3283,6 +3285,9 @@ TEST_URLS = (
################################## ##################################
# NotifyXML # NotifyXML
################################## ##################################
('xml://:@/', {
'instance': None,
}),
('xml://', { ('xml://', {
'instance': None, 'instance': None,
}), }),
@ -3318,12 +3323,14 @@ TEST_URLS = (
}), }),
('xmls://localhost:8080/path/', { ('xmls://localhost:8080/path/', {
'instance': plugins.NotifyXML, 'instance': plugins.NotifyXML,
# Our expected url(privacy=True) startswith() response:
'privacy_url': 'xmls://localhost:8080/path/',
}), }),
('xmls://user:pass@localhost:8080', { ('xmls://user:pass@localhost:8080', {
'instance': plugins.NotifyXML, 'instance': plugins.NotifyXML,
}), }),
('xml://:@/', { ('xml://localhost:8080/path?-HeaderKey=HeaderValue', {
'instance': None, 'instance': plugins.NotifyXML,
}), }),
('xml://user:pass@localhost:8081', { ('xml://user:pass@localhost:8081', {
'instance': plugins.NotifyXML, 'instance': plugins.NotifyXML,
@ -3343,9 +3350,6 @@ TEST_URLS = (
# is set and tests that we gracfully handle them # is set and tests that we gracfully handle them
'test_requests_exceptions': True, 'test_requests_exceptions': True,
}), }),
('xml://localhost:8080/path?-HeaderKey=HeaderValue', {
'instance': plugins.NotifyXML,
}),
################################## ##################################
# NotifyZulip # NotifyZulip