diff --git a/tests/test_addresses.py b/tests/test_addresses.py
index eb57537..2718bb1 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
-
-import sleekxmpp.plugins.xep_0033 as addr
+from sleektest import *
+import sleekxmpp.plugins.xep_0033 as xep_0033
-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(SleekTest):
-
-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 = """"""
-
- msg = self.addr.Message()
+ msg = self.Message()
msg['addresses'].addAddress(atype='to', jid='to@header1.org')
- self.try2Methods(xmlstring, msg)
+ self.checkMessage(msg, """
+
+
+
+
+
+ """)
- xmlstring = """"""
-
- msg = self.addr.Message()
- msg['addresses'].addAddress(atype='replyto', jid='replyto@header1.org', desc='Reply address')
- self.try2Methods(xmlstring, msg)
+ msg = self.Message()
+ msg['addresses'].addAddress(atype='replyto',
+ jid='replyto@header1.org',
+ desc='Reply address')
+ self.checkMessage(msg, """
+
+
+
+
+
+ """)
def testAddAddresses(self):
"""Testing adding multiple extended stanza addresses."""
- xmlstring = """"""
+ xmlstring = """
+
+
+
+
+
+
+
+ """
- 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.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.addr.Message()
- msg['addresses']['replyto'] = [{'jid':'replyto@header1.org', 'desc':'Reply address'}]
+ 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 = """"""
- 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, """
+
+
+
+
+
+ """)
- xmlstring = """"""
addr['uri'] = 'mailto:to@header2.org'
- self.try2Methods(xmlstring, msg)
+ self.checkMessage(msg, """
+
+
+
+
+
+ """)
def testDelivered(self):
"""Testing delivered attribute of extended stanza addresses."""
- xmlstring = """"""
+ xmlstring = """
+
+
+
+
+
+ """
- 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)
diff --git a/tests/test_chatstates.py b/tests/test_chatstates.py
index 8878e31..1e585be 100644
--- a/tests/test_chatstates.py
+++ b/tests/test_chatstates.py
@@ -1,47 +1,44 @@
-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_0085 as xep_0085
-import sleekxmpp.plugins.xep_0085 as cs
-
-def stanzaPlugin(stanza, plugin):
- stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
- stanza.plugin_tag_map["{%s}%s" % (plugin.namespace, plugin.name)] = plugin
-
-class testchatstates(unittest.TestCase):
+class TestChatStates(SleekTest):
def setUp(self):
- self.cs = cs
- stanzaPlugin(self.cs.Message, self.cs.Active)
- stanzaPlugin(self.cs.Message, self.cs.Composing)
- stanzaPlugin(self.cs.Message, self.cs.Gone)
- stanzaPlugin(self.cs.Message, self.cs.Inactive)
- stanzaPlugin(self.cs.Message, self.cs.Paused)
-
- def try2Methods(self, xmlstring, msg):
- msg2 = self.cs.Message(None, self.cs.ET.fromstring(xmlstring))
- self.failUnless(xmlstring == str(msg) == str(msg2),
- "Two methods for creating stanza don't match")
+ self.stanzaPlugin(Message, xep_0085.Active)
+ self.stanzaPlugin(Message, xep_0085.Composing)
+ self.stanzaPlugin(Message, xep_0085.Gone)
+ self.stanzaPlugin(Message, xep_0085.Inactive)
+ self.stanzaPlugin(Message, xep_0085.Paused)
def testCreateChatState(self):
"""Testing creating chat states."""
- xmlstring = """<%s xmlns="http://jabber.org/protocol/chatstates" />"""
+
+ xmlstring = """
+
+ <%s xmlns="http://jabber.org/protocol/chatstates" />
+
+ """
- msg = self.cs.Message()
+ msg = self.Message()
msg['chat_state'].active()
- self.try2Methods(xmlstring % 'active', msg)
+ self.checkMessage(msg, xmlstring % 'active',
+ use_values=False)
msg['chat_state'].composing()
- self.try2Methods(xmlstring % 'composing', msg)
+ self.checkMessage(msg, xmlstring % 'composing',
+ use_values=False)
+
msg['chat_state'].gone()
- self.try2Methods(xmlstring % 'gone', msg)
+ self.checkMessage(msg, xmlstring % 'gone',
+ use_values=False)
msg['chat_state'].inactive()
- self.try2Methods(xmlstring % 'inactive', msg)
+ self.checkMessage(msg, xmlstring % 'inactive',
+ use_values=False)
msg['chat_state'].paused()
- self.try2Methods(xmlstring % 'paused', msg)
+ self.checkMessage(msg, xmlstring % 'paused',
+ use_values=False)
-suite = unittest.TestLoader().loadTestsFromTestCase(testchatstates)
+suite = unittest.TestLoader().loadTestsFromTestCase(TestChatStates)
diff --git a/tests/test_disco.py b/tests/test_disco.py
index bbe285a..6daad13 100644
--- a/tests/test_disco.py
+++ b/tests/test_disco.py
@@ -1,96 +1,118 @@
-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_0030 as xep_0030
-import sleekxmpp.plugins.xep_0030 as sd
-def stanzaPlugin(stanza, plugin):
- stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
- stanza.plugin_tag_map["{%s}%s" % (plugin.namespace, plugin.name)] = plugin
-
-class testdisco(unittest.TestCase):
+class TestDisco(SleekTest):
def setUp(self):
- self.sd = sd
- stanzaPlugin(self.sd.Iq, self.sd.DiscoInfo)
- stanzaPlugin(self.sd.Iq, self.sd.DiscoItems)
-
- def try3Methods(self, xmlstring, iq):
- iq2 = self.sd.Iq(None, self.sd.ET.fromstring(xmlstring))
- values = iq2.getValues()
- iq3 = self.sd.Iq()
- iq3.setValues(values)
- self.failUnless(xmlstring == str(iq) == str(iq2) == str(iq3), str(iq)+"3 methods for creating stanza don't match")
+ self.stanzaPlugin(Iq, xep_0030.DiscoInfo)
+ self.stanzaPlugin(Iq, xep_0030.DiscoItems)
def testCreateInfoQueryNoNode(self):
"""Testing disco#info query with no node."""
- iq = self.sd.Iq()
+ iq = self.Iq()
iq['id'] = "0"
iq['disco_info']['node'] = ''
- xmlstring = """"""
- self.try3Methods(xmlstring, iq)
+
+ self.checkIq(iq, """
+
+
+
+ """)
def testCreateInfoQueryWithNode(self):
"""Testing disco#info query with a node."""
- iq = self.sd.Iq()
+ iq = self.Iq()
iq['id'] = "0"
iq['disco_info']['node'] = 'foo'
- xmlstring = """"""
- self.try3Methods(xmlstring, iq)
+
+ self.checkIq(iq, """
+
+
+
+ """)
def testCreateInfoQueryNoNode(self):
"""Testing disco#items query with no node."""
- iq = self.sd.Iq()
+ iq = self.Iq()
iq['id'] = "0"
iq['disco_items']['node'] = ''
- xmlstring = """"""
- self.try3Methods(xmlstring, iq)
+
+ self.checkIq(iq, """
+
+
+
+ """)
def testCreateItemsQueryWithNode(self):
"""Testing disco#items query with a node."""
- iq = self.sd.Iq()
+ iq = self.Iq()
iq['id'] = "0"
iq['disco_items']['node'] = 'foo'
- xmlstring = """"""
- self.try3Methods(xmlstring, iq)
+
+ self.checkIq(iq, """
+
+
+
+ """)
def testInfoIdentities(self):
"""Testing adding identities to disco#info."""
- iq = self.sd.Iq()
+ iq = self.Iq()
iq['id'] = "0"
iq['disco_info']['node'] = 'foo'
iq['disco_info'].addIdentity('conference', 'text', 'Chatroom')
- xmlstring = """"""
- self.try3Methods(xmlstring, iq)
+
+ self.checkIq(iq, """
+
+
+
+
+
+ """)
def testInfoFeatures(self):
"""Testing adding features to disco#info."""
- iq = self.sd.Iq()
+ iq = self.Iq()
iq['id'] = "0"
iq['disco_info']['node'] = 'foo'
iq['disco_info'].addFeature('foo')
iq['disco_info'].addFeature('bar')
- xmlstring = """"""
- self.try3Methods(xmlstring, iq)
+
+ self.checkIq(iq, """
+
+
+
+
+
+
+ """)
def testItems(self):
"""Testing adding features to disco#info."""
- iq = self.sd.Iq()
+ iq = self.Iq()
iq['id'] = "0"
iq['disco_items']['node'] = 'foo'
iq['disco_items'].addItem('user@localhost')
iq['disco_items'].addItem('user@localhost', 'foo')
iq['disco_items'].addItem('user@localhost', 'bar', 'Testing')
- xmlstring = """ """
- self.try3Methods(xmlstring, iq)
+
+ self.checkIq(iq, """
+
+
+
+
+
+
+
+ """)
def testAddRemoveIdentities(self):
"""Test adding and removing identities to disco#info stanza"""
ids = [('automation', 'commands', 'AdHoc'),
('conference', 'text', 'ChatRoom')]
- info = self.sd.DiscoInfo()
+ info = xep_0030.DiscoInfo()
info.addIdentity(*ids[0])
self.failUnless(info.getIdentities() == [ids[0]])
@@ -110,7 +132,7 @@ class testdisco(unittest.TestCase):
"""Test adding and removing features to disco#info stanza"""
features = ['foo', 'bar', 'baz']
- info = self.sd.DiscoInfo()
+ info = xep_0030.DiscoInfo()
info.addFeature(features[0])
self.failUnless(info.getFeatures() == [features[0]])
@@ -132,7 +154,7 @@ class testdisco(unittest.TestCase):
('user@localhost', 'foo', None),
('user@localhost', 'bar', 'Test')]
- info = self.sd.DiscoItems()
+ info = xep_0030.DiscoItems()
self.failUnless(True, ""+str(items[0]))
info.addItem(*(items[0]))
@@ -151,5 +173,4 @@ class testdisco(unittest.TestCase):
self.failUnless(info.getItems() == [])
-
-suite = unittest.TestLoader().loadTestsFromTestCase(testdisco)
+suite = unittest.TestLoader().loadTestsFromTestCase(TestDisco)