From 205add7991961bcd0888982ef763b00f8cb7e713 Mon Sep 17 00:00:00 2001 From: David Rousselie Date: Tue, 15 May 2007 17:57:03 +0200 Subject: [PATCH] fix send_stanzas when no stanza given darcs-hash:20070515155703-86b55-e76575f68f0c13fea7de6c7585ad21d12b4c630b.gz --- src/jcl/jabber/component.py | 7 ++++--- src/jcl/jabber/tests/component.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/jcl/jabber/component.py b/src/jcl/jabber/component.py index 3d7ad9a..94ed74c 100644 --- a/src/jcl/jabber/component.py +++ b/src/jcl/jabber/component.py @@ -214,8 +214,9 @@ class JCLComponent(Component, object): def send_stanzas(self, stanzas): """Send given stanza list""" self.__logger.debug("Sending responses") - for stanza in stanzas: - self.stream.send(stanza) + if stanzas is not None: + for stanza in stanzas: + self.stream.send(stanza) def apply_behavior(self, info_query, \ account_handler, \ @@ -462,7 +463,7 @@ class JCLComponent(Component, object): # Utils ########################################################################### def send_error(self, _account, exception): - """""" + """ """ self.send_stanzas(self.account_manager.send_error(_account, exception)) type, value, stack = sys.exc_info() # TODO : not checking email here diff --git a/src/jcl/jabber/tests/component.py b/src/jcl/jabber/tests/component.py index bbe3916..e017c76 100644 --- a/src/jcl/jabber/tests/component.py +++ b/src/jcl/jabber/tests/component.py @@ -1959,6 +1959,22 @@ class JCLComponent_TestCase(unittest.TestCase): self.comp.send_error(_account, exception) 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(): return unittest.makeSuite(JCLComponent_TestCase, 'test')