1 from sleekxmpp
.test
import *
2 from sleekxmpp
.stanza
.roster
import Roster
5 class TestRosterStanzas(SleekTest
):
7 def testAddItems(self
):
8 """Test adding items to a roster stanza."""
10 iq
['roster'].setItems({
13 'subscription': 'both',
14 'groups': ['Friends', 'Coworkers']},
15 'otheruser@example.com': {
17 'subscription': 'both',
21 <query xmlns="jabber:iq:roster">
22 <item jid="user@example.com" name="User" subscription="both">
23 <group>Friends</group>
24 <group>Coworkers</group>
26 <item jid="otheruser@example.com" name="Other User"
27 subscription="both" />
32 def testGetItems(self
):
33 """Test retrieving items from a roster stanza."""
36 <query xmlns="jabber:iq:roster">
37 <item jid="user@example.com" name="User" subscription="both">
38 <group>Friends</group>
39 <group>Coworkers</group>
41 <item jid="otheruser@example.com" name="Other User"
42 subscription="both" />
46 iq
= self
.Iq(ET
.fromstring(xml_string
))
50 'subscription': 'both',
51 'groups': ['Friends', 'Coworkers']},
52 'otheruser@example.com': {
54 'subscription': 'both',
56 debug
= "Roster items don't match after retrieval."
57 debug
+= "\nReturned: %s" % str(iq
['roster']['items'])
58 debug
+= "\nExpected: %s" % str(expected
)
59 self
.failUnless(iq
['roster']['items'] == expected
, debug
)
61 def testDelItems(self
):
62 """Test clearing items from a roster stanza."""
65 <query xmlns="jabber:iq:roster">
66 <item jid="user@example.com" name="User" subscription="both">
67 <group>Friends</group>
68 <group>Coworkers</group>
70 <item jid="otheruser@example.com" name="Other User"
71 subscription="both" />
75 iq
= self
.Iq(ET
.fromstring(xml_string
))
76 del iq
['roster']['items']
79 <query xmlns="jabber:iq:roster" />
84 suite
= unittest
.TestLoader().loadTestsFromTestCase(TestRosterStanzas
)