Add an example for dumping the roster to the command line.
[slixmpp.git] / tests / test_stanza_xep_0033.py
blobec9a53096078af6aeeca8ebbdeb03cd9afbedc47
1 from sleekxmpp.test import *
2 import sleekxmpp.plugins.xep_0033 as xep_0033
5 class TestAddresses(SleekTest):
7 def setUp(self):
8 register_stanza_plugin(Message, xep_0033.Addresses)
10 def testAddAddress(self):
11 """Testing adding extended stanza address."""
12 msg = self.Message()
13 msg['addresses'].addAddress(atype='to', jid='to@header1.org')
14 self.check(msg, """
15 <message>
16 <addresses xmlns="http://jabber.org/protocol/address">
17 <address jid="to@header1.org" type="to" />
18 </addresses>
19 </message>
20 """)
22 msg = self.Message()
23 msg['addresses'].addAddress(atype='replyto',
24 jid='replyto@header1.org',
25 desc='Reply address')
26 self.check(msg, """
27 <message>
28 <addresses xmlns="http://jabber.org/protocol/address">
29 <address jid="replyto@header1.org" type="replyto" desc="Reply address" />
30 </addresses>
31 </message>
32 """)
34 def testAddAddresses(self):
35 """Testing adding multiple extended stanza addresses."""
37 xmlstring = """
38 <message>
39 <addresses xmlns="http://jabber.org/protocol/address">
40 <address jid="replyto@header1.org" type="replyto" desc="Reply address" />
41 <address jid="cc@header2.org" type="cc" />
42 <address jid="bcc@header2.org" type="bcc" />
43 </addresses>
44 </message>
45 """
47 msg = self.Message()
48 msg['addresses'].setAddresses([
49 {'type':'replyto',
50 'jid':'replyto@header1.org',
51 'desc':'Reply address'},
52 {'type':'cc',
53 'jid':'cc@header2.org'},
54 {'type':'bcc',
55 'jid':'bcc@header2.org'}])
56 self.check(msg, xmlstring)
58 msg = self.Message()
59 msg['addresses']['replyto'] = [{'jid':'replyto@header1.org',
60 'desc':'Reply address'}]
61 msg['addresses']['cc'] = [{'jid':'cc@header2.org'}]
62 msg['addresses']['bcc'] = [{'jid':'bcc@header2.org'}]
63 self.check(msg, xmlstring)
65 def testAddURI(self):
66 """Testing adding URI attribute to extended stanza address."""
68 msg = self.Message()
69 addr = msg['addresses'].addAddress(atype='to',
70 jid='to@header1.org',
71 node='foo')
72 self.check(msg, """
73 <message>
74 <addresses xmlns="http://jabber.org/protocol/address">
75 <address node="foo" jid="to@header1.org" type="to" />
76 </addresses>
77 </message>
78 """)
80 addr['uri'] = 'mailto:to@header2.org'
81 self.check(msg, """
82 <message>
83 <addresses xmlns="http://jabber.org/protocol/address">
84 <address type="to" uri="mailto:to@header2.org" />
85 </addresses>
86 </message>
87 """)
89 def testDelivered(self):
90 """Testing delivered attribute of extended stanza addresses."""
92 xmlstring = """
93 <message>
94 <addresses xmlns="http://jabber.org/protocol/address">
95 <address %s jid="to@header1.org" type="to" />
96 </addresses>
97 </message>
98 """
100 msg = self.Message()
101 addr = msg['addresses'].addAddress(jid='to@header1.org', atype='to')
102 self.check(msg, xmlstring % '')
104 addr['delivered'] = True
105 self.check(msg, xmlstring % 'delivered="true"')
107 addr['delivered'] = False
108 self.check(msg, xmlstring % '')
111 suite = unittest.TestLoader().loadTestsFromTestCase(TestAddresses)