diff --git a/src/jcl/jabber/component.py b/src/jcl/jabber/component.py index 1dc1784..ea09b49 100644 --- a/src/jcl/jabber/component.py +++ b/src/jcl/jabber/component.py @@ -203,7 +203,6 @@ class AccountManager(object): from_jid = _account.user.jid field = None result = [] - model.db_connect() for (field, field_type, field_options, field_post_func, field_default_func) in _account.get_register_fields(): if field is not None: @@ -219,11 +218,13 @@ class AccountManager(object): try: getattr(_account, "populate_handler")() except Exception, exception: - type, value, stack = sys.exc_info() - self.__logger.error("Error in timer thread\n%s\n%s" - % (exception, "".join(traceback.format_exception - (type, value, stack, 5)))) - return self.send_error_from_account(_account, exception) + typ, value, stack = sys.exc_info() + self.__logger.error(\ + "Error in timer thread\n%s\n%s" + % (exception, "".join(traceback.format_exception + (typ, value, stack, 5)))) + result.extend(self.send_error_from_account(_account, + exception)) if first_account: # component subscribe user presence when registering the first @@ -253,7 +254,6 @@ class AccountManager(object): to_jid=from_jid, subject=_account.get_update_message_subject(lang_class), body=_account.get_update_message_body(lang_class))) - model.db_disconnect() return result def update_account(self, diff --git a/src/jcl/jabber/tests/component.py b/src/jcl/jabber/tests/component.py index bf4e2ba..259d523 100644 --- a/src/jcl/jabber/tests/component.py +++ b/src/jcl/jabber/tests/component.py @@ -3133,6 +3133,39 @@ class AccountManager_TestCase(JCLTestCase): self.account_manager.populate_account(account11, Lang.en, x_data, False, False) self.assertTrue(account11.populate_handler_called) + AccountPopulateHandlerMock.dropTable(ifExists=True) + + def test_populate_account_handler_error(self): + self.comp.stream = MockStream() + self.comp.stream_class = MockStream + x_data = Form("submit") + x_data.add_field(name="name", + value="account1", + field_type="text-single") + class AccountPopulateHandlerErrorMock(Account): + def _init(self, *args, **kw): + Account._init(self, *args, **kw) + self.populate_handler_called = False + + def populate_handler(self): + self.populate_handler_called = True + raise Exception() + + AccountPopulateHandlerErrorMock.createTable(ifNotExists=True) + user1 = User(jid="test1@test.com") + account11 = AccountPopulateHandlerErrorMock(\ + user=user1, name="account11", jid="account11@jcl.test.com") + self.assertFalse(account11.populate_handler_called) + result = self.account_manager.populate_account(account11, Lang.en, + x_data, False, False) + self.assertEquals(len(result), 2) + self.assertEquals(result[0].get_type(), "error") + self.assertEquals(result[0].get_from(), "account11@jcl.test.com") + self.assertEquals(result[0].get_to(), "test1@test.com") + self.assertEquals(result[1].get_type(), None) + self.assertEquals(result[1].get_from(), "jcl.test.com") + self.assertEquals(result[1].get_to(), "test1@test.com") + self.assertTrue(account11.populate_handler_called) def suite(): test_suite = unittest.TestSuite()