mirror of
https://github.com/caronc/apprise.git
synced 2025-06-28 21:51:32 +02:00
Set default port for Mattermost notifications (#1293)
This commit is contained in:
parent
386c77e14d
commit
6295888ef0
@ -205,6 +205,10 @@ class NotifyMattermost(NotifyBase):
|
||||
# Set our user
|
||||
payload['username'] = self.user if self.user else self.app_id
|
||||
|
||||
port = ''
|
||||
if self.port is not None:
|
||||
port = ':{}'.format(self.port)
|
||||
|
||||
# For error tracking
|
||||
has_error = False
|
||||
|
||||
@ -215,8 +219,8 @@ class NotifyMattermost(NotifyBase):
|
||||
if channel:
|
||||
payload['channel'] = channel
|
||||
|
||||
url = '{}://{}:{}{}/hooks/{}'.format(
|
||||
self.schema, self.host, self.port,
|
||||
url = '{}://{}{}{}/hooks/{}'.format(
|
||||
self.schema, self.host, port,
|
||||
self.fullpath.rstrip('/'), self.token)
|
||||
|
||||
self.logger.debug('Mattermost POST URL: %s (cert_verify=%r)' % (
|
||||
|
@ -199,3 +199,28 @@ def test_plugin_mattermost_channels(request_mock):
|
||||
assert posted_json['username'] == 'user1'
|
||||
assert posted_json['channel'] == 'two'
|
||||
assert posted_json['text'] == 'title\r\nbody'
|
||||
|
||||
|
||||
def test_mattermost_post_default_port(request_mock):
|
||||
# Test token
|
||||
token = 'token'
|
||||
|
||||
# Instantiate our URL
|
||||
obj = Apprise.instantiate(
|
||||
'mmosts://mattermost.example.com/{token}'.format(
|
||||
token=token)
|
||||
)
|
||||
|
||||
assert isinstance(obj, NotifyMattermost)
|
||||
assert obj.notify(body="body", title='title') is True
|
||||
|
||||
# Make sure we don't use port if not provided
|
||||
assert request_mock.called is True
|
||||
assert request_mock.call_count == 1
|
||||
assert request_mock.call_args_list[0][0][0].startswith(
|
||||
'https://mattermost.example.com/hooks/token')
|
||||
|
||||
# Our Posted JSON Object
|
||||
posted_json = json.loads(request_mock.call_args_list[0][1]['data'])
|
||||
assert 'text' in posted_json
|
||||
assert posted_json['text'] == 'title\r\nbody'
|
||||
|
Loading…
x
Reference in New Issue
Block a user