Correct get_register_fields inheritance usage
PresenceAccount subclasses called PresenceAccount.get_register_fields but the "cls" parameter was always PresenceAccount. Now subclasses pass a "real_class" parameter which contains the class type on which get_register_fields was called. darcs-hash:20070325122936-86b55-fb6db014fbdeaa2fa1a423b935df5e72ffe6a20a.gz
This commit is contained in:
@@ -59,7 +59,7 @@ if __name__ == '__main__':
|
||||
jcl_suite = unittest.TestSuite()
|
||||
# jcl_suite.addTest(FeederComponent_TestCase('test_handle_tick'))
|
||||
# jcl_suite.addTest(JCLComponent_TestCase('test_handle_get_register_exist_complex'))
|
||||
# jcl_suite.addTest(AccountModule_TestCase('test_mandatory_field'))
|
||||
# jcl_suite.addTest(PresenceAccount_TestCase('test_possibles_actions'))
|
||||
# jcl_suite = unittest.TestSuite((account_module_suite))
|
||||
# jcl_suite = unittest.TestSuite((presence_account_suite))
|
||||
|
||||
|
||||
@@ -435,12 +435,11 @@ class JCLComponent(Component, object):
|
||||
_account = new_account_class(user_jid = unicode(base_from_jid), \
|
||||
name = name, \
|
||||
jid = name + u"@" + unicode(self.jid))
|
||||
self.__logger.debug("Account '" + str(name) + "' created: " + str(_account))
|
||||
field = None
|
||||
try:
|
||||
self.__logger.debug("Populating " + str(_account))
|
||||
for (field, field_type, field_options, field_post_func, \
|
||||
field_default_func) in _account.get_register_fields():
|
||||
self.__logger.debug("Testing " + field)
|
||||
if field is not None:
|
||||
if field in x_data:
|
||||
value = x_data[field].value
|
||||
@@ -571,9 +570,11 @@ class JCLComponent(Component, object):
|
||||
accounts = None
|
||||
self.db_connect()
|
||||
if not name:
|
||||
self.__logger.debug("subscribe request on main jid")
|
||||
accounts = self.account_classes[0].select(\
|
||||
self.account_classes[0].q.user_jid == base_from_jid)
|
||||
else:
|
||||
self.__logger.debug("subscribe request on '" + name + "' account")
|
||||
accounts = self.account_classes[0].select(\
|
||||
AND(self.account_classes[0].q.name == name, \
|
||||
self.account_classes[0].q.user_jid == base_from_jid))
|
||||
@@ -581,6 +582,10 @@ class JCLComponent(Component, object):
|
||||
and accounts.count() > 0):
|
||||
presence = stanza.make_accept_response()
|
||||
self.stream.send(presence)
|
||||
else:
|
||||
self.__logger.debug("Account '" + str(name) + "' for user '" + \
|
||||
str(base_from_jid) + "' was not found. " + \
|
||||
"Refusing subscription")
|
||||
self.db_disconnect()
|
||||
return 1
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"""
|
||||
|
||||
__revision__ = "$Id: account.py,v 1.3 2005/09/18 20:24:07 dax Exp $"
|
||||
|
||||
2
|
||||
from sqlobject.inheritance import InheritableSQLObject
|
||||
from sqlobject.col import StringCol, EnumCol, IntCol, BoolCol
|
||||
from sqlobject.dbconnection import ConnectionHub
|
||||
@@ -111,7 +111,7 @@ class Account(InheritableSQLObject):
|
||||
|
||||
status = property(get_status, set_status)
|
||||
|
||||
def _get_register_fields(cls):
|
||||
def _get_register_fields(cls, real_class = None):
|
||||
"""Return a list of tuples for X Data Form composition
|
||||
A tuple is composed of:
|
||||
- field_name: might be the name of one of the class attribut
|
||||
@@ -181,10 +181,10 @@ class PresenceAccount(Account):
|
||||
|
||||
get_presence_actions_fields = classmethod(_get_presence_actions_fields)
|
||||
|
||||
def _get_register_fields(cls):
|
||||
def _get_register_fields(cls, real_class = None):
|
||||
""" See Account._get_register_fields """
|
||||
def get_possibles_actions(presence_action_field):
|
||||
return cls.get_presence_actions_fields()[presence_action_field][0]
|
||||
return real_class.get_presence_actions_fields()[presence_action_field][0]
|
||||
|
||||
def is_action_possible(presence_action_field, action, default_func):
|
||||
if int(action) in get_possibles_actions(presence_action_field):
|
||||
@@ -192,9 +192,11 @@ class PresenceAccount(Account):
|
||||
raise default_func()
|
||||
|
||||
def get_default_presence_action(presence_action_field):
|
||||
return cls.get_presence_actions_fields()[presence_action_field][1]
|
||||
return real_class.get_presence_actions_fields()[presence_action_field][1]
|
||||
|
||||
return Account.get_register_fields() + \
|
||||
if real_class is None:
|
||||
real_class = cls
|
||||
return Account.get_register_fields(real_class) + \
|
||||
[(None, None, None, None, None), \
|
||||
("chat_action", "list-single", \
|
||||
[str(action) for action in get_possibles_actions("chat_action")], \
|
||||
|
||||
@@ -37,13 +37,15 @@ class ExampleAccount(Account):
|
||||
test_enum = EnumCol(default = "choice1", enumValues = ["choice1", "choice2", "choice3"])
|
||||
test_int = IntCol(default = 42)
|
||||
|
||||
def _get_register_fields(cls):
|
||||
def _get_register_fields(cls, real_class = None):
|
||||
def password_post_func(password, default_func):
|
||||
if password is None or password == "":
|
||||
return None
|
||||
return password
|
||||
|
||||
return Account.get_register_fields() + \
|
||||
if real_class is None:
|
||||
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, \
|
||||
@@ -64,8 +66,10 @@ class ExampleAccount(Account):
|
||||
class Example2Account(Account):
|
||||
test_new_int = IntCol(default = 42)
|
||||
|
||||
def _get_register_fields(cls):
|
||||
return Account.get_register_fields() + \
|
||||
def _get_register_fields(cls, real_class = None):
|
||||
if real_class is None:
|
||||
real_class = cls
|
||||
return Account.get_register_fields(real_class) + \
|
||||
[("test_new_int", "text-single", None, account.int_post_func, \
|
||||
lambda : 43)]
|
||||
get_register_fields = classmethod(_get_register_fields)
|
||||
@@ -94,3 +98,12 @@ class PresenceAccountExample(PresenceAccount):
|
||||
|
||||
get_presence_actions_fields = classmethod(_get_presence_actions_fields)
|
||||
|
||||
test_new_int = IntCol(default = 42)
|
||||
|
||||
def _get_register_fields(cls, real_class = None):
|
||||
if real_class is None:
|
||||
real_class = cls
|
||||
return PresenceAccount.get_register_fields(real_class) + \
|
||||
[("test_new_int", "text-single", None, account.int_post_func, \
|
||||
lambda : 43)]
|
||||
get_register_fields = classmethod(_get_register_fields)
|
||||
|
||||
@@ -162,10 +162,9 @@ class PresenceAccount_TestCase(unittest.TestCase):
|
||||
possibles_actions, \
|
||||
post_func, \
|
||||
default_func) in account11.get_register_fields()[1:]:
|
||||
for possible_action in possibles_actions:
|
||||
self.assertEquals(post_func(possible_action, default_func),
|
||||
int(possible_action))
|
||||
self.assertTrue(str(default_func()) in possibles_actions)
|
||||
if possibles_actions is not None:
|
||||
for possible_action in possibles_actions:
|
||||
self.assertEquals(post_func(possible_action, default_func),
|
||||
int(possible_action))
|
||||
self.assertTrue(str(default_func()) in possibles_actions)
|
||||
del account.hub.threadConnection
|
||||
|
||||
#TODO: test get_register_field with cls.possible_actions inheritance
|
||||
|
||||
Reference in New Issue
Block a user