summaryrefslogtreecommitdiff
path: root/tests/test_addresses.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-06-27 17:40:06 -0400
committerLance Stout <lancestout@gmail.com>2010-06-27 17:47:32 -0400
commit7f8179d91e4f8ae3d58448e57f2e350ed6269fd0 (patch)
tree8bf26ca9b2878896641840b9ce5f1eab89e6482f /tests/test_addresses.py
parent37ada498029c12459e5724ed27db92c828ce2a38 (diff)
downloadslixmpp-7f8179d91e4f8ae3d58448e57f2e350ed6269fd0.tar.gz
slixmpp-7f8179d91e4f8ae3d58448e57f2e350ed6269fd0.tar.bz2
slixmpp-7f8179d91e4f8ae3d58448e57f2e350ed6269fd0.tar.xz
slixmpp-7f8179d91e4f8ae3d58448e57f2e350ed6269fd0.zip
Refactored unit tests for XEP-0030, XEP-0033, and XEP-0085 to use the new SleekTest class.
Diffstat (limited to 'tests/test_addresses.py')
-rw-r--r--tests/test_addresses.py129
1 files changed, 78 insertions, 51 deletions
diff --git a/tests/test_addresses.py b/tests/test_addresses.py
index eb57537a..2718bb19 100644
--- a/tests/test_addresses.py
+++ b/tests/test_addresses.py
@@ -1,83 +1,110 @@
-import unittest
-from xml.etree import cElementTree as ET
-from sleekxmpp.xmlstream.matcher.stanzapath import StanzaPath
-from . import xmlcompare
+from sleektest import *
+import sleekxmpp.plugins.xep_0033 as xep_0033
-import sleekxmpp.plugins.xep_0033 as addr
+class TestAddresses(SleekTest):
-def stanzaPlugin(stanza, plugin):
- stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
- stanza.plugin_tag_map["{%s}%s" % (plugin.namespace, plugin.name)] = plugin
-
-
-class testaddresses(unittest.TestCase):
def setUp(self):
- self.addr = addr
- stanzaPlugin(self.addr.Message, self.addr.Addresses)
-
- def try2Methods(self, xmlstring, msg):
- msg2 = self.addr.Message(None, self.addr.ET.fromstring(xmlstring))
- self.failUnless(xmlstring == str(msg) == str(msg2),
- """Three methods for creating stanza don't match:\n%s\n%s\n%s""" % (xmlstring, str(msg), str(msg2)))
+ self.stanzaPlugin(Message, xep_0033.Addresses)
def testAddAddress(self):
"""Testing adding extended stanza address."""
- xmlstring = """<message><addresses xmlns="http://jabber.org/protocol/address"><address jid="to@header1.org" type="to" /></addresses></message>"""
-
- msg = self.addr.Message()
+ msg = self.Message()
msg['addresses'].addAddress(atype='to', jid='to@header1.org')
- self.try2Methods(xmlstring, msg)
-
- xmlstring = """<message><addresses xmlns="http://jabber.org/protocol/address"><address jid="replyto@header1.org" type="replyto" desc="Reply address" /></addresses></message>"""
-
- msg = self.addr.Message()
- msg['addresses'].addAddress(atype='replyto', jid='replyto@header1.org', desc='Reply address')
- self.try2Methods(xmlstring, msg)
+ self.checkMessage(msg, """
+ <message>
+ <addresses xmlns="http://jabber.org/protocol/address">
+ <address jid="to@header1.org" type="to" />
+ </addresses>
+ </message>
+ """)
+
+ msg = self.Message()
+ msg['addresses'].addAddress(atype='replyto',
+ jid='replyto@header1.org',
+ desc='Reply address')
+ self.checkMessage(msg, """
+ <message>
+ <addresses xmlns="http://jabber.org/protocol/address">
+ <address jid="replyto@header1.org" type="replyto" desc="Reply address" />
+ </addresses>
+ </message>
+ """)
def testAddAddresses(self):
"""Testing adding multiple extended stanza addresses."""
- xmlstring = """<message><addresses xmlns="http://jabber.org/protocol/address"><address jid="replyto@header1.org" type="replyto" desc="Reply address" /><address jid="cc@header2.org" type="cc" /><address jid="bcc@header2.org" type="bcc" /></addresses></message>"""
-
- msg = self.addr.Message()
- msg['addresses'].setAddresses([{'type':'replyto', 'jid':'replyto@header1.org', 'desc':'Reply address'},
- {'type':'cc', 'jid':'cc@header2.org'},
- {'type':'bcc', 'jid':'bcc@header2.org'}])
- self.try2Methods(xmlstring, msg)
-
- msg = self.addr.Message()
- msg['addresses']['replyto'] = [{'jid':'replyto@header1.org', 'desc':'Reply address'}]
+ xmlstring = """
+ <message>
+ <addresses xmlns="http://jabber.org/protocol/address">
+ <address jid="replyto@header1.org" type="replyto" desc="Reply address" />
+ <address jid="cc@header2.org" type="cc" />
+ <address jid="bcc@header2.org" type="bcc" />
+ </addresses>
+ </message>
+ """
+
+ msg = self.Message()
+ msg['addresses'].setAddresses([{'type':'replyto',
+ 'jid':'replyto@header1.org',
+ 'desc':'Reply address'},
+ {'type':'cc',
+ 'jid':'cc@header2.org'},
+ {'type':'bcc',
+ 'jid':'bcc@header2.org'}])
+ self.checkMessage(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.try2Methods(xmlstring, msg)
+ self.checkMessage(msg, xmlstring)
def testAddURI(self):
"""Testing adding URI attribute to extended stanza address."""
- xmlstring = """<message><addresses xmlns="http://jabber.org/protocol/address"><address node="foo" jid="to@header1.org" type="to" /></addresses></message>"""
- msg = self.addr.Message()
- addr = msg['addresses'].addAddress(atype='to', jid='to@header1.org', node='foo')
- self.try2Methods(xmlstring, msg)
+ msg = self.Message()
+ addr = msg['addresses'].addAddress(atype='to',
+ jid='to@header1.org',
+ node='foo')
+ self.checkMessage(msg, """
+ <message>
+ <addresses xmlns="http://jabber.org/protocol/address">
+ <address node="foo" jid="to@header1.org" type="to" />
+ </addresses>
+ </message>
+ """)
- xmlstring = """<message><addresses xmlns="http://jabber.org/protocol/address"><address type="to" uri="mailto:to@header2.org" /></addresses></message>"""
addr['uri'] = 'mailto:to@header2.org'
- self.try2Methods(xmlstring, msg)
+ self.checkMessage(msg, """
+ <message>
+ <addresses xmlns="http://jabber.org/protocol/address">
+ <address type="to" uri="mailto:to@header2.org" />
+ </addresses>
+ </message>
+ """)
def testDelivered(self):
"""Testing delivered attribute of extended stanza addresses."""
- xmlstring = """<message><addresses xmlns="http://jabber.org/protocol/address"><address %sjid="to@header1.org" type="to" /></addresses></message>"""
+ xmlstring = """
+ <message>
+ <addresses xmlns="http://jabber.org/protocol/address">
+ <address %s jid="to@header1.org" type="to" />
+ </addresses>
+ </message>
+ """
- msg = self.addr.Message()
+ msg = self.Message()
addr = msg['addresses'].addAddress(jid='to@header1.org', atype='to')
- self.try2Methods(xmlstring % '', msg)
+ self.checkMessage(msg, xmlstring % '')
addr['delivered'] = True
- self.try2Methods(xmlstring % 'delivered="true" ', msg)
+ self.checkMessage(msg, xmlstring % 'delivered="true"')
addr['delivered'] = False
- self.try2Methods(xmlstring % '', msg)
+ self.checkMessage(msg, xmlstring % '')
-suite = unittest.TestLoader().loadTestsFromTestCase(testaddresses)
+suite = unittest.TestLoader().loadTestsFromTestCase(TestAddresses)