Add an example for dumping the roster to the command line.
[slixmpp.git] / tests / test_stanza_xep_0050.py
blobae584de4255658c87ff6c7eef8014c900ccdd536
1 from sleekxmpp import Iq
2 from sleekxmpp.test import *
3 from sleekxmpp.plugins.xep_0050 import Command
6 class TestAdHocCommandStanzas(SleekTest):
8 def setUp(self):
9 register_stanza_plugin(Iq, Command)
11 def testAction(self):
12 """Test using the action attribute."""
13 iq = self.Iq()
14 iq['type'] = 'set'
15 iq['command']['node'] = 'foo'
17 iq['command']['action'] = 'execute'
18 self.failUnless(iq['command']['action'] == 'execute')
20 iq['command']['action'] = 'complete'
21 self.failUnless(iq['command']['action'] == 'complete')
23 iq['command']['action'] = 'cancel'
24 self.failUnless(iq['command']['action'] == 'cancel')
26 def testSetActions(self):
27 """Test setting next actions in a command stanza."""
28 iq = self.Iq()
29 iq['type'] = 'result'
30 iq['command']['node'] = 'foo'
31 iq['command']['actions'] = ['prev', 'next']
33 self.check(iq, """
34 <iq id="0" type="result">
35 <command xmlns="http://jabber.org/protocol/commands"
36 node="foo">
37 <actions>
38 <prev />
39 <next />
40 </actions>
41 </command>
42 </iq>
43 """)
45 def testGetActions(self):
46 """Test retrieving next actions from a command stanza."""
47 iq = self.Iq()
48 iq['command']['node'] = 'foo'
49 iq['command']['actions'] = ['prev', 'next']
51 results = iq['command']['actions']
52 expected = ['prev', 'next']
53 self.assertEqual(results, expected,
54 "Incorrect next actions: %s" % results)
56 def testDelActions(self):
57 """Test removing next actions from a command stanza."""
58 iq = self.Iq()
59 iq['type'] = 'result'
60 iq['command']['node'] = 'foo'
61 iq['command']['actions'] = ['prev', 'next']
63 del iq['command']['actions']
65 self.check(iq, """
66 <iq id="0" type="result">
67 <command xmlns="http://jabber.org/protocol/commands"
68 node="foo" />
69 </iq>
70 """)
72 def testAddNote(self):
73 """Test adding a command note."""
74 iq = self.Iq()
75 iq['type'] = 'result'
76 iq['command']['node'] = 'foo'
77 iq['command'].add_note('Danger!', ntype='warning')
79 self.check(iq, """
80 <iq id="0" type="result">
81 <command xmlns="http://jabber.org/protocol/commands"
82 node="foo">
83 <note type="warning">Danger!</note>
84 </command>
85 </iq>
86 """)
88 def testNotes(self):
89 """Test using command notes."""
90 iq = self.Iq()
91 iq['type'] = 'result'
92 iq['command']['node'] = 'foo'
94 notes = [('info', 'Interesting...'),
95 ('warning', 'Danger!'),
96 ('error', "I can't let you do that")]
97 iq['command']['notes'] = notes
99 self.failUnless(iq['command']['notes'] == notes,
100 "Notes don't match: %s %s" % (notes, iq['command']['notes']))
102 self.check(iq, """
103 <iq id="0" type="result">
104 <command xmlns="http://jabber.org/protocol/commands"
105 node="foo">
106 <note type="info">Interesting...</note>
107 <note type="warning">Danger!</note>
108 <note type="error">I can't let you do that</note>
109 </command>
110 </iq>
111 """)
114 suite = unittest.TestLoader().loadTestsFromTestCase(TestAdHocCommandStanzas)