summaryrefslogtreecommitdiff
path: root/sleekxmpp/test/sleektest.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-12-13 14:36:53 -0500
committerLance Stout <lancestout@gmail.com>2010-12-13 14:36:53 -0500
commitc16913c99929a6a5a57611ec8a1757e3e82d4a45 (patch)
treed92b98975b3dc012c734997e6fddc0ac9e2b82d8 /sleekxmpp/test/sleektest.py
parent12b61365adbbc910841475ea3cf8204f26ccd9c7 (diff)
parentf4451fe6b72f7cfb9680ead7a608d5ca1bc7e753 (diff)
downloadslixmpp-c16913c99929a6a5a57611ec8a1757e3e82d4a45.tar.gz
slixmpp-c16913c99929a6a5a57611ec8a1757e3e82d4a45.tar.bz2
slixmpp-c16913c99929a6a5a57611ec8a1757e3e82d4a45.tar.xz
slixmpp-c16913c99929a6a5a57611ec8a1757e3e82d4a45.zip
Merge branch 'develop' into roster
Conflicts: sleekxmpp/basexmpp.py
Diffstat (limited to 'sleekxmpp/test/sleektest.py')
-rw-r--r--sleekxmpp/test/sleektest.py38
1 files changed, 25 insertions, 13 deletions
diff --git a/sleekxmpp/test/sleektest.py b/sleekxmpp/test/sleektest.py
index 3afd9a62..ce582e3a 100644
--- a/sleekxmpp/test/sleektest.py
+++ b/sleekxmpp/test/sleektest.py
@@ -52,6 +52,10 @@ class SleekTest(unittest.TestCase):
compare -- Compare XML objects against each other.
"""
+ def __init__(self, *args, **kwargs):
+ unittest.TestCase.__init__(self, *args, **kwargs)
+ self.xmpp = None
+
def runTest(self):
pass
@@ -73,6 +77,8 @@ class SleekTest(unittest.TestCase):
xml = self.parse_xml(xml_string)
xml = xml.getchildren()[0]
return xml
+ else:
+ self.fail("XML data was mal-formed:\n%s" % xml_string)
# ------------------------------------------------------------------
# Shortcut methods for creating stanza objects
@@ -86,7 +92,7 @@ class SleekTest(unittest.TestCase):
Arguments:
xml -- An XML object to use for the Message's values.
"""
- return Message(None, *args, **kwargs)
+ return Message(self.xmpp, *args, **kwargs)
def Iq(self, *args, **kwargs):
"""
@@ -97,7 +103,7 @@ class SleekTest(unittest.TestCase):
Arguments:
xml -- An XML object to use for the Iq's values.
"""
- return Iq(None, *args, **kwargs)
+ return Iq(self.xmpp, *args, **kwargs)
def Presence(self, *args, **kwargs):
"""
@@ -108,7 +114,7 @@ class SleekTest(unittest.TestCase):
Arguments:
xml -- An XML object to use for the Iq's values.
"""
- return Presence(None, *args, **kwargs)
+ return Presence(self.xmpp, *args, **kwargs)
def check_jid(self, jid, user=None, domain=None, resource=None,
bare=None, full=None, string=None):
@@ -194,7 +200,7 @@ class SleekTest(unittest.TestCase):
Arguments:
stanza -- The stanza object to test.
criteria -- An expression the stanza must match against.
- method -- The type of matching to use; one of:
+ method -- The type of matching to use; one of:
'exact', 'mask', 'id', 'xpath', and 'stanzapath'.
Defaults to the value of self.match_method.
defaults -- A list of stanza interfaces that have default
@@ -283,7 +289,7 @@ class SleekTest(unittest.TestCase):
def stream_start(self, mode='client', skip=True, header=None,
socket='mock', jid='tester@localhost',
password='test', server='localhost',
- port=5222):
+ port=5222, plugins=None):
"""
Initialize an XMPP client or component using a dummy XML stream.
@@ -303,6 +309,8 @@ class SleekTest(unittest.TestCase):
server -- The name of the XMPP server. Defaults to 'localhost'.
port -- The port to use when connecting to the server.
Defaults to 5222.
+ plugins -- List of plugins to register. By default, all plugins
+ are loaded.
"""
if mode == 'client':
self.xmpp = ClientXMPP(jid, password)
@@ -338,7 +346,11 @@ class SleekTest(unittest.TestCase):
else:
raise ValueError("Unknown socket type.")
- self.xmpp.register_plugins()
+ if plugins is None:
+ self.xmpp.register_plugins()
+ else:
+ for plugin in plugins:
+ self.xmpp.register_plugin(plugin)
self.xmpp.process(threaded=True)
if skip:
if socket != 'live':
@@ -387,7 +399,7 @@ class SleekTest(unittest.TestCase):
return header % ' '.join(parts)
def recv(self, data, defaults=[], method='exact',
- use_values=True, timeout=1):
+ use_values=True, timeout=1):
"""
Pass data to the dummy XMPP client as if it came from an XMPP server.
@@ -415,7 +427,7 @@ class SleekTest(unittest.TestCase):
# receiving data.
recv_data = self.xmpp.socket.next_recv(timeout)
if recv_data is None:
- return False
+ self.fail("No stanza was received.")
xml = self.parse_xml(recv_data)
self.fix_namespaces(xml, 'jabber:client')
stanza = self.xmpp._build_stanza(xml, 'jabber:client')
@@ -510,14 +522,14 @@ class SleekTest(unittest.TestCase):
xml = self.parse_xml(data)
recv_xml = self.parse_xml(recv_data)
if recv_data is None:
- return False
+ self.fail("No stanza was received.")
if method == 'exact':
self.failUnless(self.compare(xml, recv_xml),
"Features do not match.\nDesired:\n%s\nReceived:\n%s" % (
tostring(xml), tostring(recv_xml)))
elif method == 'mask':
matcher = MatchXMLMask(xml)
- self.failUnless(matcher.match(recv_xml),
+ self.failUnless(matcher.match(recv_xml),
"Stanza did not match using %s method:\n" % method + \
"Criteria:\n%s\n" % tostring(xml) + \
"Stanza:\n%s" % tostring(recv_xml))
@@ -580,14 +592,14 @@ class SleekTest(unittest.TestCase):
xml = self.parse_xml(data)
sent_xml = self.parse_xml(sent_data)
if sent_data is None:
- return False
+ self.fail("No stanza was sent.")
if method == 'exact':
self.failUnless(self.compare(xml, sent_xml),
"Features do not match.\nDesired:\n%s\nReceived:\n%s" % (
tostring(xml), tostring(sent_xml)))
elif method == 'mask':
matcher = MatchXMLMask(xml)
- self.failUnless(matcher.match(sent_xml),
+ self.failUnless(matcher.match(sent_xml),
"Stanza did not match using %s method:\n" % method + \
"Criteria:\n%s\n" % tostring(xml) + \
"Stanza:\n%s" % tostring(sent_xml))
@@ -618,7 +630,7 @@ class SleekTest(unittest.TestCase):
"""
sent = self.xmpp.socket.next_sent(timeout)
if sent is None:
- return False
+ self.fail("No stanza was sent.")
xml = self.parse_xml(sent)
self.fix_namespaces(xml, 'jabber:client')
sent = self.xmpp._build_stanza(xml, 'jabber:client')