slixmpp/tests/test_stanza_xep_0050.py

117 lines
3.5 KiB
Python
Raw Permalink Normal View History

2014-07-17 12:19:04 +00:00
from slixmpp import Iq
2013-07-26 11:02:26 +00:00
import unittest
2014-07-17 12:19:04 +00:00
from slixmpp.test import SlixTest
from slixmpp.plugins.xep_0050 import Command
from slixmpp.xmlstream import register_stanza_plugin
2014-07-17 12:19:04 +00:00
class TestAdHocCommandStanzas(SlixTest):
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'
2018-10-08 21:25:23 +00:00
self.assertTrue(iq['command']['action'] == 'execute')
iq['command']['action'] = 'complete'
2018-10-08 21:25:23 +00:00
self.assertTrue(iq['command']['action'] == 'complete')
iq['command']['action'] = 'cancel'
2018-10-08 21:25:23 +00:00
self.assertTrue(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
2018-10-08 21:25:23 +00:00
self.assertTrue(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)