From ab25301953138343d3d295aaa8872de9c5bc2cf9 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 18 Nov 2010 15:50:45 -0500 Subject: Adding stream tests for XEP-0030. Fixed some errors when responding to disco requests. --- sleekxmpp/test/sleektest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'sleekxmpp/test') diff --git a/sleekxmpp/test/sleektest.py b/sleekxmpp/test/sleektest.py index 5e61cec2..f1b5ef93 100644 --- a/sleekxmpp/test/sleektest.py +++ b/sleekxmpp/test/sleektest.py @@ -257,7 +257,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. @@ -277,6 +277,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) @@ -312,7 +314,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': -- cgit v1.2.3 From 5f2fc67c40f0cd73bee7b2cf3bc3a73d83832a50 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 7 Dec 2010 17:19:39 -0500 Subject: Added option for iq.send to accept a callhandler. The callback will be a stream level handler, and will not execute in its own thread. If you must have a thread, have the callback function raise a custom event, which can be processed by another event handler, which may run in an individual thread, like so: def handle_reply(self, iq): self.event('custom_event', iq) def do_long_operation_in_thread(self, iq): ... self.add_event_handler('custom_event', self.do_long_operation_in_thread) ...take out already prepared iq stanza... iq.send(callback=self.handle_reply) --- sleekxmpp/test/sleektest.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'sleekxmpp/test') diff --git a/sleekxmpp/test/sleektest.py b/sleekxmpp/test/sleektest.py index f1b5ef93..e11be5d6 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 @@ -86,7 +90,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 +101,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 +112,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): -- cgit v1.2.3 From defc252c7dabb1d54fe20b3ac8661d0198ff40bd Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 7 Dec 2010 23:04:37 -0500 Subject: Fix several errors in SleekTest. Notably, not sending an expected stanza will not silently pass. --- sleekxmpp/test/sleektest.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'sleekxmpp/test') diff --git a/sleekxmpp/test/sleektest.py b/sleekxmpp/test/sleektest.py index e11be5d6..aa411cd7 100644 --- a/sleekxmpp/test/sleektest.py +++ b/sleekxmpp/test/sleektest.py @@ -77,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 @@ -172,7 +174,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 @@ -281,7 +283,7 @@ 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 + plugins -- List of plugins to register. By default, all plugins are loaded. """ if mode == 'client': @@ -371,7 +373,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. @@ -399,7 +401,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') @@ -494,14 +496,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)) @@ -564,14 +566,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)) @@ -602,7 +604,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') -- cgit v1.2.3