PresenceAccount creation

darcs-hash:20070116172724-86b55-a944af8b2e75e749c5a6533521352de26dcee39f.gz
This commit is contained in:
David Rousselie
2007-01-16 18:27:24 +01:00
parent 9a2da0eeff
commit 51334ed5f7
4 changed files with 121 additions and 12 deletions

View File

@@ -26,7 +26,7 @@ from sqlobject.col import StringCol, BoolCol, EnumCol, IntCol
from jcl.lang import Lang
from jcl.model import account
from jcl.model.account import Account
from jcl.model.account import Account, PresenceAccount
class AccountExample(Account):
login = StringCol(default = "")
@@ -55,3 +55,26 @@ class AccountExample(Account):
lambda field_name: 44)]
get_register_fields = classmethod(_get_register_fields)
class PresenceAccountExample(PresenceAccount):
DO_SOMETHING_ELSE = 2
possibles_actions = [DO_SOMETHING_ELSE]
def _get_presence_actions_fields(cls):
"""See PresenceAccount._get_presence_actions_fields
"""
return {'chat_action': (cls.possibles_actions, \
PresenceAccountExample.DO_SOMETHING_ELSE), \
'online_action': (cls.possibles_actions, \
PresenceAccountExample.DO_SOMETHING_ELSE), \
'away_action': (cls.possibles_actions, \
PresenceAccountExample.DO_SOMETHING_ELSE), \
'xa_action': (cls.possibles_actions, \
PresenceAccountExample.DO_SOMETHING_ELSE), \
'dnd_action': (cls.possibles_actions, \
PresenceAccountExample.DO_SOMETHING_ELSE), \
'offline_action': (cls.possibles_actions, \
PresenceAccountExample.DO_SOMETHING_ELSE)}
get_presence_actions_fields = classmethod(_get_presence_actions_fields)

View File

@@ -29,9 +29,9 @@ from sqlobject.dbconnection import TheURIOpener
from jcl.jabber.error import FieldError
from jcl.model import account
from jcl.model.account import Account
from jcl.model.account import Account, PresenceAccount
from tests.jcl.model.account import AccountExample
from tests.jcl.model.account import AccountExample, PresenceAccountExample
DB_PATH = "/tmp/test.db"
DB_URL = DB_PATH# + "?debug=1&debugThreading=1"
@@ -92,6 +92,10 @@ class Account_TestCase(unittest.TestCase):
def setUp(self):
if os.path.exists(DB_PATH):
os.unlink(DB_PATH)
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
Account.createTable(ifNotExists = True)
AccountExample.createTable(ifNotExists = True)
del account.hub.threadConnection
def tearDown(self):
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
@@ -105,7 +109,6 @@ class Account_TestCase(unittest.TestCase):
def test_set_status(self):
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
Account.createTable(ifNotExists = True)
account11 = Account(user_jid = "test1@test.com", \
name = "account11", \
jid = "account11@jcl.test.com")
@@ -116,7 +119,6 @@ class Account_TestCase(unittest.TestCase):
def test_set_status_live_password(self):
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
AccountExample.createTable(ifNotExists = True)
account11 = AccountExample(user_jid = "test1@test.com", \
name = "account11", \
jid = "account11@jcl.test.com", \
@@ -131,4 +133,46 @@ class Account_TestCase(unittest.TestCase):
self.assertEquals(account11.waiting_password_reply, False)
self.assertEquals(account11.password, None)
del account.hub.threadConnection
class PresenceAccount_TestCase(unittest.TestCase):
def setUp(self):
if os.path.exists(DB_PATH):
os.unlink(DB_PATH)
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
Account.createTable(ifNotExists = True)
PresenceAccount.createTable(ifNotExists = True)
PresenceAccountExample.createTable(ifNotExists = True)
del account.hub.threadConnection
def tearDown(self):
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
PresenceAccountExample.dropTable(ifExists = True)
PresenceAccount.dropTable(ifExists = True)
Account.dropTable(ifExists = True)
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
account.hub.threadConnection.close()
del account.hub.threadConnection
if os.path.exists(DB_PATH):
os.unlink(DB_PATH)
def test_get_presence_actions_fields(self):
fields = PresenceAccount.get_presence_actions_fields()
(possibles_actions, chat_default_action) = fields["chat_action"]
self.assertEquals(chat_default_action, PresenceAccount.DO_SOMETHING)
self.assertEquals(possibles_actions, PresenceAccount.possibles_actions)
(possibles_actions, online_default_action) = fields["online_action"]
self.assertEquals(online_default_action, PresenceAccount.DO_SOMETHING)
self.assertEquals(possibles_actions, PresenceAccount.possibles_actions)
def test_possibles_actions(self):
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
account11 = PresenceAccountExample(\
user_jid = "test1@test.com", \
name = "account11", \
jid = "account11@jcl.test.com")
self.assertEquals(account11.possibles_actions, PresenceAccountExample.possibles_actions)
(possibles_actions, chat_default_action) = account11.get_presence_actions_fields()["chat_action"]
self.assertEquals(chat_default_action, PresenceAccountExample.DO_SOMETHING_ELSE)
self.assertEquals(possibles_actions, PresenceAccountExample.possibles_actions)
del account.hub.threadConnection