Set default port for Mattermost notifications (#1293)

This commit is contained in:
Stanislav Ochotnický 2025-03-16 21:26:06 +01:00 committed by GitHub
parent 386c77e14d
commit 6295888ef0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 2 deletions

View File

@ -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)' % (

View File

@ -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'