mirror of https://github.com/caronc/apprise
test coverage
parent
3a7b360805
commit
81f83b2fe9
|
@ -147,13 +147,8 @@ class NotifySMPP(NotifyBase):
|
||||||
self.logger.warning(msg)
|
self.logger.warning(msg)
|
||||||
raise TypeError(msg)
|
raise TypeError(msg)
|
||||||
|
|
||||||
if not self.user:
|
if not (self.user and self.password):
|
||||||
msg = 'No SMPP user account was specified.'
|
msg = 'No SMPP user/pass combination was provided'
|
||||||
self.logger.warning(msg)
|
|
||||||
raise TypeError(msg)
|
|
||||||
|
|
||||||
if not self.host:
|
|
||||||
msg = 'No SMPP host was specified.'
|
|
||||||
self.logger.warning(msg)
|
self.logger.warning(msg)
|
||||||
raise TypeError(msg)
|
raise TypeError(msg)
|
||||||
|
|
||||||
|
@ -293,10 +288,6 @@ class NotifySMPP(NotifyBase):
|
||||||
# We're done early as we couldn't load the results
|
# We're done early as we couldn't load the results
|
||||||
return 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
|
# Support the 'from' and 'source' variable so that we can support
|
||||||
# targets this way too.
|
# targets this way too.
|
||||||
# The 'from' makes it easier to use yaml configuration
|
# The 'from' makes it easier to use yaml configuration
|
||||||
|
|
|
@ -32,7 +32,9 @@ from unittest import mock
|
||||||
import pytest
|
import pytest
|
||||||
from apprise import Apprise
|
from apprise import Apprise
|
||||||
from apprise.plugins.smpp import NotifySMPP
|
from apprise.plugins.smpp import NotifySMPP
|
||||||
|
from apprise import NotifyType
|
||||||
from helpers import AppriseURLTester
|
from helpers import AppriseURLTester
|
||||||
|
import smpplib
|
||||||
|
|
||||||
logging.disable(logging.CRITICAL)
|
logging.disable(logging.CRITICAL)
|
||||||
|
|
||||||
|
@ -103,7 +105,7 @@ def test_plugin_smpplib_import_error(mock_client):
|
||||||
|
|
||||||
# Attempt to instantiate our object
|
# Attempt to instantiate our object
|
||||||
obj = Apprise.instantiate(
|
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
|
# It's not possible because our cryptography depedancy is missing
|
||||||
assert obj is None
|
assert obj is None
|
||||||
|
@ -117,9 +119,41 @@ def test_plugin_smpp_urls(mock_client):
|
||||||
NotifySMPP() Apprise URLs
|
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
|
# Run our general tests
|
||||||
AppriseURLTester(tests=apprise_url_tests).run_all()
|
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
|
||||||
|
|
Loading…
Reference in New Issue