Continue registration even if populate_handle account method fails

darcs-hash:20080304210314-86b55-ce83c9932a03e98fab6e795504f75a159051f7f0.gz
This commit is contained in:
David Rousselie
2008-03-04 22:03:14 +01:00
parent e1c2cd070d
commit d3963c669e
2 changed files with 40 additions and 7 deletions

View File

@@ -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"
typ, 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, 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,

View File

@@ -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()