2013-07-26 04:02:26 -07:00
|
|
|
import unittest
|
2014-07-17 05:19:04 -07:00
|
|
|
from slixmpp.test import SlixTest
|
2010-10-07 07:58:13 -07:00
|
|
|
|
2010-07-29 20:55:13 -07:00
|
|
|
|
2014-07-17 05:19:04 -07:00
|
|
|
class TestErrorStanzas(SlixTest):
|
2010-08-05 17:23:07 -07:00
|
|
|
|
2011-05-13 12:28:47 -07:00
|
|
|
def setUp(self):
|
|
|
|
# Ensure that the XEP-0086 plugin has been loaded.
|
|
|
|
self.stream_start()
|
|
|
|
self.stream_close()
|
|
|
|
|
2010-07-29 20:55:13 -07:00
|
|
|
def testSetup(self):
|
|
|
|
"""Test setting initial values in error stanza."""
|
|
|
|
msg = self.Message()
|
|
|
|
msg.enable('error')
|
2010-11-05 11:45:58 -07:00
|
|
|
self.check(msg, """
|
2010-07-29 20:55:13 -07:00
|
|
|
<message type="error">
|
2011-04-08 13:51:24 -07:00
|
|
|
<error type="cancel" code="501">
|
2010-07-29 20:55:13 -07:00
|
|
|
<feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
|
|
|
|
</error>
|
|
|
|
</message>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testCondition(self):
|
|
|
|
"""Test modifying the error condition."""
|
2010-08-05 17:23:07 -07:00
|
|
|
msg = self.Message()
|
2010-07-29 20:55:13 -07:00
|
|
|
msg['error']['condition'] = 'item-not-found'
|
|
|
|
|
2010-11-05 11:45:58 -07:00
|
|
|
self.check(msg, """
|
2010-07-29 20:55:13 -07:00
|
|
|
<message type="error">
|
2011-04-08 13:51:24 -07:00
|
|
|
<error type="cancel" code="404">
|
2010-07-29 20:55:13 -07:00
|
|
|
<item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
|
|
|
|
</error>
|
|
|
|
</message>
|
|
|
|
""")
|
|
|
|
|
2018-10-08 14:25:23 -07:00
|
|
|
self.assertTrue(msg['error']['condition'] == 'item-not-found', "Error condition doesn't match.")
|
2010-07-29 20:55:13 -07:00
|
|
|
|
2010-10-07 16:42:28 -07:00
|
|
|
msg['error']['condition'] = 'resource-constraint'
|
2010-07-29 20:55:13 -07:00
|
|
|
|
2010-11-05 11:45:58 -07:00
|
|
|
self.check(msg, """
|
2010-07-29 20:55:13 -07:00
|
|
|
<message type="error">
|
2011-04-08 13:51:24 -07:00
|
|
|
<error type="wait" code="500">
|
2010-10-07 16:42:28 -07:00
|
|
|
<resource-constraint xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
|
|
|
|
</error>
|
2010-07-29 20:55:13 -07:00
|
|
|
</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'
|
2010-08-05 17:23:07 -07:00
|
|
|
|
2010-07-29 20:55:13 -07:00
|
|
|
del msg['error']['condition']
|
|
|
|
|
2010-11-05 11:45:58 -07:00
|
|
|
self.check(msg, """
|
2010-07-29 20:55:13 -07:00
|
|
|
<message type="error">
|
2011-04-08 13:51:24 -07:00
|
|
|
<error type="wait" code="500">
|
2010-07-29 20:55:13 -07:00
|
|
|
<text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Error!</text>
|
|
|
|
</error>
|
|
|
|
</message>
|
2010-10-07 16:42:28 -07:00
|
|
|
""", use_values=False)
|
2010-07-29 20:55:13 -07:00
|
|
|
|
2010-10-24 16:56:42 -07:00
|
|
|
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']
|
|
|
|
|
2010-11-05 11:45:58 -07:00
|
|
|
self.check(msg, """
|
2010-10-24 16:56:42 -07:00
|
|
|
<message type="error">
|
2011-04-08 13:51:24 -07:00
|
|
|
<error type="wait" code="500">
|
2010-10-24 16:56:42 -07:00
|
|
|
<internal-server-error xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
|
|
|
|
</error>
|
|
|
|
</message>
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
2010-07-29 20:55:13 -07:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestErrorStanzas)
|