PresenceAccount creation
darcs-hash:20070116172724-86b55-a944af8b2e75e749c5a6533521352de26dcee39f.gz
This commit is contained in:
@@ -58,12 +58,13 @@ if __name__ == '__main__':
|
||||
lang_suite = unittest.makeSuite(Lang_TestCase, "test")
|
||||
account_module_suite = unittest.makeSuite(AccountModule_TestCase, "test")
|
||||
account_suite = unittest.makeSuite(Account_TestCase, "test")
|
||||
presence_account_suite = unittest.makeSuite(PresenceAccount_TestCase, "test")
|
||||
|
||||
jcl_suite = unittest.TestSuite()
|
||||
# jcl_suite.addTest(FeederComponent_TestCase('test_handle_tick'))
|
||||
# jcl_suite.addTest(JCLComponent_TestCase('test_handle_set_register_new_field_mandatory'))
|
||||
# jcl_suite = unittest.TestSuite((feeder_component_suite))
|
||||
# jcl_suite = unittest.TestSuite((component_suite))
|
||||
# jcl_suite = unittest.TestSuite((presence_account_suite))
|
||||
jcl_suite = unittest.TestSuite((component_suite, \
|
||||
feeder_component_suite, \
|
||||
feeder_suite, \
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
__revision__ = "$Id: account.py,v 1.3 2005/09/18 20:24:07 dax Exp $"
|
||||
|
||||
from sqlobject.main import SQLObject
|
||||
from sqlobject.col import StringCol
|
||||
from sqlobject.inheritance import InheritableSQLObject
|
||||
from sqlobject.col import StringCol, EnumCol, IntCol
|
||||
from sqlobject.dbconnection import ConnectionHub
|
||||
|
||||
from jcl.lang import Lang
|
||||
@@ -63,7 +63,7 @@ def mandatory_field(field_name):
|
||||
# create a hub to attach a per thread connection
|
||||
hub = ConnectionHub()
|
||||
|
||||
class Account(SQLObject):
|
||||
class Account(InheritableSQLObject):
|
||||
"""Base Account class"""
|
||||
_cacheValue = False
|
||||
_connection = hub
|
||||
@@ -114,7 +114,6 @@ class Account(SQLObject):
|
||||
|
||||
status = property(get_status, set_status)
|
||||
|
||||
|
||||
def _get_register_fields(cls):
|
||||
"""Return a list of tuples for X Data Form composition
|
||||
A tuple is composed of:
|
||||
@@ -144,3 +143,45 @@ class Account(SQLObject):
|
||||
def get_update_message_body(self, lang_class):
|
||||
"""Return localized message body for existing account"""
|
||||
return lang_class.new_account_message_body
|
||||
|
||||
class PresenceAccount(Account):
|
||||
DO_NOTHING = 0
|
||||
DO_SOMETHING = 1
|
||||
|
||||
# Should use EnumCol but attribute redefinition is not supported
|
||||
chat_action = IntCol(default = DO_NOTHING)
|
||||
online_action = IntCol(default = DO_NOTHING)
|
||||
away_action = IntCol(default = DO_NOTHING)
|
||||
xa_action = IntCol(default = DO_NOTHING)
|
||||
dnd_action = IntCol(default = DO_NOTHING)
|
||||
offline_action = IntCol(default = DO_NOTHING)
|
||||
|
||||
possibles_actions = [DO_NOTHING, DO_SOMETHING]
|
||||
|
||||
def _get_presence_actions_fields(cls):
|
||||
"""Return a list of tuples for X Data Form composition
|
||||
for actions asociated to a presence state.
|
||||
A tuple is composed of:
|
||||
- presence_state (related to an Account attribut): 'chat_action',
|
||||
'online_action', 'away_action', 'xa_action', 'dnd_action',
|
||||
'offline_action'
|
||||
- possible_actions: list of possibles actions
|
||||
- default_action: one of the possibles actions, 'None' for no default
|
||||
if nothing is selected by the user, Account.DO_NOTHING will be used.
|
||||
"""
|
||||
return {'chat_action': (cls.possibles_actions, \
|
||||
PresenceAccount.DO_SOMETHING), \
|
||||
'online_action': (cls.possibles_actions, \
|
||||
PresenceAccount.DO_SOMETHING), \
|
||||
'away_action': (cls.possibles_actions, \
|
||||
PresenceAccount.DO_NOTHING), \
|
||||
'xa_action': (cls.possibles_actions, \
|
||||
PresenceAccount.DO_NOTHING), \
|
||||
'dnd_action': (cls.possibles_actions, \
|
||||
PresenceAccount.DO_NOTHING), \
|
||||
'offline_action': (cls.possibles_actions, \
|
||||
PresenceAccount.DO_NOTHING)}
|
||||
|
||||
get_presence_actions_fields = classmethod(_get_presence_actions_fields)
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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", \
|
||||
@@ -132,3 +134,45 @@ class Account_TestCase(unittest.TestCase):
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user