test cases reworked for situations where smpplib is unavailable

pull/1354/head
Chris Caron 2025-06-29 21:42:32 -04:00
parent d40757c74f
commit d7cb97406f
1 changed files with 39 additions and 29 deletions

View File

@ -99,8 +99,7 @@ apprise_url_tests = (
@pytest.mark.skipif( @pytest.mark.skipif(
'smpplib' in sys.modules, 'smpplib' in sys.modules,
reason="Requires that smpplib NOT be installed") reason="Requires that smpplib NOT be installed")
@mock.patch('smpplib.client.Client') def test_plugin_smpplib_import_error():
def test_plugin_smpplib_import_error(mock_client):
""" """
NotifySMPP() smpplib loading failure NotifySMPP() smpplib loading failure
""" """
@ -115,11 +114,20 @@ def test_plugin_smpplib_import_error(mock_client):
@pytest.mark.skipif( @pytest.mark.skipif(
'smpplib' not in sys.modules, reason="Requires smpplib") 'smpplib' not in sys.modules, reason="Requires smpplib")
@mock.patch('smpplib.client.Client') def test_plugin_smpp_urls():
def test_plugin_smpp_urls(mock_client):
""" """
NotifySMPP() Apprise URLs NotifySMPP() Apprise URLs
""" """
# mock nested inside of outside function to avoid failing
# when smpplib is unavailable
with mock.patch('smpplib.client.Client') as mock_client_class:
mock_client_instance = mock.Mock()
mock_client_class.return_value = mock_client_instance
# Raise exception on connect
mock_client_instance.connect.return_value = True
mock_client_instance.bind_transmitter.return_value = True
mock_client_instance.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()
@ -127,12 +135,14 @@ def test_plugin_smpp_urls(mock_client):
@pytest.mark.skipif( @pytest.mark.skipif(
'smpplib' not in sys.modules, reason="Requires smpplib") 'smpplib' not in sys.modules, reason="Requires smpplib")
@mock.patch('smpplib.client.Client') def test_plugin_smpp_edge_case():
def test_plugin_smpp_edge_case(mock_client_class):
""" """
NotifySMPP() Apprise Edge Case NotifySMPP() Apprise Edge Case
""" """
# mock nested inside of outside function to avoid failing
# when smpplib is unavailable
with mock.patch('smpplib.client.Client') as mock_client_class:
mock_client_instance = mock.Mock() mock_client_instance = mock.Mock()
mock_client_class.return_value = mock_client_instance mock_client_class.return_value = mock_client_instance