Move set_register handlers to AccountManager

darcs-hash:20070329160047-86b55-476be92b2db0b0b144a27d44111478b880adfa85.gz
This commit is contained in:
David Rousselie
2007-03-29 18:00:47 +02:00
parent 77eaa91405
commit 863da17c6f
6 changed files with 230 additions and 155 deletions

View File

@@ -867,9 +867,9 @@ class JCLComponent_TestCase(unittest.TestCase):
self.comp.handle_set_register(iq_set)
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
accounts = self.comp.account_classes[0].select(\
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
and self.comp.account_classes[0].q.name == "account1")
accounts = Account.select(\
Account.q.user_jid == "user1@test.com" \
and Account.q.name == "account1")
self.assertEquals(accounts.count(), 1)
_account = accounts[0]
self.assertEquals(_account.user_jid, "user1@test.com")
@@ -911,7 +911,7 @@ class JCLComponent_TestCase(unittest.TestCase):
def test_handle_set_register_new_multiple_types(self):
self.comp.stream = MockStream()
self.comp.stream_class = MockStream
self.comp.account_classes = [ExampleAccount, Example2Account]
self.comp.account_manager.account_classes = (ExampleAccount, Example2Account)
x_data = Form("submit")
x_data.add_field(name = "name", \
value = "account1", \
@@ -924,9 +924,9 @@ class JCLComponent_TestCase(unittest.TestCase):
self.comp.handle_set_register(iq_set)
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
accounts = self.comp.account_classes[1].select(\
self.comp.account_classes[1].q.user_jid == "user1@test.com" \
and self.comp.account_classes[1].q.name == "account1")
accounts = Account.select(\
Account.q.user_jid == "user1@test.com" \
and Account.q.name == "account1")
self.assertEquals(accounts.count(), 1)
_account = accounts[0]
self.assertEquals(_account.user_jid, "user1@test.com")
@@ -968,7 +968,7 @@ class JCLComponent_TestCase(unittest.TestCase):
def test_handle_set_register_new_complex(self):
self.comp.stream = MockStream()
self.comp.stream_class = MockStream
self.comp.account_classes = [ExampleAccount]
self.comp.account_manager.account_classes = (ExampleAccount,)
x_data = Form("submit")
x_data.add_field(name = "name", \
value = "account1", \
@@ -996,9 +996,9 @@ class JCLComponent_TestCase(unittest.TestCase):
self.comp.handle_set_register(iq_set)
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
accounts = self.comp.account_classes[0].select(\
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
and self.comp.account_classes[0].q.name == "account1")
accounts = Account.select(\
Account.q.user_jid == "user1@test.com" \
and Account.q.name == "account1")
self.assertEquals(accounts.count(), 1)
_account = accounts[0]
self.assertEquals(_account.user_jid, "user1@test.com")
@@ -1045,7 +1045,7 @@ class JCLComponent_TestCase(unittest.TestCase):
def test_handle_set_register_new_default_values(self):
self.comp.stream = MockStream()
self.comp.stream_class = MockStream
self.comp.account_classes = [ExampleAccount]
self.comp.account_manager.account_classes = (ExampleAccount,)
x_data = Form("submit")
x_data.add_field(name = "name", \
value = "account1", \
@@ -1061,9 +1061,9 @@ class JCLComponent_TestCase(unittest.TestCase):
self.comp.handle_set_register(iq_set)
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
accounts = self.comp.account_classes[0].select(\
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
and self.comp.account_classes[0].q.name == "account1")
accounts = Account.select(\
Account.q.user_jid == "user1@test.com" \
and Account.q.name == "account1")
self.assertEquals(accounts.count(), 1)
_account = accounts[0]
self.assertEquals(_account.user_jid, "user1@test.com")
@@ -1088,9 +1088,9 @@ class JCLComponent_TestCase(unittest.TestCase):
self.comp.handle_set_register(iq_set)
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
accounts = self.comp.account_classes[0].select(\
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
and self.comp.account_classes[0].q.name == "account1")
accounts = Account.select(\
Account.q.user_jid == "user1@test.com" \
and Account.q.name == "account1")
self.assertEquals(accounts.count(), 0)
del account.hub.threadConnection
@@ -1107,7 +1107,7 @@ class JCLComponent_TestCase(unittest.TestCase):
def test_handle_set_register_new_field_mandatory(self):
self.comp.stream = MockStream()
self.comp.stream_class = MockStream
self.comp.account_classes = [ExampleAccount]
self.comp.account_manager.account_classes = (ExampleAccount,)
x_data = Form("submit")
x_data.add_field(name = "name", \
value = "account1", \
@@ -1120,9 +1120,9 @@ class JCLComponent_TestCase(unittest.TestCase):
self.comp.handle_set_register(iq_set)
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
accounts = self.comp.account_classes[0].select(\
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
and self.comp.account_classes[0].q.name == "account1")
accounts = Account.select(\
Account.q.user_jid == "user1@test.com" \
and Account.q.name == "account1")
self.assertEquals(accounts.count(), 0)
del account.hub.threadConnection
@@ -1140,6 +1140,7 @@ class JCLComponent_TestCase(unittest.TestCase):
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
self.comp.stream = MockStream()
self.comp.stream_class = MockStream
self.comp.account_manager.account_classes = (Example2Account, ExampleAccount)
existing_account = ExampleAccount(user_jid = "user1@test.com", \
name = "account1", \
jid = "account1@jcl.test.com", \
@@ -1178,17 +1179,18 @@ class JCLComponent_TestCase(unittest.TestCase):
field_type = "text-single")
iq_set = Iq(stanza_type = "set", \
from_jid = "user1@test.com", \
to_jid = "jcl.test.com")
to_jid = "account1@jcl.test.com")
query = iq_set.new_query("jabber:iq:register")
x_data.as_xml(query)
self.comp.handle_set_register(iq_set)
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
accounts = self.comp.account_classes[0].select(\
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
and self.comp.account_classes[0].q.name == "account1")
accounts = Account.select(\
Account.q.user_jid == "user1@test.com" \
and Account.q.name == "account1")
self.assertEquals(accounts.count(), 1)
_account = accounts[0]
self.assertEquals(_account.__class__.__name__, "ExampleAccount")
self.assertEquals(_account.user_jid, "user1@test.com")
self.assertEquals(_account.name, "account1")
self.assertEquals(_account.jid, "account1@jcl.test.com")
@@ -1204,7 +1206,7 @@ class JCLComponent_TestCase(unittest.TestCase):
iq_result = stanza_sent[0]
self.assertTrue(isinstance(iq_result, Iq))
self.assertEquals(iq_result.get_node().prop("type"), "result")
self.assertEquals(iq_result.get_from(), "jcl.test.com")
self.assertEquals(iq_result.get_from(), "account1@jcl.test.com")
self.assertEquals(iq_result.get_to(), "user1@test.com")
message = stanza_sent[1]
@@ -1238,11 +1240,11 @@ class JCLComponent_TestCase(unittest.TestCase):
self.comp.handle_set_register(iq_set)
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
accounts = self.comp.account_classes[0].select(\
self.comp.account_classes[0].q.user_jid == "user1@test.com")
accounts = Account.select(\
Account.q.user_jid == "user1@test.com")
self.assertEquals(accounts.count(), 0)
accounts = self.comp.account_classes[0].select(\
self.comp.account_classes[0].q.user_jid == "user2@test.com")
accounts = Account.select(\
Account.q.user_jid == "user2@test.com")
self.assertEquals(accounts.count(), 1)
_account = accounts[0]
self.assertEquals(_account.user_jid, "user2@test.com")
@@ -1773,14 +1775,14 @@ class JCLComponent_TestCase(unittest.TestCase):
self.assertEqual(presence.xpath_eval("@type")[0].get_content(), \
"unsubscribed")
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
self.assertEquals(self.comp.account_classes[0].select(\
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
and self.comp.account_classes[0].q.name == "account11").count(), \
self.assertEquals(Account.select(\
Account.q.user_jid == "user1@test.com" \
and Account.q.name == "account11").count(), \
0)
self.assertEquals(self.comp.account_classes[0].select(\
self.comp.account_classes[0].q.user_jid == "user1@test.com").count(), \
self.assertEquals(Account.select(\
Account.q.user_jid == "user1@test.com").count(), \
1)
self.assertEquals(self.comp.account_classes[0].select().count(), \
self.assertEquals(Account.select().count(), \
2)
del account.hub.threadConnection
@@ -1805,7 +1807,7 @@ class JCLComponent_TestCase(unittest.TestCase):
presence_sent = self.comp.stream.sent
self.assertEqual(len(presence_sent), 0)
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
self.assertEquals(self.comp.account_classes[0].select().count(), \
self.assertEquals(Account.select().count(), \
3)
del account.hub.threadConnection
@@ -1831,7 +1833,7 @@ class JCLComponent_TestCase(unittest.TestCase):
presence_sent = self.comp.stream.sent
self.assertEqual(len(presence_sent), 0)
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
self.assertEquals(self.comp.account_classes[0].select().count(), \
self.assertEquals(Account.select().count(), \
3)
del account.hub.threadConnection

View File

@@ -38,7 +38,7 @@ class ExampleAccount(Account):
test_int = IntCol(default = 42)
def _get_register_fields(cls, real_class = None):
def password_post_func(password, default_func):
def password_post_func(password):
if password is None or password == "":
return None
return password
@@ -47,11 +47,10 @@ class ExampleAccount(Account):
real_class = cls
return Account.get_register_fields(real_class) + \
[("login", "text-single", None, \
lambda field_value, default_func: account.mandatory_field("login", \
field_value, \
default_func), \
lambda field_value, default_func: account.mandatory_field(field_value), \
lambda : ""), \
("password", "text-private", None, password_post_func, \
("password", "text-private", None, \
lambda field_value, default_func: password_post_func(field_value), \
lambda : ""), \
("store_password", "boolean", None, account.default_post_func, \
lambda : True), \

View File

@@ -64,15 +64,15 @@ class AccountModule_TestCase(unittest.TestCase):
def test_mandatory_field_empty(self):
self.assertRaises(FieldError, \
account.mandatory_field, \
"field", "", None)
"")
def test_mandatory_field_none(self):
self.assertRaises(FieldError, \
account.mandatory_field, \
"field", None, None)
None)
def test_mandatory_field_empty(self):
self.assertEquals(account.mandatory_field("field", "value", None), \
self.assertEquals(account.mandatory_field("value"), \
"value")
class Account_TestCase(unittest.TestCase):