Add account handler that is called when after populating it
darcs-hash:20071031155901-86b55-b2db6a5baf178b18050d231f16da3d6a5827e771.gz
This commit is contained in:
@@ -215,6 +215,9 @@ class AccountManager(object):
|
||||
field_post_func(value, field_default_func,
|
||||
unicode(from_jid.bare())))
|
||||
|
||||
if hasattr(_account, "populate_handler"):
|
||||
getattr(_account, "populate_handler")()
|
||||
|
||||
if first_account:
|
||||
# component subscribe user presence when registering the first
|
||||
# account
|
||||
@@ -376,7 +379,7 @@ class AccountManager(object):
|
||||
else:
|
||||
type_label = account_type
|
||||
yield (account_type, type_label)
|
||||
|
||||
|
||||
def get_account_class(self, account_type=None,
|
||||
account_class_name=None):
|
||||
"""Return account class definition from declared classes in
|
||||
@@ -1063,7 +1066,7 @@ class JCLComponent(Component, object):
|
||||
% ("".join(traceback.format_exception
|
||||
(type, value, stack, 5))))
|
||||
return 1
|
||||
|
||||
|
||||
###########################################################################
|
||||
# Utils
|
||||
###########################################################################
|
||||
@@ -1136,7 +1139,7 @@ class JCLComponent(Component, object):
|
||||
def del_welcome_message(self):
|
||||
self.del_config_parameter("component", "welcome_message")
|
||||
|
||||
|
||||
|
||||
###########################################################################
|
||||
# Virtual methods
|
||||
###########################################################################
|
||||
|
||||
@@ -3070,7 +3070,7 @@ class AccountManager_TestCase(JCLTestCase):
|
||||
"localhost",
|
||||
"5347",
|
||||
None)
|
||||
self.account_manager = AccountManager(self.comp)
|
||||
self.account_manager = self.comp.account_manager
|
||||
|
||||
def test_send_presence_all(self):
|
||||
user1 = User(jid="test1@test.com")
|
||||
@@ -3108,6 +3108,31 @@ class AccountManager_TestCase(JCLTestCase):
|
||||
self.assertEquals(result[5].get_to(), "test2@test.com")
|
||||
self.assertEquals(result[5].get_type(), "unavailable")
|
||||
|
||||
def test_populate_account_handler(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 AccountPopulateHandlerMock(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
|
||||
|
||||
AccountPopulateHandlerMock.createTable(ifNotExists=True)
|
||||
user1 = User(jid="test1@test.com")
|
||||
account11 = AccountPopulateHandlerMock(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
self.assertFalse(account11.populate_handler_called)
|
||||
self.account_manager.populate_account(account11, Lang.en, x_data,
|
||||
False, False)
|
||||
self.assertTrue(account11.populate_handler_called)
|
||||
|
||||
def suite():
|
||||
test_suite = unittest.TestSuite()
|
||||
test_suite.addTest(unittest.makeSuite(JCLComponent_TestCase, 'test'))
|
||||
|
||||
Reference in New Issue
Block a user