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