make PresenceAccount tests inheritable

darcs-hash:20070513170643-86b55-46d262b56085ce15320bd8bf765b8200bc97e852.gz
This commit is contained in:
David Rousselie
2007-05-13 19:06:43 +02:00
parent 74aa7b02df
commit 140aefdd3c

View File

@@ -214,6 +214,7 @@ class PresenceAccount_TestCase(unittest.TestCase):
name = "account11", \ name = "account11", \
jid = "account11@jcl.test.com") jid = "account11@jcl.test.com")
del account.hub.threadConnection del account.hub.threadConnection
self.account_class = PresenceAccount
def tearDown(self): def tearDown(self):
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
@@ -227,27 +228,32 @@ class PresenceAccount_TestCase(unittest.TestCase):
os.unlink(DB_PATH) os.unlink(DB_PATH)
def test_get_presence_actions_fields(self): def test_get_presence_actions_fields(self):
fields = PresenceAccount.get_presence_actions_fields() fields = self.account_class.get_presence_actions_fields()
self.assertEquals(len(fields), 6)
(possibles_actions, chat_default_action) = fields["chat_action"] (possibles_actions, chat_default_action) = fields["chat_action"]
self.assertEquals(chat_default_action, PresenceAccount.DO_SOMETHING) self.assertEquals(possibles_actions, self.account_class.possibles_actions)
self.assertEquals(possibles_actions, PresenceAccount.possibles_actions)
(possibles_actions, online_default_action) = fields["online_action"] (possibles_actions, online_default_action) = fields["online_action"]
self.assertEquals(online_default_action, PresenceAccount.DO_SOMETHING) self.assertEquals(possibles_actions, self.account_class.possibles_actions)
self.assertEquals(possibles_actions, PresenceAccount.possibles_actions)
def test_possibles_actions(self): def test_possibles_actions(self):
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
for (field_name, \ for (field_name, \
field_type, \ field_type, \
possibles_actions, \ possibles_actions, \
post_func, \ post_func, \
default_func) in self.account.get_register_fields()[1:]: default_func) in self.account_class.get_register_fields()[1:]:
if possibles_actions is not None: if possibles_actions is not None:
for possible_action in possibles_actions: for possible_action in possibles_actions:
self.assertEquals(post_func(possible_action, default_func), self.assertEquals(post_func(possible_action, default_func),
int(possible_action)) int(possible_action))
self.assertTrue(str(default_func()) in possibles_actions) self.assertTrue(str(default_func()) in possibles_actions)
del account.hub.threadConnection else:
try:
post_func("42", default_func)
default_func()
except FieldError, error:
pass
except Exception, exception:
self.fail("Unexcepted exception: " + str(exception))
def suite(): def suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()