summaryrefslogtreecommitdiff
path: root/sleekxmpp/test/sleektest.py
diff options
context:
space:
mode:
Diffstat (limited to 'sleekxmpp/test/sleektest.py')
-rw-r--r--sleekxmpp/test/sleektest.py38
1 files changed, 21 insertions, 17 deletions
diff --git a/sleekxmpp/test/sleektest.py b/sleekxmpp/test/sleektest.py
index cac99f77..e26f99ce 100644
--- a/sleekxmpp/test/sleektest.py
+++ b/sleekxmpp/test/sleektest.py
@@ -8,20 +8,15 @@
import unittest
from xml.parsers.expat import ExpatError
-try:
- import Queue as queue
-except:
- import queue
-import sleekxmpp
from sleekxmpp import ClientXMPP, ComponentXMPP
+from sleekxmpp.util import Queue
from sleekxmpp.stanza import Message, Iq, Presence
from sleekxmpp.test import TestSocket, TestLiveSocket
-from sleekxmpp.exceptions import XMPPError, IqTimeout, IqError
-from sleekxmpp.xmlstream import ET, register_stanza_plugin
-from sleekxmpp.xmlstream import ElementBase, StanzaBase
+from sleekxmpp.xmlstream import ET
+from sleekxmpp.xmlstream import ElementBase
from sleekxmpp.xmlstream.tostring import tostring
-from sleekxmpp.xmlstream.matcher import StanzaPath, MatcherId
+from sleekxmpp.xmlstream.matcher import StanzaPath, MatcherId, MatchIDSender
from sleekxmpp.xmlstream.matcher import MatchXMLMask, MatchXPath
@@ -217,6 +212,7 @@ class SleekTest(unittest.TestCase):
matchers = {'stanzapath': StanzaPath,
'xpath': MatchXPath,
'mask': MatchXMLMask,
+ 'idsender': MatchIDSender,
'id': MatcherId}
Matcher = matchers.get(method, None)
if Matcher is None:
@@ -292,11 +288,8 @@ class SleekTest(unittest.TestCase):
if self.xmpp:
self.xmpp.socket.disconnect_error()
- def stream_start(self, mode='client', skip=True, header=None,
- socket='mock', jid='tester@localhost',
- password='test', server='localhost',
- port=5222, sasl_mech=None,
- plugins=None, plugin_config={}):
+ def stream_start(self, mode='client', skip=True, header=None, socket='mock', jid='tester@localhost',
+ password='test', server='localhost', port=5222, sasl_mech=None, plugins=None, plugin_config=None):
"""
Initialize an XMPP client or component using a dummy XML stream.
@@ -319,6 +312,9 @@ class SleekTest(unittest.TestCase):
plugins -- List of plugins to register. By default, all plugins
are loaded.
"""
+ if not plugin_config:
+ plugin_config = {}
+
if mode == 'client':
self.xmpp = ClientXMPP(jid, password,
sasl_mech=sasl_mech,
@@ -338,7 +334,7 @@ class SleekTest(unittest.TestCase):
# We will use this to wait for the session_start event
# for live connections.
- skip_queue = queue.Queue()
+ skip_queue = Queue()
if socket == 'mock':
self.xmpp.set_socket(TestSocket())
@@ -371,10 +367,16 @@ class SleekTest(unittest.TestCase):
else:
for plugin in plugins:
self.xmpp.register_plugin(plugin)
+
+ # Some plugins require messages to have ID values. Set
+ # this to True in tests related to those plugins.
+ self.xmpp.use_message_ids = False
+
self.xmpp.process(threaded=True)
if skip:
if socket != 'live':
# Mark send queue as usable
+ self.xmpp.session_bind_event.set()
self.xmpp.session_started_event.set()
# Clear startup stanzas
self.xmpp.socket.next_sent(timeout=1)
@@ -423,8 +425,7 @@ class SleekTest(unittest.TestCase):
parts.append('xmlns="%s"' % default_ns)
return header % ' '.join(parts)
- def recv(self, data, defaults=[], method='exact',
- use_values=True, timeout=1):
+ def recv(self, data, defaults=None, method='exact', use_values=True, timeout=1):
"""
Pass data to the dummy XMPP client as if it came from an XMPP server.
@@ -445,6 +446,9 @@ class SleekTest(unittest.TestCase):
timeout -- Time to wait in seconds for data to be received by
a live connection.
"""
+ if not defaults:
+ defaults = []
+
if self.xmpp.socket.is_live:
# we are working with a live connection, so we should
# verify what has been received instead of simulating