3 from slixmpp
.test
import SlixTest
4 from slixmpp
.plugins
.xep_0050
import Command
5 from slixmpp
.xmlstream
import register_stanza_plugin
8 class TestAdHocCommandStanzas(SlixTest
):
11 register_stanza_plugin(Iq
, Command
)
14 """Test using the action attribute."""
17 iq
['command']['node'] = 'foo'
19 iq
['command']['action'] = 'execute'
20 self
.failUnless(iq
['command']['action'] == 'execute')
22 iq
['command']['action'] = 'complete'
23 self
.failUnless(iq
['command']['action'] == 'complete')
25 iq
['command']['action'] = 'cancel'
26 self
.failUnless(iq
['command']['action'] == 'cancel')
28 def testSetActions(self
):
29 """Test setting next actions in a command stanza."""
32 iq
['command']['node'] = 'foo'
33 iq
['command']['actions'] = ['prev', 'next']
36 <iq id="0" type="result">
37 <command xmlns="http://jabber.org/protocol/commands"
47 def testGetActions(self
):
48 """Test retrieving next actions from a command stanza."""
50 iq
['command']['node'] = 'foo'
51 iq
['command']['actions'] = ['prev', 'next']
53 results
= iq
['command']['actions']
54 expected
= set(['prev', 'next'])
55 self
.assertEqual(results
, expected
,
56 "Incorrect next actions: %s" % results
)
58 def testDelActions(self
):
59 """Test removing next actions from a command stanza."""
62 iq
['command']['node'] = 'foo'
63 iq
['command']['actions'] = ['prev', 'next']
65 del iq
['command']['actions']
68 <iq id="0" type="result">
69 <command xmlns="http://jabber.org/protocol/commands"
74 def testAddNote(self
):
75 """Test adding a command note."""
78 iq
['command']['node'] = 'foo'
79 iq
['command'].add_note('Danger!', ntype
='warning')
82 <iq id="0" type="result">
83 <command xmlns="http://jabber.org/protocol/commands"
85 <note type="warning">Danger!</note>
91 """Test using command notes."""
94 iq
['command']['node'] = 'foo'
96 notes
= [('info', 'Interesting...'),
97 ('warning', 'Danger!'),
98 ('error', "I can't let you do that")]
99 iq
['command']['notes'] = notes
101 self
.failUnless(iq
['command']['notes'] == notes
,
102 "Notes don't match: %s %s" % (notes
, iq
['command']['notes']))
105 <iq id="0" type="result">
106 <command xmlns="http://jabber.org/protocol/commands"
108 <note type="info">Interesting...</note>
109 <note type="warning">Danger!</note>
110 <note type="error">I can't let you do that</note>
116 suite
= unittest
.TestLoader().loadTestsFromTestCase(TestAdHocCommandStanzas
)