Continue registration even if populate_handle account method fails
darcs-hash:20080304210314-86b55-ce83c9932a03e98fab6e795504f75a159051f7f0.gz
This commit is contained in:
@@ -203,7 +203,6 @@ class AccountManager(object):
|
|||||||
from_jid = _account.user.jid
|
from_jid = _account.user.jid
|
||||||
field = None
|
field = None
|
||||||
result = []
|
result = []
|
||||||
model.db_connect()
|
|
||||||
for (field, field_type, field_options, field_post_func,
|
for (field, field_type, field_options, field_post_func,
|
||||||
field_default_func) in _account.get_register_fields():
|
field_default_func) in _account.get_register_fields():
|
||||||
if field is not None:
|
if field is not None:
|
||||||
@@ -219,11 +218,13 @@ class AccountManager(object):
|
|||||||
try:
|
try:
|
||||||
getattr(_account, "populate_handler")()
|
getattr(_account, "populate_handler")()
|
||||||
except Exception, exception:
|
except Exception, exception:
|
||||||
type, value, stack = sys.exc_info()
|
typ, value, stack = sys.exc_info()
|
||||||
self.__logger.error("Error in timer thread\n%s\n%s"
|
self.__logger.error(\
|
||||||
|
"Error in timer thread\n%s\n%s"
|
||||||
% (exception, "".join(traceback.format_exception
|
% (exception, "".join(traceback.format_exception
|
||||||
(type, value, stack, 5))))
|
(typ, value, stack, 5))))
|
||||||
return self.send_error_from_account(_account, exception)
|
result.extend(self.send_error_from_account(_account,
|
||||||
|
exception))
|
||||||
|
|
||||||
if first_account:
|
if first_account:
|
||||||
# component subscribe user presence when registering the first
|
# component subscribe user presence when registering the first
|
||||||
@@ -253,7 +254,6 @@ class AccountManager(object):
|
|||||||
to_jid=from_jid,
|
to_jid=from_jid,
|
||||||
subject=_account.get_update_message_subject(lang_class),
|
subject=_account.get_update_message_subject(lang_class),
|
||||||
body=_account.get_update_message_body(lang_class)))
|
body=_account.get_update_message_body(lang_class)))
|
||||||
model.db_disconnect()
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def update_account(self,
|
def update_account(self,
|
||||||
|
|||||||
@@ -3133,6 +3133,39 @@ class AccountManager_TestCase(JCLTestCase):
|
|||||||
self.account_manager.populate_account(account11, Lang.en, x_data,
|
self.account_manager.populate_account(account11, Lang.en, x_data,
|
||||||
False, False)
|
False, False)
|
||||||
self.assertTrue(account11.populate_handler_called)
|
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():
|
def suite():
|
||||||
test_suite = unittest.TestSuite()
|
test_suite = unittest.TestSuite()
|
||||||
|
|||||||
Reference in New Issue
Block a user