Skip to content

Commit

Permalink
bug fixes and test coverage complete
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Oct 1, 2023
1 parent 40e4d9d commit 55d7365
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 37 deletions.
5 changes: 4 additions & 1 deletion apprise/plugins/NotifyMSG91.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):
)
# Prepare our payload
payload = {
'template_id': self.template_id,
'template_id': self.template,
'short_url': 1 if self.short_url else 0,
# target phone numbers are sent with a comma delimiter
'recipients': recipients,
Expand Down Expand Up @@ -306,6 +306,9 @@ def parse_url(url):
# The hostname is our authentication key
results['authkey'] = NotifyMSG91.unquote(results['host'])

# The template id is kept in the user field
results['template'] = NotifyMSG91.unquote(results['user'])

if 'short_url' in results['qsd'] and len(results['qsd']['short_url']):
results['short_url'] = parse_bool(results['qsd']['short_url'])

Expand Down
55 changes: 19 additions & 36 deletions test/test_plugin_msg91.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,69 +53,49 @@
'instance': TypeError,
}),
('msg91://{}'.format('a' * 23), {
# valid AuthKey
'instance': NotifyMSG91,
# Since there are no targets specified we expect a False return on
# send()
'notify_response': False,
# valid AuthKey but no Template ID
'instance': TypeError,
}),
('msg91://{}/123'.format('a' * 23), {
# invalid phone number
('msg91://{}@{}'.format('t' * 20, 'a' * 23), {
# Valid entry but no targets
'instance': NotifyMSG91,
# Since there are no targets specified we expect a False return on
# send()
'notify_response': False,
}),
('msg91://{}/abcd'.format('a' * 23), {
('msg91://{}@{}/abcd'.format('t' * 20, 'a' * 23), {
# No number to notify
'instance': NotifyMSG91,
# Since there are no targets specified we expect a False return on
# send()
'notify_response': False,
}),
('msg91://{}/15551232000/?country=invalid'.format('a' * 23), {
# invalid country
'instance': TypeError,
}),
('msg91://{}/15551232000/?country=99'.format('a' * 23), {
# invalid country
'instance': TypeError,
}),
('msg91://{}/15551232000/?route=invalid'.format('a' * 23), {
# invalid route
'instance': TypeError,
}),
('msg91://{}/15551232000/?route=99'.format('a' * 23), {
# invalid route
'instance': TypeError,
}),
('msg91://{}/15551232000'.format('a' * 23), {
('msg91://{}@{}/15551232000'.format('t' * 20, 'a' * 23), {
# a valid message
'instance': NotifyMSG91,

# Our expected url(privacy=True) startswith() response:
'privacy_url': 'msg91://a...a/15551232000',
'privacy_url': 'msg91://t...t@a...a/15551232000',
}),
('msg91://{}/?to=15551232000'.format('a' * 23), {
('msg91://{}@{}/?to=15551232000&short_url=no'.format('t' * 20, 'a' * 23), {
# a valid message
'instance': NotifyMSG91,
}),
('msg91://{}/15551232000?country=91&route=1'.format('a' * 23), {
# using phone no with no target - we text ourselves in
# this case
('msg91://{}@{}/15551232000?short_url=yes'.format('t' * 20, 'a' * 23), {
# testing short_url
'instance': NotifyMSG91,
}),
('msg91://{}/15551232000'.format('a' * 23), {
('msg91://{}@{}/15551232000'.format('t' * 20, 'a' * 23), {
# use get args to acomplish the same thing
'instance': NotifyMSG91,
}),
('msg91://{}/15551232000'.format('a' * 23), {
('msg91://{}@{}/15551232000'.format('t' * 20, 'a' * 23), {
'instance': NotifyMSG91,
# throw a bizzare code forcing us to fail to look it up
'response': False,
'requests_response_code': 999,
}),
('msg91://{}/15551232000'.format('a' * 23), {
('msg91://{}@{}/15551232000'.format('t' * 20, 'a' * 23), {
'instance': NotifyMSG91,
# Throws a series of connection and transfer exceptions when this flag
# is set and tests that we gracfully handle them
Expand Down Expand Up @@ -149,11 +129,14 @@ def test_plugin_msg91_edge_cases(mock_post):
mock_post.return_value = response

# Initialize some generic (but valid) tokens
# authkey = '{}'.format('a' * 24)
target = '+1 (555) 123-3456'

# No authkey specified
with pytest.raises(TypeError):
NotifyMSG91(authkey=None, targets=target)
NotifyMSG91(template="1234", authkey=None, targets=target)
with pytest.raises(TypeError):
NotifyMSG91(template="1234", authkey=" ", targets=target)
with pytest.raises(TypeError):
NotifyMSG91(template=" ", authkey='a' * 23, targets=target)
with pytest.raises(TypeError):
NotifyMSG91(authkey=" ", targets=target)
NotifyMSG91(template=None, authkey='a' * 23, targets=target)

0 comments on commit 55d7365

Please sign in to comment.