From 55d73655ec42b8f5c8a7528ecccf623c6e5a2b3d Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sun, 1 Oct 2023 10:57:49 -0400 Subject: [PATCH] bug fixes and test coverage complete --- apprise/plugins/NotifyMSG91.py | 5 +++- test/test_plugin_msg91.py | 55 ++++++++++++---------------------- 2 files changed, 23 insertions(+), 37 deletions(-) diff --git a/apprise/plugins/NotifyMSG91.py b/apprise/plugins/NotifyMSG91.py index fab61917ff..2a7804c384 100644 --- a/apprise/plugins/NotifyMSG91.py +++ b/apprise/plugins/NotifyMSG91.py @@ -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, @@ -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']) diff --git a/test/test_plugin_msg91.py b/test/test_plugin_msg91.py index 4ac7c87cfe..9ffe7fdd33 100644 --- a/test/test_plugin_msg91.py +++ b/test/test_plugin_msg91.py @@ -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 @@ -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)