mirror of
https://github.com/caronc/apprise.git
synced 2025-01-07 14:39:51 +01:00
ImportErrors thrown if sleekxmpp was missing fixed
This commit is contained in:
parent
6a79d38e12
commit
3a8a7711dc
@ -2,13 +2,27 @@
|
|||||||
|
|
||||||
import ssl
|
import ssl
|
||||||
from os.path import isfile
|
from os.path import isfile
|
||||||
import sleekxmpp
|
|
||||||
import logging
|
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):
|
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",
|
"/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,
|
def __init__(self, host=None, port=None, secure=False,
|
||||||
verify_certificate=True, xep=None, jid=None, password=None,
|
verify_certificate=True, xep=None, jid=None, password=None,
|
||||||
body=None, targets=None, before_message=None, logger=None):
|
body=None, targets=None, before_message=None, logger=None):
|
||||||
|
@ -30,25 +30,11 @@ from ...URLBase import PrivacyMode
|
|||||||
from ...common import NotifyType
|
from ...common import NotifyType
|
||||||
from ...utils import parse_list
|
from ...utils import parse_list
|
||||||
from ...AppriseLocale import gettext_lazy as _
|
from ...AppriseLocale import gettext_lazy as _
|
||||||
|
from .SleekXmppAdapter import SleekXmppAdapter
|
||||||
|
|
||||||
# xep string parser
|
# xep string parser
|
||||||
XEP_PARSE_RE = re.compile('^[^1-9]*(?P<xep>[1-9][0-9]{0,3})$')
|
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):
|
class NotifyXMPP(NotifyBase):
|
||||||
"""
|
"""
|
||||||
@ -86,7 +72,7 @@ class NotifyXMPP(NotifyBase):
|
|||||||
# If anyone is seeing this had knows a better way of testing this
|
# 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
|
# outside of what is defined in test/test_xmpp_plugin.py, please
|
||||||
# let me know! :)
|
# let me know! :)
|
||||||
_enabled = NOTIFY_XMPP_SUPPORT_ENABLED
|
_enabled = SleekXmppAdapter._enabled
|
||||||
|
|
||||||
# Define object templates
|
# Define object templates
|
||||||
templates = (
|
templates = (
|
||||||
|
@ -29,7 +29,6 @@ import sys
|
|||||||
import ssl
|
import ssl
|
||||||
import mock
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import apprise
|
import apprise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -43,11 +42,14 @@ except ImportError:
|
|||||||
# Python v2.7
|
# Python v2.7
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Disable logging for a cleaner testing output
|
# Disable logging for a cleaner testing output
|
||||||
import logging
|
import logging
|
||||||
logging.disable(logging.CRITICAL)
|
logging.disable(logging.CRITICAL)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
'sleekxmpp' not in sys.modules, reason="requires sleekxmpp")
|
||||||
def test_xmpp_plugin_import_error(tmpdir):
|
def test_xmpp_plugin_import_error(tmpdir):
|
||||||
"""
|
"""
|
||||||
API: NotifyXMPP Plugin() Import Error
|
API: NotifyXMPP Plugin() Import Error
|
||||||
@ -111,13 +113,15 @@ def test_xmpp_plugin_import_error(tmpdir):
|
|||||||
sys.path.remove(str(suite))
|
sys.path.remove(str(suite))
|
||||||
|
|
||||||
# Reload the libraries we care about
|
# 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.SleekXmppAdapter'])
|
||||||
|
reload(sys.modules['apprise.plugins.NotifyXMPP'])
|
||||||
reload(sys.modules['apprise.plugins'])
|
reload(sys.modules['apprise.plugins'])
|
||||||
reload(sys.modules['apprise.Apprise'])
|
reload(sys.modules['apprise.Apprise'])
|
||||||
reload(sys.modules['apprise'])
|
reload(sys.modules['apprise'])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
'sleekxmpp' not in sys.modules, reason="requires sleekxmpp")
|
||||||
def test_xmpp_plugin(tmpdir):
|
def test_xmpp_plugin(tmpdir):
|
||||||
"""
|
"""
|
||||||
API: NotifyXMPP Plugin()
|
API: NotifyXMPP Plugin()
|
||||||
@ -318,6 +322,8 @@ def test_xmpp_plugin(tmpdir):
|
|||||||
ca_backup
|
ca_backup
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
'sleekxmpp' not in sys.modules, reason="requires sleekxmpp")
|
||||||
def test_sleekxmpp_callbacks():
|
def test_sleekxmpp_callbacks():
|
||||||
"""
|
"""
|
||||||
API: NotifyXMPP Plugin() Sleekxmpp callback tests
|
API: NotifyXMPP Plugin() Sleekxmpp callback tests
|
||||||
|
Loading…
Reference in New Issue
Block a user