mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-30 11:09:56 +00:00
Added unit tests for error stanzas. Corrected error in deleting conditions.
This commit is contained in:
parent
a96a046e27
commit
1da3e5b35e
2 changed files with 59 additions and 1 deletions
|
@ -108,7 +108,9 @@ class Error(ElementBase):
|
|||
"""Remove the condition element."""
|
||||
for child in self.xml.getchildren():
|
||||
if "{%s}" % self.condition_ns in child.tag:
|
||||
self.xml.remove(child)
|
||||
tag = child.tag.split('}', 1)[-1]
|
||||
if tag in self.conditions:
|
||||
self.xml.remove(child)
|
||||
return self
|
||||
|
||||
def getText(self):
|
||||
|
|
56
tests/test_errorstanzas.py
Normal file
56
tests/test_errorstanzas.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
from sleektest import *
|
||||
|
||||
class TestErrorStanzas(SleekTest):
|
||||
|
||||
def testSetup(self):
|
||||
"""Test setting initial values in error stanza."""
|
||||
msg = self.Message()
|
||||
msg.enable('error')
|
||||
self.checkMessage(msg, """
|
||||
<message type="error">
|
||||
<error type="cancel">
|
||||
<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.checkMessage(msg, """
|
||||
<message type="error">
|
||||
<error type="cancel">
|
||||
<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.")
|
||||
|
||||
del msg['error']['condition']
|
||||
|
||||
self.checkMessage(msg, """
|
||||
<message type="error">
|
||||
<error type="cancel" />
|
||||
</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.checkMessage(msg, """
|
||||
<message type="error">
|
||||
<error type="cancel">
|
||||
<text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Error!</text>
|
||||
</error>
|
||||
</message>
|
||||
""")
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestErrorStanzas)
|
Loading…
Reference in a new issue