Add account handler that is called when after populating it

darcs-hash:20071031155901-86b55-b2db6a5baf178b18050d231f16da3d6a5827e771.gz
This commit is contained in:
David Rousselie
2007-10-31 16:59:01 +01:00
parent dcf0ad7b90
commit 4be61ae002
2 changed files with 32 additions and 4 deletions

View File

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

View File

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