Rename to slixmpp
[slixmpp.git] / tests / test_stanza_xep_0050.py
blob7272d783600161b9e5347c322392e1a3d10f69ab
1 from slixmpp import Iq
2 import unittest
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):
10 def setUp(self):
11 register_stanza_plugin(Iq, Command)
13 def testAction(self):
14 """Test using the action attribute."""
15 iq = self.Iq()
16 iq['type'] = 'set'
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."""
30 iq = self.Iq()
31 iq['type'] = 'result'
32 iq['command']['node'] = 'foo'
33 iq['command']['actions'] = ['prev', 'next']
35 self.check(iq, """
36 <iq id="0" type="result">
37 <command xmlns="http://jabber.org/protocol/commands"
38 node="foo">
39 <actions>
40 <prev />
41 <next />
42 </actions>
43 </command>
44 </iq>
45 """)
47 def testGetActions(self):
48 """Test retrieving next actions from a command stanza."""
49 iq = self.Iq()
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."""
60 iq = self.Iq()
61 iq['type'] = 'result'
62 iq['command']['node'] = 'foo'
63 iq['command']['actions'] = ['prev', 'next']
65 del iq['command']['actions']
67 self.check(iq, """
68 <iq id="0" type="result">
69 <command xmlns="http://jabber.org/protocol/commands"
70 node="foo" />
71 </iq>
72 """)
74 def testAddNote(self):
75 """Test adding a command note."""
76 iq = self.Iq()
77 iq['type'] = 'result'
78 iq['command']['node'] = 'foo'
79 iq['command'].add_note('Danger!', ntype='warning')
81 self.check(iq, """
82 <iq id="0" type="result">
83 <command xmlns="http://jabber.org/protocol/commands"
84 node="foo">
85 <note type="warning">Danger!</note>
86 </command>
87 </iq>
88 """)
90 def testNotes(self):
91 """Test using command notes."""
92 iq = self.Iq()
93 iq['type'] = 'result'
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']))
104 self.check(iq, """
105 <iq id="0" type="result">
106 <command xmlns="http://jabber.org/protocol/commands"
107 node="foo">
108 <note type="info">Interesting...</note>
109 <note type="warning">Danger!</note>
110 <note type="error">I can't let you do that</note>
111 </command>
112 </iq>
113 """)
116 suite = unittest.TestLoader().loadTestsFromTestCase(TestAdHocCommandStanzas)