ImportErrors thrown if sleekxmpp was missing fixed

This commit is contained in:
Chris Caron 2020-03-30 16:59:09 -04:00
parent 6a79d38e12
commit 3a8a7711dc
3 changed files with 35 additions and 20 deletions

View File

@ -2,13 +2,27 @@
import ssl
from os.path import isfile
import sleekxmpp
import logging
# Default our global support flag
SLEEKXMPP_SUPPORT_AVAILABLE = False
try:
# Import sleekxmpp if available
import sleekxmpp
SLEEKXMPP_SUPPORT_AVAILABLE = True
except ImportError:
# No problem; we just simply can't support this plugin because we're
# either using Linux, or simply do not have sleekxmpp installed.
pass
class SleekXmppAdapter(object):
"""
Wrapper to SleekXmpp
Wrapper to sleekxmpp
"""
@ -44,6 +58,15 @@ class SleekXmppAdapter(object):
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem",
]
# This entry is a bit hacky, but it allows us to unit-test this library
# in an environment that simply doesn't have the sleekxmpp package
# available to us.
#
# If anyone is seeing this had knows a better way of testing this
# outside of what is defined in test/test_xmpp_plugin.py, please
# let me know! :)
_enabled = SLEEKXMPP_SUPPORT_AVAILABLE
def __init__(self, host=None, port=None, secure=False,
verify_certificate=True, xep=None, jid=None, password=None,
body=None, targets=None, before_message=None, logger=None):

View File

@ -30,25 +30,11 @@ from ...URLBase import PrivacyMode
from ...common import NotifyType
from ...utils import parse_list
from ...AppriseLocale import gettext_lazy as _
from .SleekXmppAdapter import SleekXmppAdapter
# xep string parser
XEP_PARSE_RE = re.compile('^[^1-9]*(?P<xep>[1-9][0-9]{0,3})$')
# Default our global support flag
NOTIFY_XMPP_SUPPORT_ENABLED = False
try:
# Import sleekxmpp if available
from .SleekXmppAdapter import SleekXmppAdapter
NOTIFY_XMPP_SUPPORT_ENABLED = True
except ImportError:
# No problem; we just simply can't support this plugin because we're
# either using Linux, or simply do not have sleekxmpp installed.
pass
class NotifyXMPP(NotifyBase):
"""
@ -86,7 +72,7 @@ class NotifyXMPP(NotifyBase):
# If anyone is seeing this had knows a better way of testing this
# outside of what is defined in test/test_xmpp_plugin.py, please
# let me know! :)
_enabled = NOTIFY_XMPP_SUPPORT_ENABLED
_enabled = SleekXmppAdapter._enabled
# Define object templates
templates = (

View File

@ -29,7 +29,6 @@ import sys
import ssl
import mock
import pytest
import apprise
try:
@ -43,11 +42,14 @@ except ImportError:
# Python v2.7
pass
# Disable logging for a cleaner testing output
import logging
logging.disable(logging.CRITICAL)
@pytest.mark.skipif(
'sleekxmpp' not in sys.modules, reason="requires sleekxmpp")
def test_xmpp_plugin_import_error(tmpdir):
"""
API: NotifyXMPP Plugin() Import Error
@ -111,13 +113,15 @@ def test_xmpp_plugin_import_error(tmpdir):
sys.path.remove(str(suite))
# Reload the libraries we care about
reload(sys.modules['apprise.plugins.NotifyXMPP'])
reload(sys.modules['apprise.plugins.NotifyXMPP.SleekXmppAdapter'])
reload(sys.modules['apprise.plugins.NotifyXMPP'])
reload(sys.modules['apprise.plugins'])
reload(sys.modules['apprise.Apprise'])
reload(sys.modules['apprise'])
@pytest.mark.skipif(
'sleekxmpp' not in sys.modules, reason="requires sleekxmpp")
def test_xmpp_plugin(tmpdir):
"""
API: NotifyXMPP Plugin()
@ -318,6 +322,8 @@ def test_xmpp_plugin(tmpdir):
ca_backup
@pytest.mark.skipif(
'sleekxmpp' not in sys.modules, reason="requires sleekxmpp")
def test_sleekxmpp_callbacks():
"""
API: NotifyXMPP Plugin() Sleekxmpp callback tests