From d0c506f93010f62cd447ce29f98ab991f521ec99 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 5 Nov 2010 14:45:58 -0400 Subject: [PATCH] Simplified SleekTest. * check_stanza does not require stanza_class parameter. Introspection! * check_message, check_iq, and check_presence removed -- use check instead. * stream_send_stanza, stream_send_message, stream_send_iq, and stream_send_presence removed -- use send instead. * Use recv instead of recv_message, recv_presence, etc. * check_jid instead of check_JID * stream_start may accept multi=True to return a new SleekTest instance for testing multiple streams at once. --- sleekxmpp/plugins/__init__.py | 4 +- sleekxmpp/test/sleektest.py | 281 ++++++++----------------------- sleekxmpp/xmlstream/xmlstream.py | 22 +++ tests/live_test.py | 32 ++-- tests/test_jid.py | 22 +-- tests/test_stanza_element.py | 36 ++-- tests/test_stanza_error.py | 10 +- tests/test_stanza_gmail.py | 2 +- tests/test_stanza_iq.py | 16 +- tests/test_stanza_message.py | 4 +- tests/test_stanza_presence.py | 10 +- tests/test_stanza_roster.py | 4 +- tests/test_stanza_xep_0004.py | 8 +- tests/test_stanza_xep_0030.py | 14 +- tests/test_stanza_xep_0033.py | 18 +- tests/test_stanza_xep_0060.py | 38 ++--- tests/test_stanza_xep_0085.py | 10 +- tests/test_stream.py | 10 +- tests/test_stream_exceptions.py | 12 +- tests/test_stream_handlers.py | 16 +- tests/test_stream_presence.py | 20 +-- tests/test_stream_roster.py | 8 +- 22 files changed, 242 insertions(+), 355 deletions(-) diff --git a/sleekxmpp/plugins/__init__.py b/sleekxmpp/plugins/__init__.py index 4dcec8f..427ab04 100644 --- a/sleekxmpp/plugins/__init__.py +++ b/sleekxmpp/plugins/__init__.py @@ -6,5 +6,5 @@ See the file LICENSE for copying permission. """ __all__ = ['xep_0004', 'xep_0012', 'xep_0030', 'xep_0033', 'xep_0045', - 'xep_0050', 'xep_0078', 'xep_0085', 'xep_0092', 'xep_0199', - 'gmail_notify', 'xep_0060', 'xep_0202'] + 'xep_0050', 'xep_0085', 'xep_0092', 'xep_0199', 'gmail_notify', + 'xep_0060', 'xep_0202'] diff --git a/sleekxmpp/test/sleektest.py b/sleekxmpp/test/sleektest.py index 2901e59..f8b4b54 100644 --- a/sleekxmpp/test/sleektest.py +++ b/sleekxmpp/test/sleektest.py @@ -1,5 +1,4 @@ """ - SleekXMPP: The Sleek XMPP Library Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout This file is part of SleekXMPP. @@ -27,27 +26,29 @@ class SleekTest(unittest.TestCase): Message -- Create a Message stanza object. Iq -- Create an Iq stanza object. Presence -- Create a Presence stanza object. - check_stanza -- Compare a generic stanza against an XML string. - check_message -- Compare a Message stanza against an XML string. - check_iq -- Compare an Iq stanza against an XML string. - check_presence -- Compare a Presence stanza against an XML string. + check_jid -- Check a JID and its component parts. + check -- Compare a stanza against an XML string. stream_start -- Initialize a dummy XMPP client. - stream_recv -- Queue data for XMPP client to receive. - stream_make_header -- Create a stream header. - stream_send_header -- Check that the given header has been sent. - stream_send_message -- Check that the XMPP client sent the given - Message stanza. - stream_send_iq -- Check that the XMPP client sent the given - Iq stanza. - stream_send_presence -- Check thatt the XMPP client sent the given - Presence stanza. - stream_send_stanza -- Check that the XMPP client sent the given - generic stanza. stream_close -- Disconnect the XMPP client. + make_header -- Create a stream header. + send_header -- Check that the given header has been sent. + send_feature -- Send a raw XML element. + send -- Check that the XMPP client sent the given + generic stanza. + recv -- Queue data for XMPP client to receive, or + verify the data that was received from a + live connection. + recv_header -- Check that a given stream header + was received. + recv_feature -- Check that a given, raw XML element + was recveived. fix_namespaces -- Add top-level namespace to an XML object. compare -- Compare XML objects against each other. """ + def runTest(self): + pass + def parse_xml(self, xml_string): try: xml = ET.fromstring(xml_string) @@ -103,10 +104,8 @@ class SleekTest(unittest.TestCase): """ return Presence(None, *args, **kwargs) - - - def check_JID(self, jid, user=None, domain=None, resource=None, - bare=None, full=None, string=None): + def check_jid(self, jid, user=None, domain=None, resource=None, + bare=None, full=None, string=None): """ Verify the components of a JID. @@ -141,8 +140,8 @@ class SleekTest(unittest.TestCase): # ------------------------------------------------------------------ # Methods for comparing stanza objects to XML strings - def check_stanza(self, stanza_class, stanza, xml_string, - defaults=None, use_values=True): + def check(self, stanza, xml_string, + defaults=None, use_values=True): """ Create and compare several stanza objects to a correct XML string. @@ -161,7 +160,6 @@ class SleekTest(unittest.TestCase): must take into account any extra elements that are included by default. Arguments: - stanza_class -- The class of the stanza being tested. stanza -- The stanza object to test. xml_string -- A string version of the correct XML expected. defaults -- A list of stanza interfaces that have default @@ -172,6 +170,7 @@ class SleekTest(unittest.TestCase): setStanzaValues() should be used. Defaults to True. """ + stanza_class = stanza.__class__ xml = self.parse_xml(xml_string) # Ensure that top level namespaces are used, even if they @@ -188,7 +187,11 @@ class SleekTest(unittest.TestCase): # so that they will compare correctly. default_stanza = stanza_class() if defaults is None: - defaults = [] + known_defaults = { + Message: ['type'], + Presence: ['priority'] + } + defaults = known_defaults.get(stanza_class, []) for interface in defaults: stanza[interface] = stanza[interface] stanza2[interface] = stanza2[interface] @@ -219,62 +222,6 @@ class SleekTest(unittest.TestCase): self.failUnless(result, debug) - def check_message(self, msg, xml_string, use_values=True): - """ - Create and compare several message stanza objects to a - correct XML string. - - If use_values is False, the test using getStanzaValues() and - setStanzaValues() will not be used. - - Arguments: - msg -- The Message stanza object to check. - xml_string -- The XML contents to compare against. - use_values -- Indicates if the test using getStanzaValues - and setStanzaValues should be used. Defaults - to True. - """ - - return self.check_stanza(Message, msg, xml_string, - defaults=['type'], - use_values=use_values) - - def check_iq(self, iq, xml_string, use_values=True): - """ - Create and compare several iq stanza objects to a - correct XML string. - - If use_values is False, the test using getStanzaValues() and - setStanzaValues() will not be used. - - Arguments: - iq -- The Iq stanza object to check. - xml_string -- The XML contents to compare against. - use_values -- Indicates if the test using getStanzaValues - and setStanzaValues should be used. Defaults - to True. - """ - return self.check_stanza(Iq, iq, xml_string, use_values=use_values) - - def check_presence(self, pres, xml_string, use_values=True): - """ - Create and compare several presence stanza objects to a - correct XML string. - - If use_values is False, the test using getStanzaValues() and - setStanzaValues() will not be used. - - Arguments: - iq -- The Iq stanza object to check. - xml_string -- The XML contents to compare against. - use_values -- Indicates if the test using getStanzaValues - and setStanzaValues should be used. Defaults - to True. - """ - return self.check_stanza(Presence, pres, xml_string, - defaults=['priority'], - use_values=use_values) - # ------------------------------------------------------------------ # Methods for simulating stanza streams. @@ -302,7 +249,6 @@ class SleekTest(unittest.TestCase): port -- The port to use when connecting to the server. Defaults to 5222. """ - if mode == 'client': self.xmpp = ClientXMPP(jid, password) elif mode == 'component': @@ -337,13 +283,13 @@ class SleekTest(unittest.TestCase): if mode == 'component': self.xmpp.socket.next_sent(timeout=1) - def stream_make_header(self, sto='', - sfrom='', - sid='', - stream_ns="http://etherx.jabber.org/streams", - default_ns="jabber:client", - version="1.0", - xml_header=True): + def make_header(self, sto='', + sfrom='', + sid='', + stream_ns="http://etherx.jabber.org/streams", + default_ns="jabber:client", + version="1.0", + xml_header=True): """ Create a stream header to be received by the test XMPP agent. @@ -374,8 +320,8 @@ class SleekTest(unittest.TestCase): parts.append('xmlns="%s"' % default_ns) return header % ' '.join(parts) - def stream_recv(self, data, stanza_class=StanzaBase, defaults=[], - use_values=True, timeout=1): + def recv(self, data, stanza_class=StanzaBase, defaults=[], + use_values=True, timeout=1): """ Pass data to the dummy XMPP client as if it came from an XMPP server. @@ -402,7 +348,7 @@ class SleekTest(unittest.TestCase): if recv_data is None: return False stanza = stanza_class(xml=self.parse_xml(recv_data)) - return self.check_stanza(stanza_class, stanza, data, + return self.check(stanza_class, stanza, data, defaults=defaults, use_values=use_values) else: @@ -410,14 +356,14 @@ class SleekTest(unittest.TestCase): data = str(data) self.xmpp.socket.recv_data(data) - def stream_recv_header(self, sto='', - sfrom='', - sid='', - stream_ns="http://etherx.jabber.org/streams", - default_ns="jabber:client", - version="1.0", - xml_header=False, - timeout=1): + def recv_header(self, sto='', + sfrom='', + sid='', + stream_ns="http://etherx.jabber.org/streams", + default_ns="jabber:client", + version="1.0", + xml_header=False, + timeout=1): """ Check that a given stream header was received. @@ -433,11 +379,11 @@ class SleekTest(unittest.TestCase): timeout -- Length of time to wait in seconds for a response. """ - header = self.stream_make_header(sto, sfrom, sid, - stream_ns=stream_ns, - default_ns=default_ns, - version=version, - xml_header=xml_header) + header = self.make_header(sto, sfrom, sid, + stream_ns=stream_ns, + default_ns=default_ns, + version=version, + xml_header=xml_header) recv_header = self.xmpp.socket.next_recv(timeout) if recv_header is None: raise ValueError("Socket did not return data.") @@ -477,9 +423,8 @@ class SleekTest(unittest.TestCase): "Stream headers do not match:\nDesired:\n%s\nReceived:\n%s" % ( '%s %s' % (xml.tag, xml.attrib), '%s %s' % (recv_xml.tag, recv_xml.attrib))) - #tostring(xml), tostring(recv_xml)))#recv_header)) - def stream_recv_feature(self, data, use_values=True, timeout=1): + def recv_feature(self, data, use_values=True, timeout=1): """ """ if self.xmpp.socket.is_live: @@ -499,39 +444,14 @@ class SleekTest(unittest.TestCase): data = str(data) self.xmpp.socket.recv_data(data) - - - def stream_recv_message(self, data, use_values=True, timeout=1): - """ - """ - return self.stream_recv(data, stanza_class=Message, - defaults=['type'], - use_values=use_values, - timeout=timeout) - - def stream_recv_iq(self, data, use_values=True, timeout=1): - """ - """ - return self.stream_recv(data, stanza_class=Iq, - use_values=use_values, - timeout=timeout) - - def stream_recv_presence(self, data, use_values=True, timeout=1): - """ - """ - return self.stream_recv(data, stanza_class=Presence, - defaults=['priority'], - use_values=use_values, - timeout=timeout) - - def stream_send_header(self, sto='', - sfrom='', - sid='', - stream_ns="http://etherx.jabber.org/streams", - default_ns="jabber:client", - version="1.0", - xml_header=False, - timeout=1): + def send_header(self, sto='', + sfrom='', + sid='', + stream_ns="http://etherx.jabber.org/streams", + default_ns="jabber:client", + version="1.0", + xml_header=False, + timeout=1): """ Check that a given stream header was sent. @@ -547,11 +467,11 @@ class SleekTest(unittest.TestCase): timeout -- Length of time to wait in seconds for a response. """ - header = self.stream_make_header(sto, sfrom, sid, - stream_ns=stream_ns, - default_ns=default_ns, - version=version, - xml_header=xml_header) + header = self.make_header(sto, sfrom, sid, + stream_ns=stream_ns, + default_ns=default_ns, + version=version, + xml_header=xml_header) sent_header = self.xmpp.socket.next_sent(timeout) if sent_header is None: raise ValueError("Socket did not return data.") @@ -569,7 +489,7 @@ class SleekTest(unittest.TestCase): "Stream headers do not match:\nDesired:\n%s\nSent:\n%s" % ( header, sent_header)) - def stream_send_feature(self, data, use_values=True, timeout=1): + def send_feature(self, data, use_values=True, timeout=1): """ """ sent_data = self.xmpp.socket.next_sent(timeout) @@ -581,13 +501,13 @@ class SleekTest(unittest.TestCase): "Features do not match.\nDesired:\n%s\nSent:\n%s" % ( tostring(xml), tostring(sent_xml))) - def stream_send_stanza(self, stanza_class, data, defaults=None, - use_values=True, timeout=.1): + def send(self, data, defaults=None, + use_values=True, timeout=.1): """ Check that the XMPP client sent the given stanza XML. Extracts the next sent stanza and compares it with the given - XML using check_stanza. + XML using check. Arguments: stanza_class -- The class of the sent stanza object. @@ -599,70 +519,15 @@ class SleekTest(unittest.TestCase): timeout -- Time in seconds to wait for a stanza before failing the check. """ - if isintance(data, str): - data = stanza_class(xml=self.parse_xml(data)) + if isinstance(data, str): + xml = self.parse_xml(data) + self.fix_namespaces(xml, 'jabber:client') + data = self.xmpp._build_stanza(xml, 'jabber:client') sent = self.xmpp.socket.next_sent(timeout) - self.check_stanza(stanza_class, data, sent, + self.check(data, sent, defaults=defaults, use_values=use_values) - def stream_send_message(self, data, use_values=True, timeout=.1): - """ - Check that the XMPP client sent the given stanza XML. - - Extracts the next sent stanza and compares it with the given - XML using check_message. - - Arguments: - data -- The XML string of the expected Message stanza, - or an equivalent stanza object. - use_values -- Modifies the type of tests used by check_message. - timeout -- Time in seconds to wait for a stanza before - failing the check. - """ - if isinstance(data, str): - data = self.Message(xml=self.parse_xml(data)) - sent = self.xmpp.socket.next_sent(timeout) - self.check_message(data, sent, use_values) - - def stream_send_iq(self, data, use_values=True, timeout=.1): - """ - Check that the XMPP client sent the given stanza XML. - - Extracts the next sent stanza and compares it with the given - XML using check_iq. - - Arguments: - data -- The XML string of the expected Iq stanza, - or an equivalent stanza object. - use_values -- Modifies the type of tests used by check_iq. - timeout -- Time in seconds to wait for a stanza before - failing the check. - """ - if isinstance(data, str): - data = self.Iq(xml=self.parse_xml(data)) - sent = self.xmpp.socket.next_sent(timeout) - self.check_iq(data, sent, use_values) - - def stream_send_presence(self, data, use_values=True, timeout=.1): - """ - Check that the XMPP client sent the given stanza XML. - - Extracts the next sent stanza and compares it with the given - XML using check_presence. - - Arguments: - data -- The XML string of the expected Presence stanza, - or an equivalent stanza object. - use_values -- Modifies the type of tests used by check_presence. - timeout -- Time in seconds to wait for a stanza before - failing the check. - """ - if isinstance(data, str): - data = self.Presence(xml=self.parse_xml(data)) - sent = self.xmpp.socket.next_sent(timeout) - self.check_presence(data, sent, use_values) - def stream_close(self): """ Disconnect the dummy XMPP client. diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index a526281..85619db 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -772,6 +772,28 @@ class XMLStream(object): root.clear() logging.debug("Ending read XML loop") + def _build_stanza(self, xml, default_ns=None): + """ + Create a stanza object from a given XML object. + + If a specialized stanza type is not found for the XML, then + a generic StanzaBase stanza will be returned. + + Arguments: + xml -- The XML object to convert into a stanza object. + default_ns -- Optional default namespace to use instead of the + stream's current default namespace. + """ + if default_ns is None: + default_ns = self.default_ns + stanza_type = StanzaBase + for stanza_class in self.__root_stanza: + if xml.tag == "{%s}%s" % (default_ns, stanza_class.name): + stanza_type = stanza_class + break + stanza = stanza_type(self, xml) + return stanza + def __spawn_event(self, xml): """ Analyze incoming XML stanzas and convert them into stanza diff --git a/tests/live_test.py b/tests/live_test.py index 7e8945f..4b4394e 100644 --- a/tests/live_test.py +++ b/tests/live_test.py @@ -20,9 +20,9 @@ class TestLiveStream(SleekTest): # Use sid=None to ignore any id sent by the server since # we can't know it in advance. - self.stream_recv_header(sfrom='localhost', sid=None) - self.stream_send_header(sto='localhost') - self.stream_recv_feature(""" + self.recv_header(sfrom='localhost', sid=None) + self.send_header(sto='localhost') + self.recv_feature(""" @@ -35,15 +35,15 @@ class TestLiveStream(SleekTest): """) - self.stream_send_feature(""" + self.send_feature(""" """) - self.stream_recv_feature(""" + self.recv_feature(""" """) - self.stream_send_header(sto='localhost') - self.stream_recv_header(sfrom='localhost', sid=None) - self.stream_recv_feature(""" + self.send_header(sto='localhost') + self.recv_header(sfrom='localhost', sid=None) + self.recv_feature(""" DIGEST-MD5 @@ -56,16 +56,16 @@ class TestLiveStream(SleekTest): """) - self.stream_send_feature(""" + self.send_feature(""" AHVzZXIAdXNlcg== """) - self.stream_recv_feature(""" + self.recv_feature(""" """) - self.stream_send_header(sto='localhost') - self.stream_recv_header(sfrom='localhost', sid=None) - self.stream_recv_feature(""" + self.send_header(sto='localhost') + self.recv_header(sfrom='localhost', sid=None) + self.recv_feature(""" @@ -77,16 +77,16 @@ class TestLiveStream(SleekTest): """) - # Should really use stream_send_iq, but our Iq stanza objects + # Should really use send, but our Iq stanza objects # can't handle bind element payloads yet. - self.stream_send_feature(""" + self.send_feature(""" test """) - self.stream_recv_feature(""" + self.recv_feature(""" user@localhost/test diff --git a/tests/test_jid.py b/tests/test_jid.py index 6ec6e02..9940299 100644 --- a/tests/test_jid.py +++ b/tests/test_jid.py @@ -8,7 +8,7 @@ class TestJIDClass(SleekTest): def testJIDFromFull(self): """Test using JID of the form 'user@server/resource/with/slashes'.""" - self.check_JID(JID('user@someserver/some/resource'), + self.check_jid(JID('user@someserver/some/resource'), 'user', 'someserver', 'some/resource', @@ -22,7 +22,7 @@ class TestJIDClass(SleekTest): j.user = 'user' j.domain = 'someserver' j.resource = 'some/resource' - self.check_JID(j, + self.check_jid(j, 'user', 'someserver', 'some/resource', @@ -34,15 +34,15 @@ class TestJIDClass(SleekTest): """Test changing JID using aliases for domain.""" j = JID('user@someserver/resource') j.server = 'anotherserver' - self.check_JID(j, domain='anotherserver') + self.check_jid(j, domain='anotherserver') j.host = 'yetanother' - self.check_JID(j, domain='yetanother') + self.check_jid(j, domain='yetanother') def testJIDSetFullWithUser(self): """Test setting the full JID with a user portion.""" j = JID('user@domain/resource') j.full = 'otheruser@otherdomain/otherresource' - self.check_JID(j, + self.check_jid(j, 'otheruser', 'otherdomain', 'otherresource', @@ -57,7 +57,7 @@ class TestJIDClass(SleekTest): """ j = JID('user@domain/resource') j.full = 'otherdomain/otherresource' - self.check_JID(j, + self.check_jid(j, '', 'otherdomain', 'otherresource', @@ -72,7 +72,7 @@ class TestJIDClass(SleekTest): """ j = JID('user@domain/resource') j.full = 'otherdomain' - self.check_JID(j, + self.check_jid(j, '', 'otherdomain', '', @@ -84,7 +84,7 @@ class TestJIDClass(SleekTest): """Test setting the bare JID with a user.""" j = JID('user@domain/resource') j.bare = 'otheruser@otherdomain' - self.check_JID(j, + self.check_jid(j, 'otheruser', 'otherdomain', 'resource', @@ -96,7 +96,7 @@ class TestJIDClass(SleekTest): """Test setting the bare JID without a user.""" j = JID('user@domain/resource') j.bare = 'otherdomain' - self.check_JID(j, + self.check_jid(j, '', 'otherdomain', 'resource', @@ -106,7 +106,7 @@ class TestJIDClass(SleekTest): def testJIDNoResource(self): """Test using JID of the form 'user@domain'.""" - self.check_JID(JID('user@someserver'), + self.check_jid(JID('user@someserver'), 'user', 'someserver', '', @@ -116,7 +116,7 @@ class TestJIDClass(SleekTest): def testJIDNoUser(self): """Test JID of the form 'component.domain.tld'.""" - self.check_JID(JID('component.someserver'), + self.check_jid(JID('component.someserver'), '', 'component.someserver', '', diff --git a/tests/test_stanza_element.py b/tests/test_stanza_element.py index d361d6f..f7387d3 100644 --- a/tests/test_stanza_element.py +++ b/tests/test_stanza_element.py @@ -27,7 +27,7 @@ class TestElementBase(SleekTest): namespace = "test" stanza = TestStanza() - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ @@ -117,7 +117,7 @@ class TestElementBase(SleekTest): 'baz': ''}]} stanza.setStanzaValues(values) - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ @@ -198,7 +198,7 @@ class TestElementBase(SleekTest): stanza['qux'] = 'overridden' stanza['foobar'] = 'plugin' - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ element! @@ -231,7 +231,7 @@ class TestElementBase(SleekTest): stanza['qux'] = 'c' stanza['foobar']['foobar'] = 'd' - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ a @@ -243,7 +243,7 @@ class TestElementBase(SleekTest): del stanza['qux'] del stanza['foobar'] - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ """) @@ -257,7 +257,7 @@ class TestElementBase(SleekTest): stanza = TestStanza() - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ """) @@ -267,7 +267,7 @@ class TestElementBase(SleekTest): stanza._set_attr('bar', 'a') stanza._set_attr('baz', 'b') - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ """) @@ -277,7 +277,7 @@ class TestElementBase(SleekTest): stanza._set_attr('bar', None) stanza._del_attr('baz') - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ """) @@ -307,7 +307,7 @@ class TestElementBase(SleekTest): "Default _get_sub_text value incorrect.") stanza['bar'] = 'found' - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ found @@ -340,7 +340,7 @@ class TestElementBase(SleekTest): stanza = TestStanza() stanza['bar'] = 'a' stanza['baz'] = 'b' - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ a @@ -349,7 +349,7 @@ class TestElementBase(SleekTest): """) stanza._set_sub_text('wrapper/bar', text='', keep=True) - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ @@ -360,7 +360,7 @@ class TestElementBase(SleekTest): stanza['bar'] = 'a' stanza._set_sub_text('wrapper/bar', text='') - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ b @@ -398,7 +398,7 @@ class TestElementBase(SleekTest): stanza['bar'] = 'a' stanza['baz'] = 'b' - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ @@ -416,7 +416,7 @@ class TestElementBase(SleekTest): del stanza['bar'] del stanza['baz'] - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ @@ -432,7 +432,7 @@ class TestElementBase(SleekTest): stanza._del_sub('path/to/only/bar', all=True) - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ @@ -603,7 +603,7 @@ class TestElementBase(SleekTest): "Incorrect empty stanza size.") stanza.append(substanza1) - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ @@ -612,7 +612,7 @@ class TestElementBase(SleekTest): "Incorrect stanza size with 1 substanza.") stanza.append(substanza2) - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ @@ -623,7 +623,7 @@ class TestElementBase(SleekTest): # Test popping substanzas stanza.pop(0) - self.check_stanza(TestStanza, stanza, """ + self.check(stanza, """ diff --git a/tests/test_stanza_error.py b/tests/test_stanza_error.py index b2d9817..e1c7d5a 100644 --- a/tests/test_stanza_error.py +++ b/tests/test_stanza_error.py @@ -7,7 +7,7 @@ class TestErrorStanzas(SleekTest): """Test setting initial values in error stanza.""" msg = self.Message() msg.enable('error') - self.check_message(msg, """ + self.check(msg, """ @@ -20,7 +20,7 @@ class TestErrorStanzas(SleekTest): msg = self.Message() msg['error']['condition'] = 'item-not-found' - self.check_message(msg, """ + self.check(msg, """ @@ -32,7 +32,7 @@ class TestErrorStanzas(SleekTest): msg['error']['condition'] = 'resource-constraint' - self.check_message(msg, """ + self.check(msg, """ @@ -48,7 +48,7 @@ class TestErrorStanzas(SleekTest): del msg['error']['condition'] - self.check_message(msg, """ + self.check(msg, """ Error! @@ -64,7 +64,7 @@ class TestErrorStanzas(SleekTest): del msg['error']['text'] - self.check_message(msg, """ + self.check(msg, """ diff --git a/tests/test_stanza_gmail.py b/tests/test_stanza_gmail.py index 8ff65a3..6190c60 100644 --- a/tests/test_stanza_gmail.py +++ b/tests/test_stanza_gmail.py @@ -18,7 +18,7 @@ class TestGmail(SleekTest): iq['gmail']['newer-than-time'] = '1140638252542' iq['gmail']['newer-than-tid'] = '11134623426430234' - self.check_iq(iq, """ + self.check(iq, """ """) @@ -19,7 +19,7 @@ class TestIqStanzas(SleekTest): """Test setting Iq stanza payload.""" iq = self.Iq() iq.setPayload(ET.Element('{test}tester')) - self.check_iq(iq, """ + self.check(iq, """ @@ -29,7 +29,7 @@ class TestIqStanzas(SleekTest): def testUnhandled(self): """Test behavior for Iq.unhandled.""" self.stream_start() - self.stream_recv(""" + self.recv(""" @@ -40,7 +40,7 @@ class TestIqStanzas(SleekTest): iq['error']['condition'] = 'feature-not-implemented' iq['error']['text'] = 'No handlers registered for this request.' - self.stream_send_iq(iq, """ + self.send(iq, """ @@ -56,14 +56,14 @@ class TestIqStanzas(SleekTest): iq = self.Iq() iq['query'] = 'query_ns' - self.check_iq(iq, """ + self.check(iq, """ """) iq['query'] = 'query_ns2' - self.check_iq(iq, """ + self.check(iq, """ @@ -72,7 +72,7 @@ class TestIqStanzas(SleekTest): self.failUnless(iq['query'] == 'query_ns2', "Query namespace doesn't match") del iq['query'] - self.check_iq(iq, """ + self.check(iq, """ """) @@ -83,7 +83,7 @@ class TestIqStanzas(SleekTest): iq['type'] = 'get' iq.reply() - self.check_iq(iq, """ + self.check(iq, """ """) diff --git a/tests/test_stanza_message.py b/tests/test_stanza_message.py index 3ffe334..f06b025 100644 --- a/tests/test_stanza_message.py +++ b/tests/test_stanza_message.py @@ -33,7 +33,7 @@ class TestMessageStanzas(SleekTest): p = ET.Element('{http://www.w3.org/1999/xhtml}p') p.text = "This is the htmlim message" msg['html']['body'] = p - self.check_message(msg, """ + self.check(msg, """ this is the plaintext message @@ -47,7 +47,7 @@ class TestMessageStanzas(SleekTest): "Test message/nick/nick stanza." msg = self.Message() msg['nick']['nick'] = 'A nickname!' - self.check_message(msg, """ + self.check(msg, """ A nickname! diff --git a/tests/test_stanza_presence.py b/tests/test_stanza_presence.py index 6a5a8b6..8d043d5 100644 --- a/tests/test_stanza_presence.py +++ b/tests/test_stanza_presence.py @@ -8,26 +8,26 @@ class TestPresenceStanzas(SleekTest): """Regression check presence['type'] = 'dnd' show value working""" p = self.Presence() p['type'] = 'dnd' - self.check_presence(p, "dnd") + self.check(p, "dnd") def testPresenceType(self): """Test manipulating presence['type']""" p = self.Presence() p['type'] = 'available' - self.check_presence(p, "") + self.check(p, "") self.failUnless(p['type'] == 'available', "Incorrect presence['type'] for type 'available': %s" % p['type']) for showtype in ['away', 'chat', 'dnd', 'xa']: p['type'] = showtype - self.check_presence(p, """ + self.check(p, """ %s """ % showtype) self.failUnless(p['type'] == showtype, "Incorrect presence['type'] for type '%s'" % showtype) p['type'] = None - self.check_presence(p, "") + self.check(p, "") def testPresenceUnsolicitedOffline(self): """ @@ -56,7 +56,7 @@ class TestPresenceStanzas(SleekTest): """Test presence/nick/nick stanza.""" p = self.Presence() p['nick']['nick'] = 'A nickname!' - self.check_presence(p, """ + self.check(p, """ A nickname! diff --git a/tests/test_stanza_roster.py b/tests/test_stanza_roster.py index a0e5798..cd3e607 100644 --- a/tests/test_stanza_roster.py +++ b/tests/test_stanza_roster.py @@ -16,7 +16,7 @@ class TestRosterStanzas(SleekTest): 'name': 'Other User', 'subscription': 'both', 'groups': []}}) - self.check_iq(iq, """ + self.check(iq, """ @@ -74,7 +74,7 @@ class TestRosterStanzas(SleekTest): """ iq = self.Iq(ET.fromstring(xml_string)) del iq['roster']['items'] - self.check_iq(iq, """ + self.check(iq, """ diff --git a/tests/test_stanza_xep_0004.py b/tests/test_stanza_xep_0004.py index 5b3e490..bdc4a87 100644 --- a/tests/test_stanza_xep_0004.py +++ b/tests/test_stanza_xep_0004.py @@ -14,7 +14,7 @@ class TestDataForms(SleekTest): msg = self.Message() msg['form']['instructions'] = "Instructions\nSecond batch" - self.check_message(msg, """ + self.check(msg, """ Instructions @@ -35,7 +35,7 @@ class TestDataForms(SleekTest): required=True, value='Some text!') - self.check_message(msg, """ + self.check(msg, """ @@ -62,7 +62,7 @@ class TestDataForms(SleekTest): 'value': 'cool'}, {'label': 'Urgh!', 'value': 'urgh'}]})] - self.check_message(msg, """ + self.check(msg, """ @@ -99,7 +99,7 @@ class TestDataForms(SleekTest): form.setValues({'foo': 'Foo!', 'bar': ['a', 'b']}) - self.check_message(msg, """ + self.check(msg, """ diff --git a/tests/test_stanza_xep_0030.py b/tests/test_stanza_xep_0030.py index c61583b..e367c8d 100644 --- a/tests/test_stanza_xep_0030.py +++ b/tests/test_stanza_xep_0030.py @@ -14,7 +14,7 @@ class TestDisco(SleekTest): iq['id'] = "0" iq['disco_info']['node'] = '' - self.check_iq(iq, """ + self.check(iq, """ @@ -26,7 +26,7 @@ class TestDisco(SleekTest): iq['id'] = "0" iq['disco_info']['node'] = 'foo' - self.check_iq(iq, """ + self.check(iq, """ @@ -38,7 +38,7 @@ class TestDisco(SleekTest): iq['id'] = "0" iq['disco_items']['node'] = '' - self.check_iq(iq, """ + self.check(iq, """ @@ -50,7 +50,7 @@ class TestDisco(SleekTest): iq['id'] = "0" iq['disco_items']['node'] = 'foo' - self.check_iq(iq, """ + self.check(iq, """ @@ -63,7 +63,7 @@ class TestDisco(SleekTest): iq['disco_info']['node'] = 'foo' iq['disco_info'].addIdentity('conference', 'text', 'Chatroom') - self.check_iq(iq, """ + self.check(iq, """ @@ -79,7 +79,7 @@ class TestDisco(SleekTest): iq['disco_info'].addFeature('foo') iq['disco_info'].addFeature('bar') - self.check_iq(iq, """ + self.check(iq, """ @@ -97,7 +97,7 @@ class TestDisco(SleekTest): iq['disco_items'].addItem('user@localhost', 'foo') iq['disco_items'].addItem('user@localhost', 'bar', 'Testing') - self.check_iq(iq, """ + self.check(iq, """ diff --git a/tests/test_stanza_xep_0033.py b/tests/test_stanza_xep_0033.py index 378946a..ec9a530 100644 --- a/tests/test_stanza_xep_0033.py +++ b/tests/test_stanza_xep_0033.py @@ -11,7 +11,7 @@ class TestAddresses(SleekTest): """Testing adding extended stanza address.""" msg = self.Message() msg['addresses'].addAddress(atype='to', jid='to@header1.org') - self.check_message(msg, """ + self.check(msg, """
@@ -23,7 +23,7 @@ class TestAddresses(SleekTest): msg['addresses'].addAddress(atype='replyto', jid='replyto@header1.org', desc='Reply address') - self.check_message(msg, """ + self.check(msg, """
@@ -53,14 +53,14 @@ class TestAddresses(SleekTest): 'jid':'cc@header2.org'}, {'type':'bcc', 'jid':'bcc@header2.org'}]) - self.check_message(msg, xmlstring) + self.check(msg, xmlstring) msg = self.Message() msg['addresses']['replyto'] = [{'jid':'replyto@header1.org', 'desc':'Reply address'}] msg['addresses']['cc'] = [{'jid':'cc@header2.org'}] msg['addresses']['bcc'] = [{'jid':'bcc@header2.org'}] - self.check_message(msg, xmlstring) + self.check(msg, xmlstring) def testAddURI(self): """Testing adding URI attribute to extended stanza address.""" @@ -69,7 +69,7 @@ class TestAddresses(SleekTest): addr = msg['addresses'].addAddress(atype='to', jid='to@header1.org', node='foo') - self.check_message(msg, """ + self.check(msg, """
@@ -78,7 +78,7 @@ class TestAddresses(SleekTest): """) addr['uri'] = 'mailto:to@header2.org' - self.check_message(msg, """ + self.check(msg, """
@@ -99,13 +99,13 @@ class TestAddresses(SleekTest): msg = self.Message() addr = msg['addresses'].addAddress(jid='to@header1.org', atype='to') - self.check_message(msg, xmlstring % '') + self.check(msg, xmlstring % '') addr['delivered'] = True - self.check_message(msg, xmlstring % 'delivered="true"') + self.check(msg, xmlstring % 'delivered="true"') addr['delivered'] = False - self.check_message(msg, xmlstring % '') + self.check(msg, xmlstring % '') suite = unittest.TestLoader().loadTestsFromTestCase(TestAddresses) diff --git a/tests/test_stanza_xep_0060.py b/tests/test_stanza_xep_0060.py index 32ee37a..5d45523 100644 --- a/tests/test_stanza_xep_0060.py +++ b/tests/test_stanza_xep_0060.py @@ -16,7 +16,7 @@ class TestPubsubStanzas(SleekTest): aff2['affiliation'] = 'publisher' iq['pubsub']['affiliations'].append(aff1) iq['pubsub']['affiliations'].append(aff2) - self.check_iq(iq, """ + self.check(iq, """ @@ -38,7 +38,7 @@ class TestPubsubStanzas(SleekTest): sub2['subscription'] = 'subscribed' iq['pubsub']['subscriptions'].append(sub1) iq['pubsub']['subscriptions'].append(sub2) - self.check_iq(iq, """ + self.check(iq, """ @@ -55,7 +55,7 @@ class TestPubsubStanzas(SleekTest): iq['pubsub']['subscription']['node'] = 'testnode alsdkjfas' iq['pubsub']['subscription']['jid'] = "fritzy@netflint.net/sleekxmpp" iq['pubsub']['subscription']['subscription'] = 'unconfigured' - self.check_iq(iq, """ + self.check(iq, """ @@ -88,7 +88,7 @@ class TestPubsubStanzas(SleekTest): item2['payload'] = payload2 iq['pubsub']['items'].append(item) iq['pubsub']['items'].append(item2) - self.check_iq(iq, """ + self.check(iq, """ @@ -115,7 +115,7 @@ class TestPubsubStanzas(SleekTest): iq['pubsub']['configure']['form'].addField('pubsub#title', ftype='text-single', value='This thing is awesome') - self.check_iq(iq, """ + self.check(iq, """ @@ -136,7 +136,7 @@ class TestPubsubStanzas(SleekTest): iq['psstate']['item']= 'myitem' pl = ET.Element('{http://andyet.net/protocol/pubsubqueue}claimed') iq['psstate']['payload'] = pl - self.check_iq(iq, """ + self.check(iq, """ @@ -152,7 +152,7 @@ class TestPubsubStanzas(SleekTest): iq['pubsub_owner']['default']['form'].addField('pubsub#title', ftype='text-single', value='This thing is awesome') - self.check_iq(iq, """ + self.check(iq, """ @@ -176,7 +176,7 @@ class TestPubsubStanzas(SleekTest): form = xep_0004.Form() form.addField('pubsub#title', ftype='text-single', value='this thing is awesome') iq['pubsub']['subscribe']['options']['options'] = form - self.check_iq(iq, """ + self.check(iq, """ @@ -214,7 +214,7 @@ class TestPubsubStanzas(SleekTest): iq['pubsub']['publish'].append(item) iq['pubsub']['publish'].append(item2) - self.check_iq(iq, """ + self.check(iq, """ @@ -238,7 +238,7 @@ class TestPubsubStanzas(SleekTest): "Testing iq/pubsub_owner/delete stanzas" iq = self.Iq() iq['pubsub_owner']['delete']['node'] = 'thingers' - self.check_iq(iq, """ + self.check(iq, """ @@ -300,7 +300,7 @@ class TestPubsubStanzas(SleekTest): 'label': 'Deliver notification only to available users'}), ]) - self.check_iq(iq, """ + self.check(iq, """ @@ -357,7 +357,7 @@ class TestPubsubStanzas(SleekTest): msg['pubsub_event']['items'].append(item) msg['pubsub_event']['items']['node'] = 'cheese' msg['type'] = 'normal' - self.check_message(msg, """ + self.check(msg, """ @@ -383,7 +383,7 @@ class TestPubsubStanzas(SleekTest): msg['pubsub_event']['items'].append(item2) msg['pubsub_event']['items']['node'] = 'cheese' msg['type'] = 'normal' - self.check_message(msg, """ + self.check(msg, """ @@ -415,7 +415,7 @@ class TestPubsubStanzas(SleekTest): msg['pubsub_event']['items'].append(item2) msg['pubsub_event']['items']['node'] = 'cheese' msg['type'] = 'normal' - self.check_message(msg, """ + self.check(msg, """ @@ -435,7 +435,7 @@ class TestPubsubStanzas(SleekTest): msg['pubsub_event']['collection']['associate']['node'] = 'cheese' msg['pubsub_event']['collection']['node'] = 'cheeseburger' msg['type'] = 'headline' - self.check_message(msg, """ + self.check(msg, """ @@ -450,7 +450,7 @@ class TestPubsubStanzas(SleekTest): msg['pubsub_event']['collection']['disassociate']['node'] = 'cheese' msg['pubsub_event']['collection']['node'] = 'cheeseburger' msg['type'] = 'headline' - self.check_message(msg, """ + self.check(msg, """ @@ -467,7 +467,7 @@ class TestPubsubStanzas(SleekTest): ftype='text-single', value='This thing is awesome') msg['type'] = 'headline' - self.check_message(msg, """ + self.check(msg, """ @@ -485,7 +485,7 @@ class TestPubsubStanzas(SleekTest): msg = self.Message() msg['pubsub_event']['purge']['node'] = 'pickles' msg['type'] = 'headline' - self.check_message(msg, """ + self.check(msg, """ @@ -501,7 +501,7 @@ class TestPubsubStanzas(SleekTest): msg['pubsub_event']['subscription']['subscription'] = 'subscribed' msg['pubsub_event']['subscription']['expiry'] = 'presence' msg['type'] = 'headline' - self.check_message(msg, """ + self.check(msg, """ diff --git a/tests/test_stanza_xep_0085.py b/tests/test_stanza_xep_0085.py index a05ab4c..5db7139 100644 --- a/tests/test_stanza_xep_0085.py +++ b/tests/test_stanza_xep_0085.py @@ -21,24 +21,24 @@ class TestChatStates(SleekTest): msg = self.Message() msg['chat_state'].active() - self.check_message(msg, xmlstring % 'active', + self.check(msg, xmlstring % 'active', use_values=False) msg['chat_state'].composing() - self.check_message(msg, xmlstring % 'composing', + self.check(msg, xmlstring % 'composing', use_values=False) msg['chat_state'].gone() - self.check_message(msg, xmlstring % 'gone', + self.check(msg, xmlstring % 'gone', use_values=False) msg['chat_state'].inactive() - self.check_message(msg, xmlstring % 'inactive', + self.check(msg, xmlstring % 'inactive', use_values=False) msg['chat_state'].paused() - self.check_message(msg, xmlstring % 'paused', + self.check(msg, xmlstring % 'paused', use_values=False) suite = unittest.TestLoader().loadTestsFromTestCase(TestChatStates) diff --git a/tests/test_stream.py b/tests/test_stream.py index 3fbf86e..f91f71f 100644 --- a/tests/test_stream.py +++ b/tests/test_stream.py @@ -19,13 +19,13 @@ class TestStreamTester(SleekTest): self.xmpp.add_event_handler('message', echo) - self.stream_recv(""" + self.recv(""" Hi! """) - self.stream_send_message(""" + self.send(""" Thanks for sending: Hi! @@ -40,13 +40,13 @@ class TestStreamTester(SleekTest): self.xmpp.add_event_handler('message', echo) - self.stream_recv(""" + self.recv(""" Hi! """) - self.stream_send_message(""" + self.send(""" Thanks for sending: Hi! @@ -55,6 +55,6 @@ class TestStreamTester(SleekTest): def testSendStreamHeader(self): """Test that we can check a sent stream header.""" self.stream_start(mode='client', skip=False) - self.stream_send_header(sto='localhost') + self.send_header(sto='localhost') suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamTester) diff --git a/tests/test_stream_exceptions.py b/tests/test_stream_exceptions.py index f788a3a..b7be648 100644 --- a/tests/test_stream_exceptions.py +++ b/tests/test_stream_exceptions.py @@ -26,13 +26,13 @@ class TestStreamExceptions(SleekTest): self.stream_start() self.xmpp.add_event_handler('message', message) - self.stream_recv(""" + self.recv(""" This is going to cause an error. """) - self.stream_send_message(""" + self.send(""" This is going to cause an error. """) - self.stream_send_message(""" + self.send(""" This is going to cause an error. """) if sys.version_info < (3, 0): - self.stream_send_message(""" + self.send(""" """) + self.recv("""""") msg = self.Message() msg['body'] = 'Success!' - self.stream_send_message(msg) + self.send(msg) def testWaiter(self): """Test using stream waiter handler.""" @@ -55,7 +55,7 @@ class TestHandlers(SleekTest): self.xmpp.add_event_handler('message', waiter_handler, threaded=True) # Send message to trigger waiter_handler - self.stream_recv(""" + self.recv(""" Testing @@ -66,10 +66,10 @@ class TestHandlers(SleekTest): iq['id'] = 'test' iq['type'] = 'set' iq['query'] = 'test' - self.stream_send_iq(iq) + self.send(iq) # Send the reply Iq - self.stream_recv(""" + self.recv(""" @@ -78,7 +78,7 @@ class TestHandlers(SleekTest): # Check that waiter_handler received the reply msg = self.Message() msg['body'] = 'Successful: test' - self.stream_send_message(msg) + self.send(msg) def testWaiterTimeout(self): """Test that waiter handler is removed after timeout.""" @@ -93,14 +93,14 @@ class TestHandlers(SleekTest): self.xmpp.add_event_handler('message', waiter_handler, threaded=True) # Start test by triggerig waiter_handler - self.stream_recv("""Start Test""") + self.recv("""Start Test""") # Check that Iq was sent to trigger start of timeout period iq = self.Iq() iq['id'] = 'test2' iq['type'] = 'set' iq['query'] = 'test2' - self.stream_send_iq(iq) + self.send(iq) # Check that the waiter is no longer registered waiter_exists = self.xmpp.removeHandler('IqWait_test2') diff --git a/tests/test_stream_presence.py b/tests/test_stream_presence.py index ca67f1d..1d5caa9 100644 --- a/tests/test_stream_presence.py +++ b/tests/test_stream_presence.py @@ -29,7 +29,7 @@ class TestStreamPresence(SleekTest): self.xmpp.add_event_handler('got_offline', got_offline) self.xmpp.add_event_handler('presence_unavailable', unavailable) - self.stream_recv(""" + self.recv(""" """) @@ -54,7 +54,7 @@ class TestStreamPresence(SleekTest): # # We use the stream to initialize the roster to make # the test independent of the roster implementation. - self.stream_recv(""" + self.recv(""" """) # Contact goes offline, should trigger got_offline. - self.stream_recv(""" + self.recv(""" """) @@ -98,7 +98,7 @@ class TestStreamPresence(SleekTest): self.xmpp.add_event_handler('presence_available', presence_available) self.xmpp.add_event_handler('got_online', got_online) - self.stream_recv(""" + self.recv(""" """) @@ -135,15 +135,15 @@ class TestStreamPresence(SleekTest): self.xmpp.auto_authorize = True self.xmpp.auto_subscribe = True - self.stream_recv(""" + self.recv(""" """) - self.stream_send_presence(""" + self.send(""" """) - self.stream_send_presence(""" + self.send(""" """) @@ -172,11 +172,11 @@ class TestStreamPresence(SleekTest): # With this setting we should reject all subscriptions. self.xmpp.auto_authorize = False - self.stream_recv(""" + self.recv(""" """) - self.stream_send_presence(""" + self.send(""" """) diff --git a/tests/test_stream_roster.py b/tests/test_stream_roster.py index 6eda7e3..165a8bc 100644 --- a/tests/test_stream_roster.py +++ b/tests/test_stream_roster.py @@ -20,12 +20,12 @@ class TestStreamRoster(SleekTest): t = threading.Thread(name='get_roster', target=self.xmpp.get_roster) t.start() - self.stream_send_iq(""" + self.send(""" """) - self.stream_recv(""" + self.recv(""" """) - self.stream_send_iq(""" + self.send("""