added MatterMost unit tests

pull/5/head
Chris Caron 7 years ago
parent d767c3a95c
commit 0f6905a2cf

@ -116,10 +116,7 @@ class NotifyMatterMost(NotifyBase):
if self.channel:
payload['channel'] = self.channel
url = '%s://%s' % (self.schema, self.host)
if isinstance(self.port, int):
url += ':%d' % self.port
url = '%s://%s:%d' % (self.schema, self.host, self.port)
url += '/hooks/%s' % self.authtoken
self.logger.debug('MatterMost POST URL: %s (cert_verify=%r)' % (
@ -153,7 +150,7 @@ class NotifyMatterMost(NotifyBase):
else:
self.logger.info('Sent MatterMost notification.')
except requests.ConnectionError as e:
except requests.RequestException as e:
self.logger.warning(
'A Connection error occured sending MatterMost '
'notification.'
@ -190,16 +187,8 @@ class NotifyMatterMost(NotifyBase):
channel = None
if 'channel' in results['qsd'] and len(results['qsd']['channel']):
# Allow the user to specify the channel to post to
try:
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['channel'] = channel

@ -30,6 +30,9 @@ VALID_URLS = (
('json://', {
'instance': None,
}),
('jsons://', {
'instance': None,
}),
('json://localhost', {
'instance': plugins.NotifyJSON,
}),
@ -71,7 +74,63 @@ VALID_URLS = (
# Throws a series of connection and transfer exceptions when this flag
# is set and tests that we gracfully handle them
'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…
Cancel
Save