Permalink
Browse files

Add unit tests for the xep_0048 stanzas

  • Loading branch information...
1 parent df99746 commit a4b96ddbc7ed546d0e20249b0f3891db673a743f @mathieui committed Dec 12, 2011
Showing with 99 additions and 0 deletions.
  1. +99 −0 tests/test_stanza_xep_0048.py
@@ -0,0 +1,99 @@
+from sleekxmpp.test import *
+import sleekxmpp.plugins.xep_0048 as xep_0048
+
+NS_STORAGE = 'xmlns="storage:bookmarks"'
+class TestBookmarks(SleekTest):
+
+ def setUp(self):
+ register_stanza_plugin(xep_0048.Storage, xep_0048.URL, iterable=True)
+ register_stanza_plugin(xep_0048.Storage, xep_0048.Conference, iterable=True)
+ register_stanza_plugin(xep_0048.Conference, xep_0048.Nick)
+ register_stanza_plugin(xep_0048.Conference, xep_0048.Password)
+
+ def testCreateNick(self):
+ """Testing creating a <nick/> element."""
+ nick = xep_0048.Nick()
+
+ self.check(nick, '<nick %s />' % NS_STORAGE)
+
+ def testCreatePassword(self):
+ """Testing creating a <password/> element."""
+ password = xep_0048.Password()
+
+ self.check(password, '<password %s />' % NS_STORAGE)
+
+ def testCreateConference(self):
+ """Testing creating a <conference/> element."""
+
+ xmlstring1 = '<conference '+NS_STORAGE+' name="%s" jid="%s"/>'
+ xmlstring2 = '<conference '+NS_STORAGE+' name="%s" jid="%s"><nick>%s</nick></conference>'
+ xmlstring3 = '<conference '+NS_STORAGE+' name="%s" jid="%s"><nick>%s</nick><password>%s</password></conference>'
+ xmlstring4 = '<conference '+NS_STORAGE+' name="%s" jid="%s"><password>%s</password></conference>'
+ xmlstring5 = '<conference '+NS_STORAGE+' name="%s" jid="%s" autojoin="true"/>'
+
+ conf_name = 'test'
+ conf_jid = 'test@conference.example'
+ nick = 'test'
+ pwd = 'pass'
+ conference = xep_0048.Conference()
+ conference['name'] = conf_name
+ conference['jid'] = conf_jid
+
+ self.check(conference, xmlstring1 % (conf_name, conf_jid), use_values=False)
+
+ conference['nick'] = nick
+
+ self.check(conference, xmlstring2 % (conf_name, conf_jid, nick), use_values=False)
+
+ conference['password'] = pwd
+
+ self.check(conference, xmlstring3 % (conf_name, conf_jid, nick, pwd), use_values=False)
+
+ del conference['nick']
+
+ self.check(conference, xmlstring4 % (conf_name, conf_jid, pwd), use_values=False)
+
+ del conference['password']
+
+ self.check(conference, xmlstring1 % (conf_name, conf_jid), use_values=False)
+
+ conference['autojoin'] = 'true'
+
+ self.check(conference, xmlstring5 % (conf_name, conf_jid), use_values=False)
+
+ def testCreateStorage(self):
+ """Testing creating a <storage/> element."""
+
+ storage = xep_0048.Storage()
+
+ self.check(storage, '<storage %s />' % NS_STORAGE)
+
+ def testStorageIter(self):
+ """Test iterating over the substanzas."""
+ storage = xep_0048.Storage()
+ c = xep_0048.Conference()
+ c['name'] = 'test1'
+ c['jid'] = 'test@conference'
+ storage.append(c)
+ c = xep_0048.Conference()
+ c['name'] = 'test2'
+ c['jid'] = 'test@conference2'
+ c['nick'] = 'nick'
+ storage.append(c)
+ c = xep_0048.Conference()
+ c['name'] = 'test3'
+ c['jid'] = 'test@conference3'
+ c['password'] = 'pwd'
+ storage.append(c)
+
+ xmlstring1 = '<conference name="test1" jid="test@conference" %s />' % NS_STORAGE
+ xmlstring2 = '<conference name="test2" jid="test@conference2" %s ><nick>nick</nick></conference>' % NS_STORAGE
+ xmlstring3 = '<conference name="test3" jid="test@conference3" %s ><password>pwd</password></conference>' % NS_STORAGE
+
+ els = [item for item in storage]
+
+ self.check(els[0], xmlstring1, use_values=False)
+ self.check(els[1], xmlstring2, use_values=False)
+ self.check(els[2], xmlstring3, use_values=False)
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestBookmarks)

0 comments on commit a4b96dd

Please sign in to comment.