Changed SleekTest to use underscored names.

This commit is contained in:
Lance Stout 2010-10-07 09:22:27 -04:00
parent 78141fe5f3
commit 75a051556f
16 changed files with 209 additions and 179 deletions

View file

@ -27,8 +27,8 @@ class TestSocket(object):
of an actual networking socket. of an actual networking socket.
Methods: Methods:
nextSent -- Return the next sent stanza. next_sent -- Return the next sent stanza.
recvData -- Make a stanza available to read next. recv_data -- Make a stanza available to read next.
recv -- Read the next stanza from the socket. recv -- Read the next stanza from the socket.
send -- Write a stanza to the socket. send -- Write a stanza to the socket.
makefile -- Dummy call, returns self. makefile -- Dummy call, returns self.
@ -70,7 +70,7 @@ class TestSocket(object):
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# Testing Interface # Testing Interface
def nextSent(self, timeout=None): def next_sent(self, timeout=None):
""" """
Get the next stanza that has been 'sent'. Get the next stanza that has been 'sent'.
@ -85,7 +85,7 @@ class TestSocket(object):
except: except:
return None return None
def recvData(self, data): def recv_data(self, data):
""" """
Add data to the receiving queue. Add data to the receiving queue.
@ -156,18 +156,23 @@ class SleekTest(unittest.TestCase):
Message -- Create a Message stanza object. Message -- Create a Message stanza object.
Iq -- Create an Iq stanza object. Iq -- Create an Iq stanza object.
Presence -- Create a Presence stanza object. Presence -- Create a Presence stanza object.
checkMessage -- Compare a Message stanza against an XML string. check_stanza -- Compare a generic stanza against an XML string.
checkIq -- Compare an Iq stanza against an XML string. check_message -- Compare a Message stanza against an XML string.
checkPresence -- Compare a Presence stanza against an XML string. check_iq -- Compare an Iq stanza against an XML string.
streamStart -- Initialize a dummy XMPP client. check_presence -- Compare a Presence stanza against an XML string.
streamRecv -- Queue data for XMPP client to receive. stream_start -- Initialize a dummy XMPP client.
streamSendMessage -- Check that the XMPP client sent the given 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. Message stanza.
streamSendIq -- Check that the XMPP client sent the given stream_send_iq -- Check that the XMPP client sent the given
Iq stanza. Iq stanza.
streamSendPresence -- Check taht the XMPP client sent the given stream_send_presence -- Check thatt the XMPP client sent the given
Presence stanza. Presence stanza.
streamClose -- Disconnect the XMPP client. stream_send_stanza -- Check that the XMPP client sent the given
generic stanza.
stream_close -- Disconnect the XMPP client.
fix_namespaces -- Add top-level namespace to an XML object. fix_namespaces -- Add top-level namespace to an XML object.
compare -- Compare XML objects against each other. compare -- Compare XML objects against each other.
""" """
@ -211,7 +216,7 @@ class SleekTest(unittest.TestCase):
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# Methods for comparing stanza objects to XML strings # Methods for comparing stanza objects to XML strings
def checkStanza(self, stanza_class, stanza, xml_string, def check_stanza(self, stanza_class, stanza, xml_string,
defaults=None, use_values=True): defaults=None, use_values=True):
""" """
Create and compare several stanza objects to a correct XML string. Create and compare several stanza objects to a correct XML string.
@ -289,7 +294,7 @@ class SleekTest(unittest.TestCase):
self.failUnless(result, debug) self.failUnless(result, debug)
def checkMessage(self, msg, xml_string, use_values=True): def check_message(self, msg, xml_string, use_values=True):
""" """
Create and compare several message stanza objects to a Create and compare several message stanza objects to a
correct XML string. correct XML string.
@ -305,11 +310,11 @@ class SleekTest(unittest.TestCase):
to True. to True.
""" """
return self.checkStanza(Message, msg, xml_string, return self.check_stanza(Message, msg, xml_string,
defaults=['type'], defaults=['type'],
use_values=use_values) use_values=use_values)
def checkIq(self, iq, xml_string, use_values=True): def check_iq(self, iq, xml_string, use_values=True):
""" """
Create and compare several iq stanza objects to a Create and compare several iq stanza objects to a
correct XML string. correct XML string.
@ -324,9 +329,9 @@ class SleekTest(unittest.TestCase):
and setStanzaValues should be used. Defaults and setStanzaValues should be used. Defaults
to True. to True.
""" """
return self.checkStanza(Iq, iq, xml_string, use_values=use_values) return self.check_stanza(Iq, iq, xml_string, use_values=use_values)
def checkPresence(self, pres, xml_string, use_values=True): def check_presence(self, pres, xml_string, use_values=True):
""" """
Create and compare several presence stanza objects to a Create and compare several presence stanza objects to a
correct XML string. correct XML string.
@ -341,14 +346,14 @@ class SleekTest(unittest.TestCase):
and setStanzaValues should be used. Defaults and setStanzaValues should be used. Defaults
to True. to True.
""" """
return self.checkStanza(Presence, pres, xml_string, return self.check_stanza(Presence, pres, xml_string,
defaults=['priority'], defaults=['priority'],
use_values=use_values) use_values=use_values)
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# Methods for simulating stanza streams. # Methods for simulating stanza streams.
def streamStart(self, mode='client', skip=True, header=None): def stream_start(self, mode='client', skip=True, header=None):
""" """
Initialize an XMPP client or component using a dummy XML stream. Initialize an XMPP client or component using a dummy XML stream.
@ -375,17 +380,17 @@ class SleekTest(unittest.TestCase):
# Must have the stream header ready for xmpp.process() to work. # Must have the stream header ready for xmpp.process() to work.
if not header: if not header:
header = self.xmpp.stream_header header = self.xmpp.stream_header
self.xmpp.socket.recvData(header) self.xmpp.socket.recv_data(header)
self.xmpp.connect = lambda a=None, b=None, c=None, d=None: True self.xmpp.connect = lambda a=None, b=None, c=None, d=None: True
self.xmpp.process(threaded=True) self.xmpp.process(threaded=True)
if skip: if skip:
# Clear startup stanzas # Clear startup stanzas
self.xmpp.socket.nextSent(timeout=0.01) self.xmpp.socket.next_sent(timeout=0.01)
if mode == 'component': if mode == 'component':
self.xmpp.socket.nextSent(timeout=0.01) self.xmpp.socket.next_sent(timeout=0.01)
def streamRecv(self, data): def stream_recv(self, data):
""" """
Pass data to the dummy XMPP client as if it came from an XMPP server. Pass data to the dummy XMPP client as if it came from an XMPP server.
@ -394,9 +399,9 @@ class SleekTest(unittest.TestCase):
XMPP client or component. XMPP client or component.
""" """
data = str(data) data = str(data)
self.xmpp.socket.recvData(data) self.xmpp.socket.recv_data(data)
def makeStreamHeader(self, sto='', def stream_make_header(self, sto='',
sfrom='', sfrom='',
sid='', sid='',
stream_ns="http://etherx.jabber.org/streams", stream_ns="http://etherx.jabber.org/streams",
@ -406,7 +411,7 @@ class SleekTest(unittest.TestCase):
""" """
Create a stream header to be received by the test XMPP agent. Create a stream header to be received by the test XMPP agent.
The header must be saved and passed to streamStart. The header must be saved and passed to stream_start.
Arguments: Arguments:
sto -- The recipient of the stream header. sto -- The recipient of the stream header.
@ -433,7 +438,7 @@ class SleekTest(unittest.TestCase):
parts.append('xmlns="%s"' % default_ns) parts.append('xmlns="%s"' % default_ns)
return header % ' '.join(parts) return header % ' '.join(parts)
def streamSendHeader(self, sto='', def stream_send_header(self, sto='',
sfrom='', sfrom='',
sid='', sid='',
stream_ns="http://etherx.jabber.org/streams", stream_ns="http://etherx.jabber.org/streams",
@ -456,12 +461,12 @@ class SleekTest(unittest.TestCase):
timeout -- Length of time to wait in seconds for a timeout -- Length of time to wait in seconds for a
response. response.
""" """
header = self.makeStreamHeader(sto, sfrom, sid, header = self.stream_make_header(sto, sfrom, sid,
stream_ns=stream_ns, stream_ns=stream_ns,
default_ns=default_ns, default_ns=default_ns,
version=version, version=version,
xml_header=xml_header) xml_header=xml_header)
sent_header = self.xmpp.socket.nextSent(timeout) sent_header = self.xmpp.socket.next_sent(timeout)
if sent_header is None: if sent_header is None:
raise ValueError("Socket did not return data.") raise ValueError("Socket did not return data.")
@ -478,75 +483,100 @@ class SleekTest(unittest.TestCase):
"Stream headers do not match:\nDesired:\n%s\nSent:\n%s" % ( "Stream headers do not match:\nDesired:\n%s\nSent:\n%s" % (
header, sent_header)) header, sent_header))
def streamSendMessage(self, data, use_values=True, timeout=.1): def stream_send_stanza(self, stanza_class, data, defaults=None,
use_values=True, timeout=.1):
""" """
Check that the XMPP client sent the given stanza XML. Check that the XMPP client sent the given stanza XML.
Extracts the next sent stanza and compares it with the given Extracts the next sent stanza and compares it with the given
XML using checkMessage. XML using check_stanza.
Arguments:
stanza_class -- The class of the sent stanza object.
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.
defaults -- A list of stanza interfaces that have defaults
values which may interfere with comparisons.
timeout -- Time in seconds to wait for a stanza before
failing the check.
"""
if isintance(data, str):
data = stanza_class(xml=ET.fromstring(data))
sent = self.xmpp.socket.next_sent(timeout)
self.check_stanza(stanza_class, 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: Arguments:
data -- The XML string of the expected Message stanza, data -- The XML string of the expected Message stanza,
or an equivalent stanza object. or an equivalent stanza object.
use_values -- Modifies the type of tests used by checkMessage. use_values -- Modifies the type of tests used by check_message.
timeout -- Time in seconds to wait for a stanza before timeout -- Time in seconds to wait for a stanza before
failing the check. failing the check.
""" """
if isinstance(data, str): if isinstance(data, str):
data = self.Message(xml=ET.fromstring(data)) data = self.Message(xml=ET.fromstring(data))
sent = self.xmpp.socket.nextSent(timeout) sent = self.xmpp.socket.next_sent(timeout)
self.checkMessage(data, sent, use_values) self.check_message(data, sent, use_values)
def streamSendIq(self, data, use_values=True, timeout=.1): def stream_send_iq(self, data, use_values=True, timeout=.1):
""" """
Check that the XMPP client sent the given stanza XML. Check that the XMPP client sent the given stanza XML.
Extracts the next sent stanza and compares it with the given Extracts the next sent stanza and compares it with the given
XML using checkIq. XML using check_iq.
Arguments: Arguments:
data -- The XML string of the expected Iq stanza, data -- The XML string of the expected Iq stanza,
or an equivalent stanza object. or an equivalent stanza object.
use_values -- Modifies the type of tests used by checkIq. use_values -- Modifies the type of tests used by check_iq.
timeout -- Time in seconds to wait for a stanza before timeout -- Time in seconds to wait for a stanza before
failing the check. failing the check.
""" """
if isinstance(data, str): if isinstance(data, str):
data = self.Iq(xml=ET.fromstring(data)) data = self.Iq(xml=ET.fromstring(data))
sent = self.xmpp.socket.nextSent(timeout) sent = self.xmpp.socket.next_sent(timeout)
self.checkIq(data, sent, use_values) self.check_iq(data, sent, use_values)
def streamSendPresence(self, data, use_values=True, timeout=.1): def stream_send_presence(self, data, use_values=True, timeout=.1):
""" """
Check that the XMPP client sent the given stanza XML. Check that the XMPP client sent the given stanza XML.
Extracts the next sent stanza and compares it with the given Extracts the next sent stanza and compares it with the given
XML using checkPresence. XML using check_presence.
Arguments: Arguments:
data -- The XML string of the expected Presence stanza, data -- The XML string of the expected Presence stanza,
or an equivalent stanza object. or an equivalent stanza object.
use_values -- Modifies the type of tests used by checkPresence. use_values -- Modifies the type of tests used by check_presence.
timeout -- Time in seconds to wait for a stanza before timeout -- Time in seconds to wait for a stanza before
failing the check. failing the check.
""" """
if isinstance(data, str): if isinstance(data, str):
data = self.Presence(xml=ET.fromstring(data)) data = self.Presence(xml=ET.fromstring(data))
sent = self.xmpp.socket.nextSent(timeout) sent = self.xmpp.socket.next_sent(timeout)
self.checkPresence(data, sent, use_values) self.check_presence(data, sent, use_values)
def streamClose(self): def stream_close(self):
""" """
Disconnect the dummy XMPP client. Disconnect the dummy XMPP client.
Can be safely called even if streamStart has not been called. Can be safely called even if stream_start has not been called.
Must be placed in the tearDown method of a test class to ensure Must be placed in the tearDown method of a test class to ensure
that the XMPP client is disconnected after an error. that the XMPP client is disconnected after an error.
""" """
if hasattr(self, 'xmpp') and self.xmpp is not None: if hasattr(self, 'xmpp') and self.xmpp is not None:
self.xmpp.disconnect() self.xmpp.disconnect()
self.xmpp.socket.recvData(self.xmpp.stream_footer) self.xmpp.socket.recv_data(self.xmpp.stream_footer)
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# XML Comparison and Cleanup # XML Comparison and Cleanup

View file

@ -11,7 +11,7 @@ class TestAddresses(SleekTest):
"""Testing adding extended stanza address.""" """Testing adding extended stanza address."""
msg = self.Message() msg = self.Message()
msg['addresses'].addAddress(atype='to', jid='to@header1.org') msg['addresses'].addAddress(atype='to', jid='to@header1.org')
self.checkMessage(msg, """ self.check_message(msg, """
<message> <message>
<addresses xmlns="http://jabber.org/protocol/address"> <addresses xmlns="http://jabber.org/protocol/address">
<address jid="to@header1.org" type="to" /> <address jid="to@header1.org" type="to" />
@ -23,7 +23,7 @@ class TestAddresses(SleekTest):
msg['addresses'].addAddress(atype='replyto', msg['addresses'].addAddress(atype='replyto',
jid='replyto@header1.org', jid='replyto@header1.org',
desc='Reply address') desc='Reply address')
self.checkMessage(msg, """ self.check_message(msg, """
<message> <message>
<addresses xmlns="http://jabber.org/protocol/address"> <addresses xmlns="http://jabber.org/protocol/address">
<address jid="replyto@header1.org" type="replyto" desc="Reply address" /> <address jid="replyto@header1.org" type="replyto" desc="Reply address" />
@ -53,14 +53,14 @@ class TestAddresses(SleekTest):
'jid':'cc@header2.org'}, 'jid':'cc@header2.org'},
{'type':'bcc', {'type':'bcc',
'jid':'bcc@header2.org'}]) 'jid':'bcc@header2.org'}])
self.checkMessage(msg, xmlstring) self.check_message(msg, xmlstring)
msg = self.Message() msg = self.Message()
msg['addresses']['replyto'] = [{'jid':'replyto@header1.org', msg['addresses']['replyto'] = [{'jid':'replyto@header1.org',
'desc':'Reply address'}] 'desc':'Reply address'}]
msg['addresses']['cc'] = [{'jid':'cc@header2.org'}] msg['addresses']['cc'] = [{'jid':'cc@header2.org'}]
msg['addresses']['bcc'] = [{'jid':'bcc@header2.org'}] msg['addresses']['bcc'] = [{'jid':'bcc@header2.org'}]
self.checkMessage(msg, xmlstring) self.check_message(msg, xmlstring)
def testAddURI(self): def testAddURI(self):
"""Testing adding URI attribute to extended stanza address.""" """Testing adding URI attribute to extended stanza address."""
@ -69,7 +69,7 @@ class TestAddresses(SleekTest):
addr = msg['addresses'].addAddress(atype='to', addr = msg['addresses'].addAddress(atype='to',
jid='to@header1.org', jid='to@header1.org',
node='foo') node='foo')
self.checkMessage(msg, """ self.check_message(msg, """
<message> <message>
<addresses xmlns="http://jabber.org/protocol/address"> <addresses xmlns="http://jabber.org/protocol/address">
<address node="foo" jid="to@header1.org" type="to" /> <address node="foo" jid="to@header1.org" type="to" />
@ -78,7 +78,7 @@ class TestAddresses(SleekTest):
""") """)
addr['uri'] = 'mailto:to@header2.org' addr['uri'] = 'mailto:to@header2.org'
self.checkMessage(msg, """ self.check_message(msg, """
<message> <message>
<addresses xmlns="http://jabber.org/protocol/address"> <addresses xmlns="http://jabber.org/protocol/address">
<address type="to" uri="mailto:to@header2.org" /> <address type="to" uri="mailto:to@header2.org" />
@ -99,13 +99,13 @@ class TestAddresses(SleekTest):
msg = self.Message() msg = self.Message()
addr = msg['addresses'].addAddress(jid='to@header1.org', atype='to') addr = msg['addresses'].addAddress(jid='to@header1.org', atype='to')
self.checkMessage(msg, xmlstring % '') self.check_message(msg, xmlstring % '')
addr['delivered'] = True addr['delivered'] = True
self.checkMessage(msg, xmlstring % 'delivered="true"') self.check_message(msg, xmlstring % 'delivered="true"')
addr['delivered'] = False addr['delivered'] = False
self.checkMessage(msg, xmlstring % '') self.check_message(msg, xmlstring % '')
suite = unittest.TestLoader().loadTestsFromTestCase(TestAddresses) suite = unittest.TestLoader().loadTestsFromTestCase(TestAddresses)

View file

@ -21,24 +21,24 @@ class TestChatStates(SleekTest):
msg = self.Message() msg = self.Message()
msg['chat_state'].active() msg['chat_state'].active()
self.checkMessage(msg, xmlstring % 'active', self.check_message(msg, xmlstring % 'active',
use_values=False) use_values=False)
msg['chat_state'].composing() msg['chat_state'].composing()
self.checkMessage(msg, xmlstring % 'composing', self.check_message(msg, xmlstring % 'composing',
use_values=False) use_values=False)
msg['chat_state'].gone() msg['chat_state'].gone()
self.checkMessage(msg, xmlstring % 'gone', self.check_message(msg, xmlstring % 'gone',
use_values=False) use_values=False)
msg['chat_state'].inactive() msg['chat_state'].inactive()
self.checkMessage(msg, xmlstring % 'inactive', self.check_message(msg, xmlstring % 'inactive',
use_values=False) use_values=False)
msg['chat_state'].paused() msg['chat_state'].paused()
self.checkMessage(msg, xmlstring % 'paused', self.check_message(msg, xmlstring % 'paused',
use_values=False) use_values=False)
suite = unittest.TestLoader().loadTestsFromTestCase(TestChatStates) suite = unittest.TestLoader().loadTestsFromTestCase(TestChatStates)

View file

@ -14,7 +14,7 @@ class TestDisco(SleekTest):
iq['id'] = "0" iq['id'] = "0"
iq['disco_info']['node'] = '' iq['disco_info']['node'] = ''
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<query xmlns="http://jabber.org/protocol/disco#info" /> <query xmlns="http://jabber.org/protocol/disco#info" />
</iq> </iq>
@ -26,7 +26,7 @@ class TestDisco(SleekTest):
iq['id'] = "0" iq['id'] = "0"
iq['disco_info']['node'] = 'foo' iq['disco_info']['node'] = 'foo'
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<query xmlns="http://jabber.org/protocol/disco#info" node="foo" /> <query xmlns="http://jabber.org/protocol/disco#info" node="foo" />
</iq> </iq>
@ -38,7 +38,7 @@ class TestDisco(SleekTest):
iq['id'] = "0" iq['id'] = "0"
iq['disco_items']['node'] = '' iq['disco_items']['node'] = ''
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<query xmlns="http://jabber.org/protocol/disco#items" /> <query xmlns="http://jabber.org/protocol/disco#items" />
</iq> </iq>
@ -50,7 +50,7 @@ class TestDisco(SleekTest):
iq['id'] = "0" iq['id'] = "0"
iq['disco_items']['node'] = 'foo' iq['disco_items']['node'] = 'foo'
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<query xmlns="http://jabber.org/protocol/disco#items" node="foo" /> <query xmlns="http://jabber.org/protocol/disco#items" node="foo" />
</iq> </iq>
@ -63,7 +63,7 @@ class TestDisco(SleekTest):
iq['disco_info']['node'] = 'foo' iq['disco_info']['node'] = 'foo'
iq['disco_info'].addIdentity('conference', 'text', 'Chatroom') iq['disco_info'].addIdentity('conference', 'text', 'Chatroom')
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<query xmlns="http://jabber.org/protocol/disco#info" node="foo"> <query xmlns="http://jabber.org/protocol/disco#info" node="foo">
<identity category="conference" type="text" name="Chatroom" /> <identity category="conference" type="text" name="Chatroom" />
@ -79,7 +79,7 @@ class TestDisco(SleekTest):
iq['disco_info'].addFeature('foo') iq['disco_info'].addFeature('foo')
iq['disco_info'].addFeature('bar') iq['disco_info'].addFeature('bar')
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<query xmlns="http://jabber.org/protocol/disco#info" node="foo"> <query xmlns="http://jabber.org/protocol/disco#info" node="foo">
<feature var="foo" /> <feature var="foo" />
@ -97,7 +97,7 @@ class TestDisco(SleekTest):
iq['disco_items'].addItem('user@localhost', 'foo') iq['disco_items'].addItem('user@localhost', 'foo')
iq['disco_items'].addItem('user@localhost', 'bar', 'Testing') iq['disco_items'].addItem('user@localhost', 'bar', 'Testing')
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<query xmlns="http://jabber.org/protocol/disco#items" node="foo"> <query xmlns="http://jabber.org/protocol/disco#items" node="foo">
<item jid="user@localhost" /> <item jid="user@localhost" />

View file

@ -26,7 +26,7 @@ class TestElementBase(SleekTest):
namespace = "test" namespace = "test"
stanza = TestStanza() stanza = TestStanza()
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="test"> <foo xmlns="test">
<bar> <bar>
<baz /> <baz />
@ -116,7 +116,7 @@ class TestElementBase(SleekTest):
'baz': ''}]} 'baz': ''}]}
stanza.setStanzaValues(values) stanza.setStanzaValues(values)
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo" bar="a"> <foo xmlns="foo" bar="a">
<pluginfoo baz="b" /> <pluginfoo baz="b" />
<pluginfoo2 bar="d" baz="e" /> <pluginfoo2 bar="d" baz="e" />
@ -197,7 +197,7 @@ class TestElementBase(SleekTest):
stanza['qux'] = 'overridden' stanza['qux'] = 'overridden'
stanza['foobar'] = 'plugin' stanza['foobar'] = 'plugin'
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo" bar="attribute!"> <foo xmlns="foo" bar="attribute!">
<baz>element!</baz> <baz>element!</baz>
<foobar foobar="plugin" /> <foobar foobar="plugin" />
@ -230,7 +230,7 @@ class TestElementBase(SleekTest):
stanza['qux'] = 'c' stanza['qux'] = 'c'
stanza['foobar']['foobar'] = 'd' stanza['foobar']['foobar'] = 'd'
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo" baz="b" qux="c"> <foo xmlns="foo" baz="b" qux="c">
<bar>a</bar> <bar>a</bar>
<foobar foobar="d" /> <foobar foobar="d" />
@ -242,7 +242,7 @@ class TestElementBase(SleekTest):
del stanza['qux'] del stanza['qux']
del stanza['foobar'] del stanza['foobar']
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo" qux="c" /> <foo xmlns="foo" qux="c" />
""") """)
@ -256,7 +256,7 @@ class TestElementBase(SleekTest):
stanza = TestStanza() stanza = TestStanza()
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo" /> <foo xmlns="foo" />
""") """)
@ -266,7 +266,7 @@ class TestElementBase(SleekTest):
stanza._setAttr('bar', 'a') stanza._setAttr('bar', 'a')
stanza._setAttr('baz', 'b') stanza._setAttr('baz', 'b')
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo" bar="a" baz="b" /> <foo xmlns="foo" bar="a" baz="b" />
""") """)
@ -276,7 +276,7 @@ class TestElementBase(SleekTest):
stanza._setAttr('bar', None) stanza._setAttr('bar', None)
stanza._delAttr('baz') stanza._delAttr('baz')
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo" /> <foo xmlns="foo" />
""") """)
@ -306,7 +306,7 @@ class TestElementBase(SleekTest):
"Default _getSubText value incorrect.") "Default _getSubText value incorrect.")
stanza['bar'] = 'found' stanza['bar'] = 'found'
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo"> <foo xmlns="foo">
<wrapper> <wrapper>
<bar>found</bar> <bar>found</bar>
@ -339,7 +339,7 @@ class TestElementBase(SleekTest):
stanza = TestStanza() stanza = TestStanza()
stanza['bar'] = 'a' stanza['bar'] = 'a'
stanza['baz'] = 'b' stanza['baz'] = 'b'
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo"> <foo xmlns="foo">
<wrapper> <wrapper>
<bar>a</bar> <bar>a</bar>
@ -348,7 +348,7 @@ class TestElementBase(SleekTest):
</foo> </foo>
""") """)
stanza._setSubText('wrapper/bar', text='', keep=True) stanza._setSubText('wrapper/bar', text='', keep=True)
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo"> <foo xmlns="foo">
<wrapper> <wrapper>
<bar /> <bar />
@ -359,7 +359,7 @@ class TestElementBase(SleekTest):
stanza['bar'] = 'a' stanza['bar'] = 'a'
stanza._setSubText('wrapper/bar', text='') stanza._setSubText('wrapper/bar', text='')
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo"> <foo xmlns="foo">
<wrapper> <wrapper>
<baz>b</baz> <baz>b</baz>
@ -397,7 +397,7 @@ class TestElementBase(SleekTest):
stanza['bar'] = 'a' stanza['bar'] = 'a'
stanza['baz'] = 'b' stanza['baz'] = 'b'
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo"> <foo xmlns="foo">
<path> <path>
<to> <to>
@ -415,7 +415,7 @@ class TestElementBase(SleekTest):
del stanza['bar'] del stanza['bar']
del stanza['baz'] del stanza['baz']
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo"> <foo xmlns="foo">
<path> <path>
<to> <to>
@ -431,7 +431,7 @@ class TestElementBase(SleekTest):
stanza._delSub('path/to/only/bar', all=True) stanza._delSub('path/to/only/bar', all=True)
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo"> <foo xmlns="foo">
<path> <path>
<to> <to>
@ -602,7 +602,7 @@ class TestElementBase(SleekTest):
"Incorrect empty stanza size.") "Incorrect empty stanza size.")
stanza.append(substanza1) stanza.append(substanza1)
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo"> <foo xmlns="foo">
<foobar qux="a" /> <foobar qux="a" />
</foo> </foo>
@ -611,7 +611,7 @@ class TestElementBase(SleekTest):
"Incorrect stanza size with 1 substanza.") "Incorrect stanza size with 1 substanza.")
stanza.append(substanza2) stanza.append(substanza2)
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo"> <foo xmlns="foo">
<foobar qux="a" /> <foobar qux="a" />
<foobar qux="b" /> <foobar qux="b" />
@ -622,7 +622,7 @@ class TestElementBase(SleekTest):
# Test popping substanzas # Test popping substanzas
stanza.pop(0) stanza.pop(0)
self.checkStanza(TestStanza, stanza, """ self.check_stanza(TestStanza, stanza, """
<foo xmlns="foo"> <foo xmlns="foo">
<foobar qux="b" /> <foobar qux="b" />
</foo> </foo>

View file

@ -6,7 +6,7 @@ class TestErrorStanzas(SleekTest):
"""Test setting initial values in error stanza.""" """Test setting initial values in error stanza."""
msg = self.Message() msg = self.Message()
msg.enable('error') msg.enable('error')
self.checkMessage(msg, """ self.check_message(msg, """
<message type="error"> <message type="error">
<error type="cancel"> <error type="cancel">
<feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /> <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
@ -19,7 +19,7 @@ class TestErrorStanzas(SleekTest):
msg = self.Message() msg = self.Message()
msg['error']['condition'] = 'item-not-found' msg['error']['condition'] = 'item-not-found'
self.checkMessage(msg, """ self.check_message(msg, """
<message type="error"> <message type="error">
<error type="cancel"> <error type="cancel">
<item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /> <item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
@ -31,7 +31,7 @@ class TestErrorStanzas(SleekTest):
del msg['error']['condition'] del msg['error']['condition']
self.checkMessage(msg, """ self.check_message(msg, """
<message type="error"> <message type="error">
<error type="cancel" /> <error type="cancel" />
</message> </message>
@ -45,7 +45,7 @@ class TestErrorStanzas(SleekTest):
del msg['error']['condition'] del msg['error']['condition']
self.checkMessage(msg, """ self.check_message(msg, """
<message type="error"> <message type="error">
<error type="cancel"> <error type="cancel">
<text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Error!</text> <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Error!</text>

View file

@ -6,10 +6,10 @@ from . sleektest import *
class TestEvents(SleekTest): class TestEvents(SleekTest):
def setUp(self): def setUp(self):
self.streamStart() self.stream_start()
def tearDown(self): def tearDown(self):
self.streamClose() self.stream_close()
def testEventHappening(self): def testEventHappening(self):
"""Test handler working""" """Test handler working"""

View file

@ -14,7 +14,7 @@ class TestDataForms(SleekTest):
msg = self.Message() msg = self.Message()
msg['form']['instructions'] = "Instructions\nSecond batch" msg['form']['instructions'] = "Instructions\nSecond batch"
self.checkMessage(msg, """ self.check_message(msg, """
<message> <message>
<x xmlns="jabber:x:data" type="form"> <x xmlns="jabber:x:data" type="form">
<instructions>Instructions</instructions> <instructions>Instructions</instructions>
@ -35,7 +35,7 @@ class TestDataForms(SleekTest):
required=True, required=True,
value='Some text!') value='Some text!')
self.checkMessage(msg, """ self.check_message(msg, """
<message> <message>
<x xmlns="jabber:x:data" type="form"> <x xmlns="jabber:x:data" type="form">
<field var="f1" type="text-single" label="Text"> <field var="f1" type="text-single" label="Text">
@ -62,7 +62,7 @@ class TestDataForms(SleekTest):
'value': 'cool'}, 'value': 'cool'},
{'label': 'Urgh!', {'label': 'Urgh!',
'value': 'urgh'}]})] 'value': 'urgh'}]})]
self.checkMessage(msg, """ self.check_message(msg, """
<message> <message>
<x xmlns="jabber:x:data" type="form"> <x xmlns="jabber:x:data" type="form">
<field var="f1" type="text-single" label="Username"> <field var="f1" type="text-single" label="Username">
@ -99,7 +99,7 @@ class TestDataForms(SleekTest):
form.setValues({'foo': 'Foo!', form.setValues({'foo': 'Foo!',
'bar': ['a', 'b']}) 'bar': ['a', 'b']})
self.checkMessage(msg, """ self.check_message(msg, """
<message> <message>
<x xmlns="jabber:x:data" type="form"> <x xmlns="jabber:x:data" type="form">
<field var="foo" type="text-single"> <field var="foo" type="text-single">

View file

@ -18,7 +18,7 @@ class TestGmail(SleekTest):
iq['gmail']['newer-than-time'] = '1140638252542' iq['gmail']['newer-than-time'] = '1140638252542'
iq['gmail']['newer-than-tid'] = '11134623426430234' iq['gmail']['newer-than-tid'] = '11134623426430234'
self.checkIq(iq, """ self.check_iq(iq, """
<iq type="get"> <iq type="get">
<query xmlns="google:mail:notify" <query xmlns="google:mail:notify"
newer-than-time="1140638252542" newer-than-time="1140638252542"

View file

@ -9,10 +9,10 @@ class TestHandlers(SleekTest):
""" """
def setUp(self): def setUp(self):
self.streamStart() self.stream_start()
def tearDown(self): def tearDown(self):
self.streamClose() self.stream_close()
def testCallback(self): def testCallback(self):
"""Test using stream callback handlers.""" """Test using stream callback handlers."""
@ -30,11 +30,11 @@ class TestHandlers(SleekTest):
self.xmpp.registerHandler(callback) self.xmpp.registerHandler(callback)
self.streamRecv("""<tester xmlns="test" />""") self.stream_recv("""<tester xmlns="test" />""")
msg = self.Message() msg = self.Message()
msg['body'] = 'Success!' msg['body'] = 'Success!'
self.streamSendMessage(msg) self.stream_send_message(msg)
def testWaiter(self): def testWaiter(self):
"""Test using stream waiter handler.""" """Test using stream waiter handler."""
@ -55,7 +55,7 @@ class TestHandlers(SleekTest):
self.xmpp.add_event_handler('message', waiter_handler, threaded=True) self.xmpp.add_event_handler('message', waiter_handler, threaded=True)
# Send message to trigger waiter_handler # Send message to trigger waiter_handler
self.streamRecv(""" self.stream_recv("""
<message> <message>
<body>Testing</body> <body>Testing</body>
</message> </message>
@ -66,10 +66,10 @@ class TestHandlers(SleekTest):
iq['id'] = 'test' iq['id'] = 'test'
iq['type'] = 'set' iq['type'] = 'set'
iq['query'] = 'test' iq['query'] = 'test'
self.streamSendIq(iq) self.stream_send_iq(iq)
# Send the reply Iq # Send the reply Iq
self.streamRecv(""" self.stream_recv("""
<iq id="test" type="result"> <iq id="test" type="result">
<query xmlns="test" /> <query xmlns="test" />
</iq> </iq>
@ -78,7 +78,7 @@ class TestHandlers(SleekTest):
# Check that waiter_handler received the reply # Check that waiter_handler received the reply
msg = self.Message() msg = self.Message()
msg['body'] = 'Successful: test' msg['body'] = 'Successful: test'
self.streamSendMessage(msg) self.stream_send_message(msg)
def testWaiterTimeout(self): def testWaiterTimeout(self):
"""Test that waiter handler is removed after timeout.""" """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) self.xmpp.add_event_handler('message', waiter_handler, threaded=True)
# Start test by triggerig waiter_handler # Start test by triggerig waiter_handler
self.streamRecv("""<message><body>Start Test</body></message>""") self.stream_recv("""<message><body>Start Test</body></message>""")
# Check that Iq was sent to trigger start of timeout period # Check that Iq was sent to trigger start of timeout period
iq = self.Iq() iq = self.Iq()
iq['id'] = 'test2' iq['id'] = 'test2'
iq['type'] = 'set' iq['type'] = 'set'
iq['query'] = 'test2' iq['query'] = 'test2'
self.streamSendIq(iq) self.stream_send_iq(iq)
# Check that the waiter is no longer registered # Check that the waiter is no longer registered
waiter_exists = self.xmpp.removeHandler('IqWait_test2') waiter_exists = self.xmpp.removeHandler('IqWait_test2')

View file

@ -6,12 +6,12 @@ class TestIqStanzas(SleekTest):
def tearDown(self): def tearDown(self):
"""Shutdown the XML stream after testing.""" """Shutdown the XML stream after testing."""
self.streamClose() self.stream_close()
def testSetup(self): def testSetup(self):
"""Test initializing default Iq values.""" """Test initializing default Iq values."""
iq = self.Iq() iq = self.Iq()
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0" /> <iq id="0" />
""") """)
@ -19,7 +19,7 @@ class TestIqStanzas(SleekTest):
"""Test setting Iq stanza payload.""" """Test setting Iq stanza payload."""
iq = self.Iq() iq = self.Iq()
iq.setPayload(ET.Element('{test}tester')) iq.setPayload(ET.Element('{test}tester'))
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<tester xmlns="test" /> <tester xmlns="test" />
</iq> </iq>
@ -28,8 +28,8 @@ class TestIqStanzas(SleekTest):
def testUnhandled(self): def testUnhandled(self):
"""Test behavior for Iq.unhandled.""" """Test behavior for Iq.unhandled."""
self.streamStart() self.stream_start()
self.streamRecv(""" self.stream_recv("""
<iq id="test" type="get"> <iq id="test" type="get">
<query xmlns="test" /> <query xmlns="test" />
</iq> </iq>
@ -40,7 +40,7 @@ class TestIqStanzas(SleekTest):
iq['error']['condition'] = 'feature-not-implemented' iq['error']['condition'] = 'feature-not-implemented'
iq['error']['text'] = 'No handlers registered for this request.' iq['error']['text'] = 'No handlers registered for this request.'
self.streamSendIq(iq, """ self.stream_send_iq(iq, """
<iq id="test" type="error"> <iq id="test" type="error">
<error type="cancel"> <error type="cancel">
<feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /> <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
@ -56,14 +56,14 @@ class TestIqStanzas(SleekTest):
iq = self.Iq() iq = self.Iq()
iq['query'] = 'query_ns' iq['query'] = 'query_ns'
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<query xmlns="query_ns" /> <query xmlns="query_ns" />
</iq> </iq>
""") """)
iq['query'] = 'query_ns2' iq['query'] = 'query_ns2'
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<query xmlns="query_ns2" /> <query xmlns="query_ns2" />
</iq> </iq>
@ -72,7 +72,7 @@ class TestIqStanzas(SleekTest):
self.failUnless(iq['query'] == 'query_ns2', "Query namespace doesn't match") self.failUnless(iq['query'] == 'query_ns2', "Query namespace doesn't match")
del iq['query'] del iq['query']
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0" /> <iq id="0" />
""") """)
@ -83,7 +83,7 @@ class TestIqStanzas(SleekTest):
iq['type'] = 'get' iq['type'] = 'get'
iq.reply() iq.reply()
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0" type="result" /> <iq id="0" type="result" />
""") """)

View file

@ -33,7 +33,7 @@ class TestMessageStanzas(SleekTest):
p = ET.Element('{http://www.w3.org/1999/xhtml}p') p = ET.Element('{http://www.w3.org/1999/xhtml}p')
p.text = "This is the htmlim message" p.text = "This is the htmlim message"
msg['html']['body'] = p msg['html']['body'] = p
self.checkMessage(msg, """ self.check_message(msg, """
<message to="fritzy@netflint.net/sleekxmpp" type="chat"> <message to="fritzy@netflint.net/sleekxmpp" type="chat">
<body>this is the plaintext message</body> <body>this is the plaintext message</body>
<html xmlns="http://jabber.org/protocol/xhtml-im"> <html xmlns="http://jabber.org/protocol/xhtml-im">
@ -47,7 +47,7 @@ class TestMessageStanzas(SleekTest):
"Test message/nick/nick stanza." "Test message/nick/nick stanza."
msg = self.Message() msg = self.Message()
msg['nick']['nick'] = 'A nickname!' msg['nick']['nick'] = 'A nickname!'
self.checkMessage(msg, """ self.check_message(msg, """
<message> <message>
<nick xmlns="http://jabber.org/nick/nick">A nickname!</nick> <nick xmlns="http://jabber.org/nick/nick">A nickname!</nick>
</message> </message>

View file

@ -9,26 +9,26 @@ class TestPresenceStanzas(SleekTest):
"""Regression check presence['type'] = 'dnd' show value working""" """Regression check presence['type'] = 'dnd' show value working"""
p = self.Presence() p = self.Presence()
p['type'] = 'dnd' p['type'] = 'dnd'
self.checkPresence(p, "<presence><show>dnd</show></presence>") self.check_presence(p, "<presence><show>dnd</show></presence>")
def testPresenceType(self): def testPresenceType(self):
"""Test manipulating presence['type']""" """Test manipulating presence['type']"""
p = self.Presence() p = self.Presence()
p['type'] = 'available' p['type'] = 'available'
self.checkPresence(p, "<presence />") self.check_presence(p, "<presence />")
self.failUnless(p['type'] == 'available', self.failUnless(p['type'] == 'available',
"Incorrect presence['type'] for type 'available'") "Incorrect presence['type'] for type 'available'")
for showtype in ['away', 'chat', 'dnd', 'xa']: for showtype in ['away', 'chat', 'dnd', 'xa']:
p['type'] = showtype p['type'] = showtype
self.checkPresence(p, """ self.check_presence(p, """
<presence><show>%s</show></presence> <presence><show>%s</show></presence>
""" % showtype) """ % showtype)
self.failUnless(p['type'] == showtype, self.failUnless(p['type'] == showtype,
"Incorrect presence['type'] for type '%s'" % showtype) "Incorrect presence['type'] for type '%s'" % showtype)
p['type'] = None p['type'] = None
self.checkPresence(p, "<presence />") self.check_presence(p, "<presence />")
def testPresenceUnsolicitedOffline(self): def testPresenceUnsolicitedOffline(self):
""" """
@ -57,7 +57,7 @@ class TestPresenceStanzas(SleekTest):
"""Test presence/nick/nick stanza.""" """Test presence/nick/nick stanza."""
p = self.Presence() p = self.Presence()
p['nick']['nick'] = 'A nickname!' p['nick']['nick'] = 'A nickname!'
self.checkPresence(p, """ self.check_presence(p, """
<presence> <presence>
<nick xmlns="http://jabber.org/nick/nick">A nickname!</nick> <nick xmlns="http://jabber.org/nick/nick">A nickname!</nick>
</presence> </presence>

View file

@ -16,7 +16,7 @@ class TestPubsubStanzas(SleekTest):
aff2['affiliation'] = 'publisher' aff2['affiliation'] = 'publisher'
iq['pubsub']['affiliations'].append(aff1) iq['pubsub']['affiliations'].append(aff1)
iq['pubsub']['affiliations'].append(aff2) iq['pubsub']['affiliations'].append(aff2)
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
<affiliations> <affiliations>
@ -38,7 +38,7 @@ class TestPubsubStanzas(SleekTest):
sub2['subscription'] = 'subscribed' sub2['subscription'] = 'subscribed'
iq['pubsub']['subscriptions'].append(sub1) iq['pubsub']['subscriptions'].append(sub1)
iq['pubsub']['subscriptions'].append(sub2) iq['pubsub']['subscriptions'].append(sub2)
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
<subscriptions> <subscriptions>
@ -55,7 +55,7 @@ class TestPubsubStanzas(SleekTest):
iq['pubsub']['subscription']['node'] = 'testnode alsdkjfas' iq['pubsub']['subscription']['node'] = 'testnode alsdkjfas'
iq['pubsub']['subscription']['jid'] = "fritzy@netflint.net/sleekxmpp" iq['pubsub']['subscription']['jid'] = "fritzy@netflint.net/sleekxmpp"
iq['pubsub']['subscription']['subscription'] = 'unconfigured' iq['pubsub']['subscription']['subscription'] = 'unconfigured'
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
<subscription node="testnode alsdkjfas" jid="fritzy@netflint.net/sleekxmpp" subscription="unconfigured"> <subscription node="testnode alsdkjfas" jid="fritzy@netflint.net/sleekxmpp" subscription="unconfigured">
@ -88,7 +88,7 @@ class TestPubsubStanzas(SleekTest):
item2['payload'] = payload2 item2['payload'] = payload2
iq['pubsub']['items'].append(item) iq['pubsub']['items'].append(item)
iq['pubsub']['items'].append(item2) iq['pubsub']['items'].append(item2)
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
<items node="crap"> <items node="crap">
@ -115,7 +115,7 @@ class TestPubsubStanzas(SleekTest):
iq['pubsub']['configure']['form'].addField('pubsub#title', iq['pubsub']['configure']['form'].addField('pubsub#title',
ftype='text-single', ftype='text-single',
value='This thing is awesome') value='This thing is awesome')
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
<create node="mynode" /> <create node="mynode" />
@ -136,7 +136,7 @@ class TestPubsubStanzas(SleekTest):
iq['psstate']['item']= 'myitem' iq['psstate']['item']= 'myitem'
pl = ET.Element('{http://andyet.net/protocol/pubsubqueue}claimed') pl = ET.Element('{http://andyet.net/protocol/pubsubqueue}claimed')
iq['psstate']['payload'] = pl iq['psstate']['payload'] = pl
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<state xmlns="http://jabber.org/protocol/psstate" node="mynode" item="myitem"> <state xmlns="http://jabber.org/protocol/psstate" node="mynode" item="myitem">
<claimed xmlns="http://andyet.net/protocol/pubsubqueue" /> <claimed xmlns="http://andyet.net/protocol/pubsubqueue" />
@ -152,7 +152,7 @@ class TestPubsubStanzas(SleekTest):
iq['pubsub_owner']['default']['form'].addField('pubsub#title', iq['pubsub_owner']['default']['form'].addField('pubsub#title',
ftype='text-single', ftype='text-single',
value='This thing is awesome') value='This thing is awesome')
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner"> <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
<default node="mynode" type="leaf"> <default node="mynode" type="leaf">
@ -176,7 +176,7 @@ class TestPubsubStanzas(SleekTest):
form = xep_0004.Form() form = xep_0004.Form()
form.addField('pubsub#title', ftype='text-single', value='this thing is awesome') form.addField('pubsub#title', ftype='text-single', value='this thing is awesome')
iq['pubsub']['subscribe']['options']['options'] = form iq['pubsub']['subscribe']['options']['options'] = form
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
<subscribe node="cheese" jid="fritzy@netflint.net/sleekxmpp"> <subscribe node="cheese" jid="fritzy@netflint.net/sleekxmpp">
@ -214,7 +214,7 @@ class TestPubsubStanzas(SleekTest):
iq['pubsub']['publish'].append(item) iq['pubsub']['publish'].append(item)
iq['pubsub']['publish'].append(item2) iq['pubsub']['publish'].append(item2)
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
<publish node="thingers"> <publish node="thingers">
@ -238,7 +238,7 @@ class TestPubsubStanzas(SleekTest):
"Testing iq/pubsub_owner/delete stanzas" "Testing iq/pubsub_owner/delete stanzas"
iq = self.Iq() iq = self.Iq()
iq['pubsub_owner']['delete']['node'] = 'thingers' iq['pubsub_owner']['delete']['node'] = 'thingers'
self.checkIq(iq, """ self.check_iq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner"> <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
<delete node="thingers" /> <delete node="thingers" />
@ -300,7 +300,7 @@ class TestPubsubStanzas(SleekTest):
'label': 'Deliver notification only to available users'}), 'label': 'Deliver notification only to available users'}),
]) ])
self.checkIq(iq, """ self.check_iq(iq, """
<iq to="pubsub.asdf" type="set" id="E" from="fritzy@asdf/87292ede-524d-4117-9076-d934ed3db8e7"> <iq to="pubsub.asdf" type="set" id="E" from="fritzy@asdf/87292ede-524d-4117-9076-d934ed3db8e7">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
<create node="testnode2" /> <create node="testnode2" />
@ -357,7 +357,7 @@ class TestPubsubStanzas(SleekTest):
msg['pubsub_event']['items'].append(item) msg['pubsub_event']['items'].append(item)
msg['pubsub_event']['items']['node'] = 'cheese' msg['pubsub_event']['items']['node'] = 'cheese'
msg['type'] = 'normal' msg['type'] = 'normal'
self.checkMessage(msg, """ self.check_message(msg, """
<message type="normal"> <message type="normal">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<items node="cheese"> <items node="cheese">
@ -383,7 +383,7 @@ class TestPubsubStanzas(SleekTest):
msg['pubsub_event']['items'].append(item2) msg['pubsub_event']['items'].append(item2)
msg['pubsub_event']['items']['node'] = 'cheese' msg['pubsub_event']['items']['node'] = 'cheese'
msg['type'] = 'normal' msg['type'] = 'normal'
self.checkMessage(msg, """ self.check_message(msg, """
<message type="normal"> <message type="normal">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<items node="cheese"> <items node="cheese">
@ -415,7 +415,7 @@ class TestPubsubStanzas(SleekTest):
msg['pubsub_event']['items'].append(item2) msg['pubsub_event']['items'].append(item2)
msg['pubsub_event']['items']['node'] = 'cheese' msg['pubsub_event']['items']['node'] = 'cheese'
msg['type'] = 'normal' msg['type'] = 'normal'
self.checkMessage(msg, """ self.check_message(msg, """
<message type="normal"> <message type="normal">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<items node="cheese"> <items node="cheese">
@ -435,7 +435,7 @@ class TestPubsubStanzas(SleekTest):
msg['pubsub_event']['collection']['associate']['node'] = 'cheese' msg['pubsub_event']['collection']['associate']['node'] = 'cheese'
msg['pubsub_event']['collection']['node'] = 'cheeseburger' msg['pubsub_event']['collection']['node'] = 'cheeseburger'
msg['type'] = 'headline' msg['type'] = 'headline'
self.checkMessage(msg, """ self.check_message(msg, """
<message type="headline"> <message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<collection node="cheeseburger"> <collection node="cheeseburger">
@ -450,7 +450,7 @@ class TestPubsubStanzas(SleekTest):
msg['pubsub_event']['collection']['disassociate']['node'] = 'cheese' msg['pubsub_event']['collection']['disassociate']['node'] = 'cheese'
msg['pubsub_event']['collection']['node'] = 'cheeseburger' msg['pubsub_event']['collection']['node'] = 'cheeseburger'
msg['type'] = 'headline' msg['type'] = 'headline'
self.checkMessage(msg, """ self.check_message(msg, """
<message type="headline"> <message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<collection node="cheeseburger"> <collection node="cheeseburger">
@ -467,7 +467,7 @@ class TestPubsubStanzas(SleekTest):
ftype='text-single', ftype='text-single',
value='This thing is awesome') value='This thing is awesome')
msg['type'] = 'headline' msg['type'] = 'headline'
self.checkMessage(msg, """ self.check_message(msg, """
<message type="headline"> <message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<configuration node="cheese"> <configuration node="cheese">
@ -485,7 +485,7 @@ class TestPubsubStanzas(SleekTest):
msg = self.Message() msg = self.Message()
msg['pubsub_event']['purge']['node'] = 'pickles' msg['pubsub_event']['purge']['node'] = 'pickles'
msg['type'] = 'headline' msg['type'] = 'headline'
self.checkMessage(msg, """ self.check_message(msg, """
<message type="headline"> <message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<purge node="pickles" /> <purge node="pickles" />
@ -501,7 +501,7 @@ class TestPubsubStanzas(SleekTest):
msg['pubsub_event']['subscription']['subscription'] = 'subscribed' msg['pubsub_event']['subscription']['subscription'] = 'subscribed'
msg['pubsub_event']['subscription']['expiry'] = 'presence' msg['pubsub_event']['subscription']['expiry'] = 'presence'
msg['type'] = 'headline' msg['type'] = 'headline'
self.checkMessage(msg, """ self.check_message(msg, """
<message type="headline"> <message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<subscription node="pickles" subid="aabb1122" jid="fritzy@netflint.net/test" subscription="subscribed" expiry="presence" /> <subscription node="pickles" subid="aabb1122" jid="fritzy@netflint.net/test" subscription="subscribed" expiry="presence" />

View file

@ -16,7 +16,7 @@ class TestRosterStanzas(SleekTest):
'name': 'Other User', 'name': 'Other User',
'subscription': 'both', 'subscription': 'both',
'groups': []}}) 'groups': []}})
self.checkIq(iq, """ self.check_iq(iq, """
<iq> <iq>
<query xmlns="jabber:iq:roster"> <query xmlns="jabber:iq:roster">
<item jid="user@example.com" name="User" subscription="both"> <item jid="user@example.com" name="User" subscription="both">
@ -74,7 +74,7 @@ class TestRosterStanzas(SleekTest):
""" """
iq = self.Iq(ET.fromstring(xml_string)) iq = self.Iq(ET.fromstring(xml_string))
del iq['roster']['items'] del iq['roster']['items']
self.checkIq(iq, """ self.check_iq(iq, """
<iq> <iq>
<query xmlns="jabber:iq:roster" /> <query xmlns="jabber:iq:roster" />
</iq> </iq>

View file

@ -8,24 +8,24 @@ class TestStreamTester(SleekTest):
""" """
def tearDown(self): def tearDown(self):
self.streamClose() self.stream_close()
def testClientEcho(self): def testClientEcho(self):
"""Test that we can interact with a ClientXMPP instance.""" """Test that we can interact with a ClientXMPP instance."""
self.streamStart(mode='client') self.stream_start(mode='client')
def echo(msg): def echo(msg):
msg.reply('Thanks for sending: %(body)s' % msg).send() msg.reply('Thanks for sending: %(body)s' % msg).send()
self.xmpp.add_event_handler('message', echo) self.xmpp.add_event_handler('message', echo)
self.streamRecv(""" self.stream_recv("""
<message to="tester@localhost" from="user@localhost"> <message to="tester@localhost" from="user@localhost">
<body>Hi!</body> <body>Hi!</body>
</message> </message>
""") """)
self.streamSendMessage(""" self.stream_send_message("""
<message to="user@localhost"> <message to="user@localhost">
<body>Thanks for sending: Hi!</body> <body>Thanks for sending: Hi!</body>
</message> </message>
@ -33,20 +33,20 @@ class TestStreamTester(SleekTest):
def testComponentEcho(self): def testComponentEcho(self):
"""Test that we can interact with a ComponentXMPP instance.""" """Test that we can interact with a ComponentXMPP instance."""
self.streamStart(mode='component') self.stream_start(mode='component')
def echo(msg): def echo(msg):
msg.reply('Thanks for sending: %(body)s' % msg).send() msg.reply('Thanks for sending: %(body)s' % msg).send()
self.xmpp.add_event_handler('message', echo) self.xmpp.add_event_handler('message', echo)
self.streamRecv(""" self.stream_recv("""
<message to="tester.localhost" from="user@localhost"> <message to="tester.localhost" from="user@localhost">
<body>Hi!</body> <body>Hi!</body>
</message> </message>
""") """)
self.streamSendMessage(""" self.stream_send_message("""
<message to="user@localhost" from="tester.localhost"> <message to="user@localhost" from="tester.localhost">
<body>Thanks for sending: Hi!</body> <body>Thanks for sending: Hi!</body>
</message> </message>
@ -54,7 +54,7 @@ class TestStreamTester(SleekTest):
def testSendStreamHeader(self): def testSendStreamHeader(self):
"""Test that we can check a sent stream header.""" """Test that we can check a sent stream header."""
self.streamStart(mode='client', skip=False) self.stream_start(mode='client', skip=False)
self.streamSendHeader(sto='localhost') self.streamSendHeader(sto='localhost')
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamTester) suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamTester)