mirror of https://github.com/caronc/apprise
Adjust XMPP tests again
parent
4e86b44fa7
commit
de1e6a35da
|
@ -26,9 +26,21 @@
|
||||||
import six
|
import six
|
||||||
import sys
|
import sys
|
||||||
import ssl
|
import ssl
|
||||||
|
import mock
|
||||||
|
|
||||||
import apprise
|
import apprise
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Python v3.4+
|
||||||
|
from importlib import reload
|
||||||
|
except ImportError:
|
||||||
|
try:
|
||||||
|
# Python v3.0-v3.3
|
||||||
|
from imp import reload
|
||||||
|
except ImportError:
|
||||||
|
# Python v2.7
|
||||||
|
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)
|
||||||
|
@ -39,13 +51,33 @@ def test_xmpp_plugin(tmpdir):
|
||||||
API: NotifyXMPP Plugin()
|
API: NotifyXMPP Plugin()
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class MockedSleekXmppAdapter(apprise.plugins.NotifyXMPP.SleekXmppAdapter):
|
# Mock the sleekxmpp module completely.
|
||||||
|
sys.modules['sleekxmpp'] = mock.MagicMock()
|
||||||
|
|
||||||
|
# The following libraries need to be reloaded to prevent
|
||||||
|
# TypeError: super(type, obj): obj must be an instance or subtype of type
|
||||||
|
# This is better explained in this StackOverflow post:
|
||||||
|
# https://stackoverflow.com/questions/31363311/\
|
||||||
|
# any-way-to-manually-fix-operation-of-\
|
||||||
|
# super-after-ipython-reload-avoiding-ty
|
||||||
|
#
|
||||||
|
reload(sys.modules['apprise.plugins.NotifyXMPP'])
|
||||||
|
reload(sys.modules['apprise.plugins'])
|
||||||
|
reload(sys.modules['apprise.Apprise'])
|
||||||
|
reload(sys.modules['apprise'])
|
||||||
|
|
||||||
|
# Mock the XMPP adapter to override "self.success".
|
||||||
|
# This will signal a successful message delivery.
|
||||||
|
from apprise.plugins.NotifyXMPP import SleekXmppAdapter
|
||||||
|
class MockedSleekXmppAdapter(SleekXmppAdapter):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(MockedSleekXmppAdapter, self).__init__(*args, **kwargs)
|
super(MockedSleekXmppAdapter, self).__init__(*args, **kwargs)
|
||||||
# Mock the XMPP adapter to override "self.success".
|
|
||||||
self.success = True
|
self.success = True
|
||||||
|
|
||||||
|
NotifyXMPP = sys.modules['apprise.plugins.NotifyXMPP']
|
||||||
|
NotifyXMPP.SleekXmppAdapter = MockedSleekXmppAdapter
|
||||||
|
|
||||||
# Disable Throttling to speed testing
|
# Disable Throttling to speed testing
|
||||||
apprise.plugins.NotifyBase.request_rate_per_sec = 0
|
apprise.plugins.NotifyBase.request_rate_per_sec = 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue