summaryrefslogtreecommitdiff
path: root/tests/test_addresses.py
blob: 63d11003eda884bd323506f4e9d25260f33e4877 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from sleektest import *
import sleekxmpp.plugins.xep_0033 as xep_0033


class TestAddresses(SleekTest):

    	def setUp(self):
                registerStanzaPlugin(Message, xep_0033.Addresses)

        def testAddAddress(self):
		"""Testing adding extended stanza address."""
		msg = self.Message()
		msg['addresses'].addAddress(atype='to', jid='to@header1.org')
		self.checkMessage(msg, """
                  <message>
                    <addresses xmlns="http://jabber.org/protocol/address">
                      <address jid="to@header1.org" type="to" />
                    </addresses>
                  </message>
                """)

		msg = self.Message()
		msg['addresses'].addAddress(atype='replyto', 
                                            jid='replyto@header1.org', 
                                            desc='Reply address')
                self.checkMessage(msg, """
                  <message>
                    <addresses xmlns="http://jabber.org/protocol/address">
                      <address jid="replyto@header1.org" type="replyto" desc="Reply address" />
                    </addresses>
                  </message>
                """)

	def testAddAddresses(self):
		"""Testing adding multiple extended stanza addresses."""

		xmlstring = """
                  <message>
                    <addresses xmlns="http://jabber.org/protocol/address">
                      <address jid="replyto@header1.org" type="replyto" desc="Reply address" />
                      <address jid="cc@header2.org" type="cc" />
                      <address jid="bcc@header2.org" type="bcc" />
                    </addresses>
                  </message>
                """

		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.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.checkMessage(msg, xmlstring)

	def testAddURI(self):
		"""Testing adding URI attribute to extended stanza address."""

		msg = self.Message()
		addr = msg['addresses'].addAddress(atype='to', 
                                                   jid='to@header1.org', 
                                                   node='foo')
                self.checkMessage(msg, """
                  <message>
                    <addresses xmlns="http://jabber.org/protocol/address">
                      <address node="foo" jid="to@header1.org" type="to" />
                    </addresses>
                  </message>
                """)

		addr['uri'] = 'mailto:to@header2.org'
		self.checkMessage(msg, """
                  <message>
                    <addresses xmlns="http://jabber.org/protocol/address">
                      <address type="to" uri="mailto:to@header2.org" />
                    </addresses>
                  </message>
                """)

	def testDelivered(self):
		"""Testing delivered attribute of extended stanza addresses."""

		xmlstring = """
                  <message>
                    <addresses xmlns="http://jabber.org/protocol/address">
                      <address %s jid="to@header1.org" type="to" />
                    </addresses>
                  </message>
                """

		msg = self.Message()
		addr = msg['addresses'].addAddress(jid='to@header1.org', atype='to')
		self.checkMessage(msg, xmlstring % '')

		addr['delivered'] = True
		self.checkMessage(msg, xmlstring % 'delivered="true"')

		addr['delivered'] = False
		self.checkMessage(msg, xmlstring % '')


suite = unittest.TestLoader().loadTestsFromTestCase(TestAddresses)