diff options
author | Jacek Konieczny <jajcus@jajcus.net> | 2004-12-31 15:38:28 +0300 |
---|---|---|
committer | Jacek Konieczny <jajcus@jajcus.net> | 2004-12-31 15:38:28 +0300 |
commit | 8e2a57ead3ffcffed0e8e810695d567196a7173d (patch) | |
tree | 8607be6f8496406e68cf8052e9815daace764757 /tests | |
parent | 859477829f0f00e5f4c5b5b1a7874064d2d6e652 (diff) |
- more tests for DiscoItems
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/disco.py | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/tests/disco.py b/tests/disco.py index 17f3166..bae0eb9 100755 --- a/tests/disco.py +++ b/tests/disco.py @@ -4,6 +4,7 @@ import unittest import libxml2 from pyxmpp.jabber import disco +from pyxmpp.jid import JID class TestDiscoInfo(unittest.TestCase): def test_xml_input(self): @@ -16,6 +17,23 @@ class TestDiscoInfo(unittest.TestCase): # def test_xml_output(self): # def test_building(self): + +test_items=[ + (JID("a@b.c"),None,None), + (JID("a@b.c"),"d",None), + (JID("f@b.c"),None,"e"), + (JID("f@b.c"),"d","e"), + ]; +test_items.sort() + +notest_items=[ + (JID("test@example.com"),None), + (JID("test@example.com"),"d"), + (JID("test@example.com"),"test"), + (JID("a@b.c"),"test"), + ]; + + class TestDiscoItems(unittest.TestCase): def test_xml_input(self): xmldata=libxml2.parseFile("data/disco_items_in.xml") @@ -24,10 +42,39 @@ class TestDiscoItems(unittest.TestCase): should_be=file("data/disco_items_in.txt").read() self.failUnlessEqual(txt,should_be) -# def test_xml_input(self): -# def test_xml_output(self): -# def test_building(self): + def build_disco_items(self,node=None): + di=disco.DiscoItems(node) + for jid,node,name in test_items: + di.add_item(jid,node,name) + return di + + def test_xml_output(self): + di=self.build_disco_items() + txt=di.xmlnode.serialize() + should_be=file("data/disco_items_out.xml").read() + self.failUnlessEqual(txt,should_be) + + def test_building(self): + self.build_disco_items() + def test_building_with_node(self): + di=self.build_disco_items("test") + self.failUnlessEqual(di.node(),"test") + + def test_items(self): + di=self.build_disco_items() + actual_items=[(i.jid(),i.node(),i.name()) for i in di.items()] + actual_items.sort() + self.failUnlessEqual(actual_items,test_items) + + def test_has_item(self): + di=self.build_disco_items() + for jid,node,name in test_items: + self.failUnless(di.has_item(jid,node)) + for jid,node in notest_items: + self.failIf(di.has_item(jid,node)) + + def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestDiscoInfo)) |