Skip to content

Commit

Permalink
added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Aug 13, 2023
1 parent bea08bd commit 82288d1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
9 changes: 6 additions & 3 deletions apprise/plugins/NotifyMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ class NotifyMatrix(NotifyBase):
# The default secure protocol
secure_protocol = 'matrixs'

# Support Attachments
attachment_support = True

# A URL that takes you to the setup/help of the specific protocol
setup_url = 'https://github.com/caronc/apprise/wiki/Notify_matrix'

Expand Down Expand Up @@ -311,8 +314,8 @@ def __init__(self, targets=None, mode=None, msgtype=None, version=None,

# Setup our version
self.version = self.template_args['version']['default'] \
if not isinstance(version, str) else version.lower()
if self.version and self.version not in MATRIX_VERSIONS:
if not isinstance(version, str) else version
if self.version not in MATRIX_VERSIONS:
msg = 'The version specified ({}) is invalid.'.format(version)
self.logger.warning(msg)
raise TypeError(msg)
Expand Down Expand Up @@ -585,7 +588,7 @@ def _send_server_notification(self, body, title='',
has_error = False

attachments = None
if attach:
if attach and self.attachment_support:
attachments = self._send_attachments(attach)

while len(rooms) > 0:
Expand Down
26 changes: 26 additions & 0 deletions test/test_plugin_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
import logging
logging.disable(logging.CRITICAL)

MATRIX_GOOD_RESPONSE = dumps({
'room_id': '!abc123:localhost',
'room_alias': '#abc123:localhost',
'joined_rooms': ['!abc123:localhost', '!def456:localhost'],
'access_token': 'abcd1234',
'home_server': 'localhost',
})

# Our Testing URLs
apprise_url_tests = (
##################################
Expand Down Expand Up @@ -97,6 +105,24 @@
# user and token correctly specified with webhook
'instance': NotifyMatrix,
}),
('matrix://user:token@localhost:123/#general/?version=3', {
# Provide version over-ride (using version=)
'instance': NotifyMatrix,
# Our response expected server response
'requests_response_text': MATRIX_GOOD_RESPONSE,
'privacy_url': 'matrix://user:****@localhost:123',
}),
('matrixs://user:token@localhost/#general?v=2', {
# Provide version over-ride (using v=)
'instance': NotifyMatrix,
# Our response expected server response
'requests_response_text': MATRIX_GOOD_RESPONSE,
'privacy_url': 'matrixs://user:****@localhost',
}),
('matrix://user:token@localhost:123/#general/?v=invalid', {
# Invalid version specified
'instance': TypeError
}),
('matrix://user:token@localhost?mode=slack&format=text', {
# user and token correctly specified with webhook
'instance': NotifyMatrix,
Expand Down

0 comments on commit 82288d1

Please sign in to comment.