fix send_stanzas when no stanza given

darcs-hash:20070515155703-86b55-e76575f68f0c13fea7de6c7585ad21d12b4c630b.gz
This commit is contained in:
David Rousselie
2007-05-15 17:57:03 +02:00
parent fc7fe41947
commit 205add7991
2 changed files with 20 additions and 3 deletions

View File

@@ -214,8 +214,9 @@ class JCLComponent(Component, object):
def send_stanzas(self, stanzas): def send_stanzas(self, stanzas):
"""Send given stanza list""" """Send given stanza list"""
self.__logger.debug("Sending responses") self.__logger.debug("Sending responses")
for stanza in stanzas: if stanzas is not None:
self.stream.send(stanza) for stanza in stanzas:
self.stream.send(stanza)
def apply_behavior(self, info_query, \ def apply_behavior(self, info_query, \
account_handler, \ account_handler, \
@@ -462,7 +463,7 @@ class JCLComponent(Component, object):
# Utils # Utils
########################################################################### ###########################################################################
def send_error(self, _account, exception): def send_error(self, _account, exception):
"""""" """ """
self.send_stanzas(self.account_manager.send_error(_account, exception)) self.send_stanzas(self.account_manager.send_error(_account, exception))
type, value, stack = sys.exc_info() type, value, stack = sys.exc_info()
# TODO : not checking email here # TODO : not checking email here

View File

@@ -1959,6 +1959,22 @@ class JCLComponent_TestCase(unittest.TestCase):
self.comp.send_error(_account, exception) self.comp.send_error(_account, exception)
self.assertEqual(len(self.comp.stream.sent), 0) self.assertEqual(len(self.comp.stream.sent), 0)
def test_send_stanzas(self):
self.comp.stream = MockStream()
self.comp.stream_class = MockStream
msg1 = Message()
msg2 = Message()
self.comp.send_stanzas([msg1, msg2])
self.assertEquals(len(self.comp.stream.sent), 2)
self.assertEquals(self.comp.stream.sent[0], msg1)
self.assertEquals(self.comp.stream.sent[1], msg2)
def test_send_stanzas_none(self):
self.comp.stream = MockStream()
self.comp.stream_class = MockStream
self.comp.send_stanzas(None)
self.assertEquals(len(self.comp.stream.sent), 0)
def suite(): def suite():
return unittest.makeSuite(JCLComponent_TestCase, 'test') return unittest.makeSuite(JCLComponent_TestCase, 'test')