1 from sleekxmpp
import Iq
2 from sleekxmpp
.test
import *
3 from sleekxmpp
.plugins
.xep_0050
import Command
6 class TestAdHocCommandStanzas(SleekTest
):
9 register_stanza_plugin(Iq
, Command
)
12 """Test using the action attribute."""
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."""
30 iq
['command']['node'] = 'foo'
31 iq
['command']['actions'] = ['prev', 'next']
34 <iq id="0" type="result">
35 <command xmlns="http://jabber.org/protocol/commands"
45 def testGetActions(self
):
46 """Test retrieving next actions from a command stanza."""
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."""
60 iq
['command']['node'] = 'foo'
61 iq
['command']['actions'] = ['prev', 'next']
63 del iq
['command']['actions']
66 <iq id="0" type="result">
67 <command xmlns="http://jabber.org/protocol/commands"
72 def testAddNote(self
):
73 """Test adding a command note."""
76 iq
['command']['node'] = 'foo'
77 iq
['command'].add_note('Danger!', ntype
='warning')
80 <iq id="0" type="result">
81 <command xmlns="http://jabber.org/protocol/commands"
83 <note type="warning">Danger!</note>
89 """Test using command notes."""
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']))
103 <iq id="0" type="result">
104 <command xmlns="http://jabber.org/protocol/commands"
106 <note type="info">Interesting...</note>
107 <note type="warning">Danger!</note>
108 <note type="error">I can't let you do that</note>
114 suite
= unittest
.TestLoader().loadTestsFromTestCase(TestAdHocCommandStanzas
)