From 629f6e76a9c003ef8befdfdf023f2e5b9eadc718 Mon Sep 17 00:00:00 2001 From: Lance stout Date: Mon, 31 May 2010 13:24:14 -0400 Subject: 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. --- tests/test_chatstates.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/test_chatstates.py (limited to 'tests/test_chatstates.py') 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 = """<%s xmlns="http://jabber.org/protocol/chatstates" />""" + + 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) -- cgit v1.2.3 From 7f8179d91e4f8ae3d58448e57f2e350ed6269fd0 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Sun, 27 Jun 2010 17:40:06 -0400 Subject: Refactored unit tests for XEP-0030, XEP-0033, and XEP-0085 to use the new SleekTest class. --- tests/test_chatstates.py | 59 +++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) (limited to 'tests/test_chatstates.py') diff --git a/tests/test_chatstates.py b/tests/test_chatstates.py index 8878e318..1e585be4 100644 --- a/tests/test_chatstates.py +++ b/tests/test_chatstates.py @@ -1,47 +1,44 @@ -import unittest -from xml.etree import cElementTree as ET -from sleekxmpp.xmlstream.matcher.stanzapath import StanzaPath -from . import xmlcompare +from sleektest import * +import sleekxmpp.plugins.xep_0085 as xep_0085 -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): +class TestChatStates(SleekTest): 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") + self.stanzaPlugin(Message, xep_0085.Active) + self.stanzaPlugin(Message, xep_0085.Composing) + self.stanzaPlugin(Message, xep_0085.Gone) + self.stanzaPlugin(Message, xep_0085.Inactive) + self.stanzaPlugin(Message, xep_0085.Paused) def testCreateChatState(self): """Testing creating chat states.""" - xmlstring = """<%s xmlns="http://jabber.org/protocol/chatstates" />""" - - msg = self.cs.Message() + + xmlstring = """ + + <%s xmlns="http://jabber.org/protocol/chatstates" /> + + """ + + msg = self.Message() msg['chat_state'].active() - self.try2Methods(xmlstring % 'active', msg) + self.checkMessage(msg, xmlstring % 'active', + use_values=False) msg['chat_state'].composing() - self.try2Methods(xmlstring % 'composing', msg) + self.checkMessage(msg, xmlstring % 'composing', + use_values=False) + msg['chat_state'].gone() - self.try2Methods(xmlstring % 'gone', msg) + self.checkMessage(msg, xmlstring % 'gone', + use_values=False) msg['chat_state'].inactive() - self.try2Methods(xmlstring % 'inactive', msg) + self.checkMessage(msg, xmlstring % 'inactive', + use_values=False) msg['chat_state'].paused() - self.try2Methods(xmlstring % 'paused', msg) + self.checkMessage(msg, xmlstring % 'paused', + use_values=False) -suite = unittest.TestLoader().loadTestsFromTestCase(testchatstates) +suite = unittest.TestLoader().loadTestsFromTestCase(TestChatStates) -- cgit v1.2.3 From d5e42ac0e7282500583bf17f21eb2f944600ce76 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Mon, 19 Jul 2010 13:58:53 -0400 Subject: Condensed all of the stanzaPlugin functions into a single registerStanzaPlugin function. Updated plugins and tests to use new function. --- tests/test_chatstates.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/test_chatstates.py') diff --git a/tests/test_chatstates.py b/tests/test_chatstates.py index 1e585be4..bcacb9e5 100644 --- a/tests/test_chatstates.py +++ b/tests/test_chatstates.py @@ -4,11 +4,11 @@ import sleekxmpp.plugins.xep_0085 as xep_0085 class TestChatStates(SleekTest): def setUp(self): - self.stanzaPlugin(Message, xep_0085.Active) - self.stanzaPlugin(Message, xep_0085.Composing) - self.stanzaPlugin(Message, xep_0085.Gone) - self.stanzaPlugin(Message, xep_0085.Inactive) - self.stanzaPlugin(Message, xep_0085.Paused) + registerStanzaPlugin(Message, xep_0085.Active) + registerStanzaPlugin(Message, xep_0085.Composing) + registerStanzaPlugin(Message, xep_0085.Gone) + registerStanzaPlugin(Message, xep_0085.Inactive) + registerStanzaPlugin(Message, xep_0085.Paused) def testCreateChatState(self): """Testing creating chat states.""" -- cgit v1.2.3 From 58f77d898f82ab108fa17d562a32c68d3ea35306 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 5 Aug 2010 20:23:07 -0400 Subject: Updated tests to use a relative import for SleekTest to please Python3. Fixed some tabs/spaces issues. --- tests/test_chatstates.py | 76 ++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'tests/test_chatstates.py') diff --git a/tests/test_chatstates.py b/tests/test_chatstates.py index bcacb9e5..74359df9 100644 --- a/tests/test_chatstates.py +++ b/tests/test_chatstates.py @@ -1,44 +1,44 @@ -from sleektest import * +from . sleektest import * import sleekxmpp.plugins.xep_0085 as xep_0085 class TestChatStates(SleekTest): - def setUp(self): - registerStanzaPlugin(Message, xep_0085.Active) - registerStanzaPlugin(Message, xep_0085.Composing) - registerStanzaPlugin(Message, xep_0085.Gone) - registerStanzaPlugin(Message, xep_0085.Inactive) - registerStanzaPlugin(Message, xep_0085.Paused) - - def testCreateChatState(self): - """Testing creating chat states.""" - - xmlstring = """ - - <%s xmlns="http://jabber.org/protocol/chatstates" /> - - """ - - msg = self.Message() - msg['chat_state'].active() - self.checkMessage(msg, xmlstring % 'active', - use_values=False) - - msg['chat_state'].composing() - self.checkMessage(msg, xmlstring % 'composing', - use_values=False) - - - msg['chat_state'].gone() - self.checkMessage(msg, xmlstring % 'gone', - use_values=False) - - msg['chat_state'].inactive() - self.checkMessage(msg, xmlstring % 'inactive', - use_values=False) - - msg['chat_state'].paused() - self.checkMessage(msg, xmlstring % 'paused', - use_values=False) + def setUp(self): + registerStanzaPlugin(Message, xep_0085.Active) + registerStanzaPlugin(Message, xep_0085.Composing) + registerStanzaPlugin(Message, xep_0085.Gone) + registerStanzaPlugin(Message, xep_0085.Inactive) + registerStanzaPlugin(Message, xep_0085.Paused) + + def testCreateChatState(self): + """Testing creating chat states.""" + + xmlstring = """ + + <%s xmlns="http://jabber.org/protocol/chatstates" /> + + """ + + msg = self.Message() + msg['chat_state'].active() + self.checkMessage(msg, xmlstring % 'active', + use_values=False) + + msg['chat_state'].composing() + self.checkMessage(msg, xmlstring % 'composing', + use_values=False) + + + msg['chat_state'].gone() + self.checkMessage(msg, xmlstring % 'gone', + use_values=False) + + msg['chat_state'].inactive() + self.checkMessage(msg, xmlstring % 'inactive', + use_values=False) + + msg['chat_state'].paused() + self.checkMessage(msg, xmlstring % 'paused', + use_values=False) suite = unittest.TestLoader().loadTestsFromTestCase(TestChatStates) -- cgit v1.2.3