2010-10-07 14:58:13 +00:00
|
|
|
from sleekxmpp.test import *
|
2010-06-27 21:40:06 +00:00
|
|
|
import sleekxmpp.plugins.xep_0033 as xep_0033
|
2010-06-23 03:09:50 +00:00
|
|
|
|
|
|
|
|
2010-06-27 21:40:06 +00:00
|
|
|
class TestAddresses(SleekTest):
|
2010-06-23 03:09:50 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
def setUp(self):
|
2010-10-18 01:38:22 +00:00
|
|
|
register_stanza_plugin(Message, xep_0033.Addresses)
|
2010-08-06 00:23:07 +00:00
|
|
|
|
|
|
|
def testAddAddress(self):
|
|
|
|
"""Testing adding extended stanza address."""
|
|
|
|
msg = self.Message()
|
|
|
|
msg['addresses'].addAddress(atype='to', jid='to@header1.org')
|
2010-10-07 13:22:27 +00:00
|
|
|
self.check_message(msg, """
|
2010-08-06 00:23:07 +00:00
|
|
|
<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')
|
2010-10-07 13:22:27 +00:00
|
|
|
self.check_message(msg, """
|
2010-08-06 00:23:07 +00:00
|
|
|
<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'}])
|
2010-10-07 13:22:27 +00:00
|
|
|
self.check_message(msg, xmlstring)
|
2010-08-06 00:23:07 +00:00
|
|
|
|
|
|
|
msg = self.Message()
|
|
|
|
msg['addresses']['replyto'] = [{'jid':'replyto@header1.org',
|
2010-06-27 21:40:06 +00:00
|
|
|
'desc':'Reply address'}]
|
2010-08-06 00:23:07 +00:00
|
|
|
msg['addresses']['cc'] = [{'jid':'cc@header2.org'}]
|
|
|
|
msg['addresses']['bcc'] = [{'jid':'bcc@header2.org'}]
|
2010-10-07 13:22:27 +00:00
|
|
|
self.check_message(msg, xmlstring)
|
2010-08-06 00:23:07 +00:00
|
|
|
|
|
|
|
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')
|
2010-10-07 13:22:27 +00:00
|
|
|
self.check_message(msg, """
|
2010-08-06 00:23:07 +00:00
|
|
|
<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'
|
2010-10-07 13:22:27 +00:00
|
|
|
self.check_message(msg, """
|
2010-08-06 00:23:07 +00:00
|
|
|
<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')
|
2010-10-07 13:22:27 +00:00
|
|
|
self.check_message(msg, xmlstring % '')
|
2010-08-06 00:23:07 +00:00
|
|
|
|
|
|
|
addr['delivered'] = True
|
2010-10-07 13:22:27 +00:00
|
|
|
self.check_message(msg, xmlstring % 'delivered="true"')
|
2010-08-06 00:23:07 +00:00
|
|
|
|
|
|
|
addr['delivered'] = False
|
2010-10-07 13:22:27 +00:00
|
|
|
self.check_message(msg, xmlstring % '')
|
2010-06-23 03:09:50 +00:00
|
|
|
|
|
|
|
|
2010-06-27 21:40:06 +00:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestAddresses)
|