From 1da3e5b35eb59909d4d6903b1c0190a7aad98a30 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 29 Jul 2010 23:55:13 -0400 Subject: Added unit tests for error stanzas. Corrected error in deleting conditions. --- sleekxmpp/stanza/error.py | 4 +++- tests/test_errorstanzas.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/test_errorstanzas.py diff --git a/sleekxmpp/stanza/error.py b/sleekxmpp/stanza/error.py index 3253d9c5..6d18c297 100644 --- a/sleekxmpp/stanza/error.py +++ b/sleekxmpp/stanza/error.py @@ -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): diff --git a/tests/test_errorstanzas.py b/tests/test_errorstanzas.py new file mode 100644 index 00000000..788d6c12 --- /dev/null +++ b/tests/test_errorstanzas.py @@ -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, """ + + + + + + """) + + def testCondition(self): + """Test modifying the error condition.""" + msg = self.Message() + msg['error']['condition'] = 'item-not-found' + + self.checkMessage(msg, """ + + + + + + """) + + self.failUnless(msg['error']['condition'] == 'item-not-found', "Error condition doesn't match.") + + del msg['error']['condition'] + + self.checkMessage(msg, """ + + + + """) + + 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, """ + + + Error! + + + """) + +suite = unittest.TestLoader().loadTestsFromTestCase(TestErrorStanzas) -- cgit v1.2.3