summaryrefslogtreecommitdiff
path: root/tests/test_stanza_xep_0050.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-03-23 23:00:41 -0400
committerLance Stout <lancestout@gmail.com>2011-03-24 09:35:36 -0400
commita3d111be12144d9dea80165d84cd8168714d3d54 (patch)
treec7627d3d8f15837a2b0ada6fb0a3cb8a66f70a28 /tests/test_stanza_xep_0050.py
parent4916a12b6f2515b22b504c650bd97dd4c30c4471 (diff)
downloadslixmpp-a3d111be12144d9dea80165d84cd8168714d3d54.tar.gz
slixmpp-a3d111be12144d9dea80165d84cd8168714d3d54.tar.bz2
slixmpp-a3d111be12144d9dea80165d84cd8168714d3d54.tar.xz
slixmpp-a3d111be12144d9dea80165d84cd8168714d3d54.zip
Added new XEP-0050 implementation.
Backward incompatibility alert! Please see examples/adhoc_provider.py for how to use the new plugin implementation, or the test examples in the files tests/test_stream_xep_0050.py and tests/test_stanza_xep_0050.py. Major changes: - May now have zero-step commands. Useful if a command is intended to be a dynamic status report that doesn't require any user input. - May use payloads other than data forms, such as a completely custom stanza type. - May include multiple payload items, such as multiple data forms, or a form and a custom stanza type. - Includes a command user API for calling adhoc commands on remote agents and managing the workflow. - Added support for note elements. Todo: - Add prev action support. You may use register_plugin('old_0050') to continue using the previous XEP-0050 implementation.
Diffstat (limited to 'tests/test_stanza_xep_0050.py')
-rw-r--r--tests/test_stanza_xep_0050.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/tests/test_stanza_xep_0050.py b/tests/test_stanza_xep_0050.py
new file mode 100644
index 00000000..ae584de4
--- /dev/null
+++ b/tests/test_stanza_xep_0050.py
@@ -0,0 +1,114 @@
+from sleekxmpp import Iq
+from sleekxmpp.test import *
+from sleekxmpp.plugins.xep_0050 import Command
+
+
+class TestAdHocCommandStanzas(SleekTest):
+
+ def setUp(self):
+ register_stanza_plugin(Iq, Command)
+
+ def testAction(self):
+ """Test using the action attribute."""
+ iq = self.Iq()
+ iq['type'] = 'set'
+ iq['command']['node'] = 'foo'
+
+ iq['command']['action'] = 'execute'
+ self.failUnless(iq['command']['action'] == 'execute')
+
+ iq['command']['action'] = 'complete'
+ self.failUnless(iq['command']['action'] == 'complete')
+
+ iq['command']['action'] = 'cancel'
+ self.failUnless(iq['command']['action'] == 'cancel')
+
+ def testSetActions(self):
+ """Test setting next actions in a command stanza."""
+ iq = self.Iq()
+ iq['type'] = 'result'
+ iq['command']['node'] = 'foo'
+ iq['command']['actions'] = ['prev', 'next']
+
+ self.check(iq, """
+ <iq id="0" type="result">
+ <command xmlns="http://jabber.org/protocol/commands"
+ node="foo">
+ <actions>
+ <prev />
+ <next />
+ </actions>
+ </command>
+ </iq>
+ """)
+
+ def testGetActions(self):
+ """Test retrieving next actions from a command stanza."""
+ iq = self.Iq()
+ iq['command']['node'] = 'foo'
+ iq['command']['actions'] = ['prev', 'next']
+
+ results = iq['command']['actions']
+ expected = ['prev', 'next']
+ self.assertEqual(results, expected,
+ "Incorrect next actions: %s" % results)
+
+ def testDelActions(self):
+ """Test removing next actions from a command stanza."""
+ iq = self.Iq()
+ iq['type'] = 'result'
+ iq['command']['node'] = 'foo'
+ iq['command']['actions'] = ['prev', 'next']
+
+ del iq['command']['actions']
+
+ self.check(iq, """
+ <iq id="0" type="result">
+ <command xmlns="http://jabber.org/protocol/commands"
+ node="foo" />
+ </iq>
+ """)
+
+ def testAddNote(self):
+ """Test adding a command note."""
+ iq = self.Iq()
+ iq['type'] = 'result'
+ iq['command']['node'] = 'foo'
+ iq['command'].add_note('Danger!', ntype='warning')
+
+ self.check(iq, """
+ <iq id="0" type="result">
+ <command xmlns="http://jabber.org/protocol/commands"
+ node="foo">
+ <note type="warning">Danger!</note>
+ </command>
+ </iq>
+ """)
+
+ def testNotes(self):
+ """Test using command notes."""
+ iq = self.Iq()
+ iq['type'] = 'result'
+ iq['command']['node'] = 'foo'
+
+ notes = [('info', 'Interesting...'),
+ ('warning', 'Danger!'),
+ ('error', "I can't let you do that")]
+ iq['command']['notes'] = notes
+
+ self.failUnless(iq['command']['notes'] == notes,
+ "Notes don't match: %s %s" % (notes, iq['command']['notes']))
+
+ self.check(iq, """
+ <iq id="0" type="result">
+ <command xmlns="http://jabber.org/protocol/commands"
+ node="foo">
+ <note type="info">Interesting...</note>
+ <note type="warning">Danger!</note>
+ <note type="error">I can't let you do that</note>
+ </command>
+ </iq>
+ """)
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestAdHocCommandStanzas)