summaryrefslogtreecommitdiff
path: root/tests/test_stanza_xep_0050.py
blob: e02e86c3a6b6e6c363c5bca1f67c2c3f8f47a840 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from sleekxmpp import Iq
from sleekxmpp.test import *
from sleekxmpp.plugins.xep_0050 import Command


class TestAdHocCommandStanzas(SleekTest):

    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'
        self.failUnless(iq['command']['action'] == 'execute')

        iq['command']['action'] = 'complete'
        self.failUnless(iq['command']['action'] == 'complete')

        iq['command']['action'] = 'cancel'
        self.failUnless(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 = set(['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

        self.failUnless(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)