mirror of https://github.com/caronc/apprise
added MatterMost unit tests
parent
d767c3a95c
commit
0f6905a2cf
|
@ -116,10 +116,7 @@ class NotifyMatterMost(NotifyBase):
|
||||||
if self.channel:
|
if self.channel:
|
||||||
payload['channel'] = self.channel
|
payload['channel'] = self.channel
|
||||||
|
|
||||||
url = '%s://%s' % (self.schema, self.host)
|
url = '%s://%s:%d' % (self.schema, self.host, self.port)
|
||||||
if isinstance(self.port, int):
|
|
||||||
url += ':%d' % self.port
|
|
||||||
|
|
||||||
url += '/hooks/%s' % self.authtoken
|
url += '/hooks/%s' % self.authtoken
|
||||||
|
|
||||||
self.logger.debug('MatterMost POST URL: %s (cert_verify=%r)' % (
|
self.logger.debug('MatterMost POST URL: %s (cert_verify=%r)' % (
|
||||||
|
@ -153,7 +150,7 @@ class NotifyMatterMost(NotifyBase):
|
||||||
else:
|
else:
|
||||||
self.logger.info('Sent MatterMost notification.')
|
self.logger.info('Sent MatterMost notification.')
|
||||||
|
|
||||||
except requests.ConnectionError as e:
|
except requests.RequestException as e:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
'A Connection error occured sending MatterMost '
|
'A Connection error occured sending MatterMost '
|
||||||
'notification.'
|
'notification.'
|
||||||
|
@ -190,16 +187,8 @@ class NotifyMatterMost(NotifyBase):
|
||||||
channel = None
|
channel = None
|
||||||
if 'channel' in results['qsd'] and len(results['qsd']['channel']):
|
if 'channel' in results['qsd'] and len(results['qsd']['channel']):
|
||||||
# Allow the user to specify the channel to post to
|
# Allow the user to specify the channel to post to
|
||||||
try:
|
|
||||||
channel = NotifyBase.unquote(results['qsd']['channel']).strip()
|
channel = NotifyBase.unquote(results['qsd']['channel']).strip()
|
||||||
|
|
||||||
except (AttributeError, TypeError, ValueError):
|
|
||||||
NotifyBase.logger.warning(
|
|
||||||
'An invalid MatterMost channel of "%s" was specified and '
|
|
||||||
'will be ignored.' % results['qsd']['channel']
|
|
||||||
)
|
|
||||||
pass
|
|
||||||
|
|
||||||
results['authtoken'] = authtoken
|
results['authtoken'] = authtoken
|
||||||
results['channel'] = channel
|
results['channel'] = channel
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,9 @@ VALID_URLS = (
|
||||||
('json://', {
|
('json://', {
|
||||||
'instance': None,
|
'instance': None,
|
||||||
}),
|
}),
|
||||||
|
('jsons://', {
|
||||||
|
'instance': None,
|
||||||
|
}),
|
||||||
('json://localhost', {
|
('json://localhost', {
|
||||||
'instance': plugins.NotifyJSON,
|
'instance': plugins.NotifyJSON,
|
||||||
}),
|
}),
|
||||||
|
@ -71,7 +74,63 @@ VALID_URLS = (
|
||||||
# Throws a series of connection and transfer exceptions when this flag
|
# Throws a series of connection and transfer exceptions when this flag
|
||||||
# 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,
|
||||||
})
|
}),
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# NotifyMatterMost
|
||||||
|
##################################
|
||||||
|
('mmost://', {
|
||||||
|
'instance': None,
|
||||||
|
}),
|
||||||
|
('mmosts://', {
|
||||||
|
'instance': None,
|
||||||
|
}),
|
||||||
|
('mmost://localhost/3ccdd113474722377935511fc85d3dd4', {
|
||||||
|
'instance': plugins.NotifyMatterMost,
|
||||||
|
}),
|
||||||
|
('mmost://user@localhost/3ccdd113474722377935511fc85d3dd4?channel=test', {
|
||||||
|
'instance': plugins.NotifyMatterMost,
|
||||||
|
}),
|
||||||
|
('mmost://localhost:8080/3ccdd113474722377935511fc85d3dd4', {
|
||||||
|
'instance': plugins.NotifyMatterMost,
|
||||||
|
}),
|
||||||
|
('mmost://localhost:0/3ccdd113474722377935511fc85d3dd4', {
|
||||||
|
'instance': plugins.NotifyMatterMost,
|
||||||
|
}),
|
||||||
|
('mmost://localhost:invalid-port/3ccdd113474722377935511fc85d3dd4', {
|
||||||
|
'instance': None,
|
||||||
|
}),
|
||||||
|
('mmosts://localhost/3ccdd113474722377935511fc85d3dd4', {
|
||||||
|
'instance': plugins.NotifyMatterMost,
|
||||||
|
}),
|
||||||
|
('mmosts://localhost', {
|
||||||
|
'instance': plugins.NotifyMatterMost,
|
||||||
|
# Thrown because there was no webhook id specified
|
||||||
|
'exception': TypeError,
|
||||||
|
}),
|
||||||
|
('mmost://localhost/bad-web-hook', {
|
||||||
|
'instance': plugins.NotifyMatterMost,
|
||||||
|
# Thrown because the webhook is not in a valid format
|
||||||
|
'exception': TypeError,
|
||||||
|
}),
|
||||||
|
('mmost://localhost/3ccdd113474722377935511fc85d3dd4', {
|
||||||
|
'instance': plugins.NotifyMatterMost,
|
||||||
|
# force a failure
|
||||||
|
'response': False,
|
||||||
|
'requests_response_code': 500,
|
||||||
|
}),
|
||||||
|
('mmost://localhost/3ccdd113474722377935511fc85d3dd4', {
|
||||||
|
'instance': plugins.NotifyMatterMost,
|
||||||
|
# throw a bizzare code forcing us to fail to look it up
|
||||||
|
'response': False,
|
||||||
|
'requests_response_code': 999,
|
||||||
|
}),
|
||||||
|
('mmost://localhost/3ccdd113474722377935511fc85d3dd4', {
|
||||||
|
'instance': plugins.NotifyMatterMost,
|
||||||
|
# Throws a series of connection and transfer exceptions when this flag
|
||||||
|
# is set and tests that we gracfully handle them
|
||||||
|
'test_requests_exceptions': True,
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue