diff options
author | Lance stout <lancestout@gmail.com> | 2010-05-31 13:24:14 -0400 |
---|---|---|
committer | Lance stout <lancestout@gmail.com> | 2010-05-31 13:24:14 -0400 |
commit | 629f6e76a9c003ef8befdfdf023f2e5b9eadc718 (patch) | |
tree | 6662bf0a70b2950d72bd2e3f788064f49557ba3c /tests/test_chatstates.py | |
parent | 1e3a6e1b5f06d307295be6b4ccaf75bf2a48399d (diff) | |
download | slixmpp-629f6e76a9c003ef8befdfdf023f2e5b9eadc718.tar.gz slixmpp-629f6e76a9c003ef8befdfdf023f2e5b9eadc718.tar.bz2 slixmpp-629f6e76a9c003ef8befdfdf023f2e5b9eadc718.tar.xz slixmpp-629f6e76a9c003ef8befdfdf023f2e5b9eadc718.zip |
Added implementation and tests for XEP-0085 - Chat State Notifications.
Chat states may be set using:
msg['chat_state'].active()
msg['chat_state'].composing()
msg['chat_state'].gone()
msg['chat_state'].inactive()
msg['chat_state'].paused()
Checking a chat state can be done with either:
msg['chat_state'].getState()
msg['chat_state'].name
When a message with a chat state is receieved, the following events
may occur:
chatstate_active
chatstate_composing
chatstate_gone
chatstate_inactive
chatstate_paused
where the event data is the message stanza. Note that currently these
events are also triggered for messages sent by SleekXMPP, not just those
received.
Diffstat (limited to 'tests/test_chatstates.py')
-rw-r--r-- | tests/test_chatstates.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_chatstates.py b/tests/test_chatstates.py new file mode 100644 index 00000000..8878e318 --- /dev/null +++ b/tests/test_chatstates.py @@ -0,0 +1,47 @@ +import unittest +from xml.etree import cElementTree as ET +from sleekxmpp.xmlstream.matcher.stanzapath import StanzaPath +from . import xmlcompare + +import sleekxmpp.plugins.xep_0085 as cs + +def stanzaPlugin(stanza, plugin): + stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin + stanza.plugin_tag_map["{%s}%s" % (plugin.namespace, plugin.name)] = plugin + +class testchatstates(unittest.TestCase): + + def setUp(self): + self.cs = cs + stanzaPlugin(self.cs.Message, self.cs.Active) + stanzaPlugin(self.cs.Message, self.cs.Composing) + stanzaPlugin(self.cs.Message, self.cs.Gone) + stanzaPlugin(self.cs.Message, self.cs.Inactive) + stanzaPlugin(self.cs.Message, self.cs.Paused) + + def try2Methods(self, xmlstring, msg): + msg2 = self.cs.Message(None, self.cs.ET.fromstring(xmlstring)) + self.failUnless(xmlstring == str(msg) == str(msg2), + "Two methods for creating stanza don't match") + + def testCreateChatState(self): + """Testing creating chat states.""" + xmlstring = """<message><%s xmlns="http://jabber.org/protocol/chatstates" /></message>""" + + msg = self.cs.Message() + msg['chat_state'].active() + self.try2Methods(xmlstring % 'active', msg) + + msg['chat_state'].composing() + self.try2Methods(xmlstring % 'composing', msg) + + msg['chat_state'].gone() + self.try2Methods(xmlstring % 'gone', msg) + + msg['chat_state'].inactive() + self.try2Methods(xmlstring % 'inactive', msg) + + msg['chat_state'].paused() + self.try2Methods(xmlstring % 'paused', msg) + +suite = unittest.TestLoader().loadTestsFromTestCase(testchatstates) |