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:
David Rousselie
2007-03-25 14:29:36 +02:00
parent 289e1f2c36
commit 0fad164e57
5 changed files with 38 additions and 19 deletions

View File

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

View File

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