From 81f83b2fe9f805fbbab72f76713b45db2903b39a Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sun, 29 Jun 2025 20:55:44 -0400 Subject: [PATCH] test coverage --- apprise/plugins/smpp.py | 13 ++---------- test/test_plugin_smpp.py | 44 +++++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/apprise/plugins/smpp.py b/apprise/plugins/smpp.py index 4cc84829..13db2600 100644 --- a/apprise/plugins/smpp.py +++ b/apprise/plugins/smpp.py @@ -147,13 +147,8 @@ class NotifySMPP(NotifyBase): self.logger.warning(msg) raise TypeError(msg) - if not self.user: - msg = 'No SMPP user account was specified.' - self.logger.warning(msg) - raise TypeError(msg) - - if not self.host: - msg = 'No SMPP host was specified.' + if not (self.user and self.password): + msg = 'No SMPP user/pass combination was provided' self.logger.warning(msg) raise TypeError(msg) @@ -293,10 +288,6 @@ class NotifySMPP(NotifyBase): # We're done early as we couldn't load the results return results - if not results: - # We're done early as we couldn't load the results - return results - # Support the 'from' and 'source' variable so that we can support # targets this way too. # The 'from' makes it easier to use yaml configuration diff --git a/test/test_plugin_smpp.py b/test/test_plugin_smpp.py index 4d2cfe15..4756f590 100644 --- a/test/test_plugin_smpp.py +++ b/test/test_plugin_smpp.py @@ -32,7 +32,9 @@ from unittest import mock import pytest from apprise import Apprise from apprise.plugins.smpp import NotifySMPP +from apprise import NotifyType from helpers import AppriseURLTester +import smpplib logging.disable(logging.CRITICAL) @@ -103,7 +105,7 @@ def test_plugin_smpplib_import_error(mock_client): # Attempt to instantiate our object obj = Apprise.instantiate( - 'smpp://user:pass@host:port/{}/{}'.format('1' * 10, '1' * 10)) + 'smpp://user:pass@host/{}/{}'.format('1' * 10, '1' * 10)) # It's not possible because our cryptography depedancy is missing assert obj is None @@ -117,9 +119,41 @@ def test_plugin_smpp_urls(mock_client): NotifySMPP() Apprise URLs """ - mock_client.connect.return_value = True - mock_client.bind_transmitter.return_value = True - mock_client.send_message.return_value = True - # Run our general tests AppriseURLTester(tests=apprise_url_tests).run_all() + + +@pytest.mark.skipif( + 'smpplib' not in sys.modules, reason="Requires smpplib") +@mock.patch('smpplib.client.Client') +def test_plugin_smpp_edge_case(mock_client_class): + """ + NotifySMPP() Apprise Edge Case + """ + + mock_client_instance = mock.Mock() + mock_client_class.return_value = mock_client_instance + + # Raise exception on connect + mock_client_instance.connect.side_effect = \ + smpplib.exceptions.ConnectionError + mock_client_instance.bind_transmitter.return_value = True + mock_client_instance.send_message.return_value = True + + # Instantiate our object + obj = Apprise.instantiate( + 'smpp://user:pass@host/{}/{}'.format('1' * 10, '1' * 10)) + + # Well fail to establish a connection + assert obj.notify( + body='body', title='title', notify_type=NotifyType.INFO) is False + + # Raise exception on connect + mock_client_instance.connect.side_effect = None + mock_client_instance.bind_transmitter.return_value = True + mock_client_instance.send_message.side_effect = \ + smpplib.exceptions.ConnectionError + + # Well fail to deliver our message + assert obj.notify( + body='body', title='title', notify_type=NotifyType.INFO) is False