2010-10-07 14:58:13 +00:00
|
|
|
from sleekxmpp.test import *
|
|
|
|
|
2010-07-30 03:55:13 +00:00
|
|
|
|
|
|
|
class TestErrorStanzas(SleekTest):
|
2010-08-06 00:23:07 +00:00
|
|
|
|
2010-07-30 03:55:13 +00:00
|
|
|
def testSetup(self):
|
|
|
|
"""Test setting initial values in error stanza."""
|
|
|
|
msg = self.Message()
|
|
|
|
msg.enable('error')
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-07-30 03:55:13 +00:00
|
|
|
<message type="error">
|
2011-04-08 20:51:24 +00:00
|
|
|
<error type="cancel" code="501">
|
2010-07-30 03:55:13 +00:00
|
|
|
<feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
|
|
|
|
</error>
|
|
|
|
</message>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testCondition(self):
|
|
|
|
"""Test modifying the error condition."""
|
2010-08-06 00:23:07 +00:00
|
|
|
msg = self.Message()
|
2010-07-30 03:55:13 +00:00
|
|
|
msg['error']['condition'] = 'item-not-found'
|
|
|
|
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-07-30 03:55:13 +00:00
|
|
|
<message type="error">
|
2011-04-08 20:51:24 +00:00
|
|
|
<error type="cancel" code="404">
|
2010-07-30 03:55:13 +00:00
|
|
|
<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.")
|
|
|
|
|
2010-10-07 23:42:28 +00:00
|
|
|
msg['error']['condition'] = 'resource-constraint'
|
2010-07-30 03:55:13 +00:00
|
|
|
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-07-30 03:55:13 +00:00
|
|
|
<message type="error">
|
2011-04-08 20:51:24 +00:00
|
|
|
<error type="wait" code="500">
|
2010-10-07 23:42:28 +00:00
|
|
|
<resource-constraint xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
|
|
|
|
</error>
|
2010-07-30 03:55:13 +00: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-06 00:23:07 +00:00
|
|
|
|
2010-07-30 03:55:13 +00:00
|
|
|
del msg['error']['condition']
|
|
|
|
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-07-30 03:55:13 +00:00
|
|
|
<message type="error">
|
2011-04-08 20:51:24 +00:00
|
|
|
<error type="wait" code="500">
|
2010-07-30 03:55:13 +00:00
|
|
|
<text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Error!</text>
|
|
|
|
</error>
|
|
|
|
</message>
|
2010-10-07 23:42:28 +00:00
|
|
|
""", use_values=False)
|
2010-07-30 03:55:13 +00:00
|
|
|
|
2010-10-24 23:56:42 +00: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 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-10-24 23:56:42 +00:00
|
|
|
<message type="error">
|
2011-04-08 20:51:24 +00:00
|
|
|
<error type="wait" code="500">
|
2010-10-24 23:56:42 +00:00
|
|
|
<internal-server-error xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
|
|
|
|
</error>
|
|
|
|
</message>
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
2010-07-30 03:55:13 +00:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestErrorStanzas)
|