summaryrefslogtreecommitdiff
path: root/tests/test_stanza_error.py
blob: d95a33ce2fc4c0b9f7c5e7a083240b9cd7113767 (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
import unittest
from sleekxmpp.test import SleekTest


class TestErrorStanzas(SleekTest):

    def setUp(self):
        # Ensure that the XEP-0086 plugin has been loaded.
        self.stream_start()
        self.stream_close()

    def testSetup(self):
        """Test setting initial values in error stanza."""
        msg = self.Message()
        msg.enable('error')
        self.check(msg, """
          <message type="error">
            <error type="cancel" code="501">
              <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
            </error>
          </message>
        """)

    def testCondition(self):
        """Test modifying the error condition."""
        msg = self.Message()
        msg['error']['condition'] = 'item-not-found'

        self.check(msg, """
          <message type="error">
            <error type="cancel" code="404">
              <item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
            </error>
          </message>
        """)

        self.failUnless(msg['error']['condition'] == 'item-not-found', "Error condition doesn't match.")

        msg['error']['condition'] = 'resource-constraint'

        self.check(msg, """
          <message type="error">
            <error type="wait" code="500">
              <resource-constraint xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
            </error>
          </message>
         """)

    def testDelCondition(self):
        """Test that deleting error conditions doesn't remove extra elements."""
        msg = self.Message()
        msg['error']['text'] = 'Error!'
        msg['error']['condition'] = 'internal-server-error'

        del msg['error']['condition']

        self.check(msg, """
          <message type="error">
            <error type="wait" code="500">
              <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Error!</text>
            </error>
          </message>
        """, use_values=False)

    def testDelText(self):
        """Test deleting the text of an error."""
        msg = self.Message()
        msg['error']['test'] = 'Error!'
        msg['error']['condition'] = 'internal-server-error'

        del msg['error']['text']

        self.check(msg, """
          <message type="error">
            <error type="wait" code="500">
              <internal-server-error xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
            </error>
          </message>
        """)


suite = unittest.TestLoader().loadTestsFromTestCase(TestErrorStanzas)