2013-07-26 04:02:26 -07:00
|
|
|
import unittest
|
2014-07-17 05:19:04 -07:00
|
|
|
import slixmpp
|
|
|
|
from slixmpp.test import SlixTest
|
2010-08-03 14:30:34 -07:00
|
|
|
|
2014-07-17 05:19:04 -07:00
|
|
|
class TestPresenceStanzas(SlixTest):
|
2010-08-03 14:30:34 -07:00
|
|
|
|
|
|
|
def testPresenceShowRegression(self):
|
|
|
|
"""Regression check presence['type'] = 'dnd' show value working"""
|
|
|
|
p = self.Presence()
|
|
|
|
p['type'] = 'dnd'
|
2010-11-05 11:45:58 -07:00
|
|
|
self.check(p, "<presence><show>dnd</show></presence>")
|
2010-08-03 14:30:34 -07:00
|
|
|
|
|
|
|
def testPresenceType(self):
|
|
|
|
"""Test manipulating presence['type']"""
|
|
|
|
p = self.Presence()
|
|
|
|
p['type'] = 'available'
|
2010-11-05 11:45:58 -07:00
|
|
|
self.check(p, "<presence />")
|
2018-10-08 14:25:23 -07:00
|
|
|
self.assertTrue(p['type'] == 'available',
|
2010-10-17 18:38:22 -07:00
|
|
|
"Incorrect presence['type'] for type 'available': %s" % p['type'])
|
2010-08-03 14:30:34 -07:00
|
|
|
|
|
|
|
for showtype in ['away', 'chat', 'dnd', 'xa']:
|
|
|
|
p['type'] = showtype
|
2010-11-05 11:45:58 -07:00
|
|
|
self.check(p, """
|
2010-08-03 14:30:34 -07:00
|
|
|
<presence><show>%s</show></presence>
|
|
|
|
""" % showtype)
|
2018-10-08 14:25:23 -07:00
|
|
|
self.assertTrue(p['type'] == showtype,
|
2010-08-03 14:30:34 -07:00
|
|
|
"Incorrect presence['type'] for type '%s'" % showtype)
|
|
|
|
|
|
|
|
p['type'] = None
|
2010-11-05 11:45:58 -07:00
|
|
|
self.check(p, "<presence />")
|
2010-08-03 14:30:34 -07:00
|
|
|
|
|
|
|
def testPresenceUnsolicitedOffline(self):
|
|
|
|
"""
|
|
|
|
Unsolicted offline presence does not spawn changed_status
|
|
|
|
or update the roster.
|
|
|
|
"""
|
|
|
|
p = self.Presence()
|
|
|
|
p['type'] = 'unavailable'
|
|
|
|
p['from'] = 'bill@chadmore.com/gmail15af'
|
|
|
|
|
2014-07-17 05:19:04 -07:00
|
|
|
c = slixmpp.ClientXMPP('crap@wherever', 'password')
|
2010-08-03 14:30:34 -07:00
|
|
|
happened = []
|
|
|
|
|
|
|
|
def handlechangedpresence(event):
|
|
|
|
happened.append(True)
|
|
|
|
|
|
|
|
c.add_event_handler("changed_status", handlechangedpresence)
|
2010-10-01 19:24:19 -07:00
|
|
|
c._handle_presence(p)
|
2010-08-03 14:30:34 -07:00
|
|
|
|
2018-10-08 14:25:23 -07:00
|
|
|
self.assertTrue(happened == [],
|
2010-08-03 14:30:34 -07:00
|
|
|
"changed_status event triggered for extra unavailable presence")
|
2010-10-27 05:09:50 -07:00
|
|
|
roster = c.roster['crap@wherever']
|
2018-10-08 14:25:23 -07:00
|
|
|
self.assertTrue(roster['bill@chadmore.com'].resources == {},
|
2010-08-03 14:30:34 -07:00
|
|
|
"Roster updated for superfulous unavailable presence")
|
|
|
|
|
2010-08-03 15:32:53 -07:00
|
|
|
def testNickPlugin(self):
|
|
|
|
"""Test presence/nick/nick stanza."""
|
|
|
|
p = self.Presence()
|
|
|
|
p['nick']['nick'] = 'A nickname!'
|
2010-11-05 11:45:58 -07:00
|
|
|
self.check(p, """
|
2010-08-03 15:32:53 -07:00
|
|
|
<presence>
|
2011-01-19 16:03:02 -08:00
|
|
|
<nick xmlns="http://jabber.org/protocol/nick">A nickname!</nick>
|
2010-08-03 15:32:53 -07:00
|
|
|
</presence>
|
|
|
|
""")
|
|
|
|
|
2010-01-29 02:11:45 -08:00
|
|
|
|
2010-07-19 21:04:34 -07:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestPresenceStanzas)
|