Multi account types support (part1)
Introduce factory function to instanciate new account class while registering. Need more work to list accounts types in disco darcs-hash:20070123185508-86b55-1797b5a17f14d9f271775bde3eff3189a61a919f.gz
This commit is contained in:
@@ -63,7 +63,7 @@ if __name__ == '__main__':
|
|||||||
jcl_suite = unittest.TestSuite()
|
jcl_suite = unittest.TestSuite()
|
||||||
# jcl_suite.addTest(FeederComponent_TestCase('test_handle_tick'))
|
# jcl_suite.addTest(FeederComponent_TestCase('test_handle_tick'))
|
||||||
# jcl_suite.addTest(JCLComponent_TestCase('test_handle_set_register_new_field_mandatory'))
|
# jcl_suite.addTest(JCLComponent_TestCase('test_handle_set_register_new_field_mandatory'))
|
||||||
# jcl_suite = unittest.TestSuite((component_suite))
|
# jcl_suite = unittest.TestSuite((feeder_component_suite))
|
||||||
# jcl_suite = unittest.TestSuite((presence_account_suite))
|
# jcl_suite = unittest.TestSuite((presence_account_suite))
|
||||||
jcl_suite = unittest.TestSuite((component_suite, \
|
jcl_suite = unittest.TestSuite((component_suite, \
|
||||||
feeder_component_suite, \
|
feeder_component_suite, \
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ from pyxmpp.presence import Presence
|
|||||||
import jcl
|
import jcl
|
||||||
from jcl.jabber.x import DataForm
|
from jcl.jabber.x import DataForm
|
||||||
from jcl.jabber.error import FieldError
|
from jcl.jabber.error import FieldError
|
||||||
from jcl.model import account
|
from jcl.model import account, default_account_factory
|
||||||
from jcl.model.account import Account
|
from jcl.model.account import Account
|
||||||
from jcl.lang import Lang
|
from jcl.lang import Lang
|
||||||
|
|
||||||
@@ -88,7 +88,8 @@ class JCLComponent(Component, object):
|
|||||||
self.name = "Jabber Component Library generic component"
|
self.name = "Jabber Component Library generic component"
|
||||||
self.spool_dir = "."
|
self.spool_dir = "."
|
||||||
self.db_connection_str = db_connection_str
|
self.db_connection_str = db_connection_str
|
||||||
self.__account_class = None
|
self.default_account_class = Account
|
||||||
|
self.account_factory = default_account_factory.create
|
||||||
self.version = VERSION
|
self.version = VERSION
|
||||||
self.accounts = []
|
self.accounts = []
|
||||||
self.time_unit = 60
|
self.time_unit = 60
|
||||||
@@ -104,27 +105,6 @@ class JCLComponent(Component, object):
|
|||||||
signal.signal(signal.SIGINT, self.signal_handler)
|
signal.signal(signal.SIGINT, self.signal_handler)
|
||||||
signal.signal(signal.SIGTERM, self.signal_handler)
|
signal.signal(signal.SIGTERM, self.signal_handler)
|
||||||
|
|
||||||
def set_account_class(self, account_class):
|
|
||||||
"""account_class attribut setter
|
|
||||||
create associated table via SQLObject"""
|
|
||||||
self.__account_class = account_class
|
|
||||||
self.db_connect()
|
|
||||||
if account_class._inheritable:
|
|
||||||
while account_class != InheritableSQLObject:
|
|
||||||
account_class.createTable(ifNotExists = True)
|
|
||||||
account_class = account_class.__base__
|
|
||||||
else:
|
|
||||||
self.__account_class.createTable(ifNotExists = True)
|
|
||||||
self.db_disconnect()
|
|
||||||
|
|
||||||
def get_account_class(self):
|
|
||||||
"""account_class attribut getter"""
|
|
||||||
if self.__account_class is None:
|
|
||||||
self.set_account_class(Account)
|
|
||||||
return self.__account_class
|
|
||||||
|
|
||||||
account_class = property(get_account_class, set_account_class)
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Main loop
|
"""Main loop
|
||||||
Connect to Jabber server
|
Connect to Jabber server
|
||||||
@@ -159,7 +139,7 @@ class JCLComponent(Component, object):
|
|||||||
# Explicit reference to account table (clauseTables) to use
|
# Explicit reference to account table (clauseTables) to use
|
||||||
# "user_jid" column with Account subclasses
|
# "user_jid" column with Account subclasses
|
||||||
for _account in \
|
for _account in \
|
||||||
self.account_class.select(clauseTables = ["account"], \
|
self.default_account_class.select(clauseTables = ["account"], \
|
||||||
orderBy = "user_jid"):
|
orderBy = "user_jid"):
|
||||||
if current_user_jid != _account.user_jid:
|
if current_user_jid != _account.user_jid:
|
||||||
current_user_jid = _account.user_jid
|
current_user_jid = _account.user_jid
|
||||||
@@ -249,7 +229,7 @@ class JCLComponent(Component, object):
|
|||||||
self.handle_message)
|
self.handle_message)
|
||||||
current_jid = None
|
current_jid = None
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
for _account in self.account_class.select(clauseTables = ["account"], \
|
for _account in self.default_account_class.select(clauseTables = ["account"], \
|
||||||
orderBy = "user_jid"):
|
orderBy = "user_jid"):
|
||||||
if _account.user_jid != current_jid:
|
if _account.user_jid != current_jid:
|
||||||
presence = Presence(from_jid = unicode(self.jid), \
|
presence = Presence(from_jid = unicode(self.jid), \
|
||||||
@@ -288,7 +268,7 @@ class JCLComponent(Component, object):
|
|||||||
disco_items = DiscoItems()
|
disco_items = DiscoItems()
|
||||||
if not node:
|
if not node:
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
for _account in self.account_class.select(Account.q.user_jid == \
|
for _account in self.default_account_class.select(Account.q.user_jid == \
|
||||||
base_from_jid):
|
base_from_jid):
|
||||||
self.__logger.debug(str(_account))
|
self.__logger.debug(str(_account))
|
||||||
DiscoItem(disco_items, \
|
DiscoItem(disco_items, \
|
||||||
@@ -310,24 +290,32 @@ class JCLComponent(Component, object):
|
|||||||
|
|
||||||
def handle_get_register(self, info_query):
|
def handle_get_register(self, info_query):
|
||||||
"""Send back register form to user
|
"""Send back register form to user
|
||||||
|
see node structure in disco_get_items()
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("GET_REGISTER")
|
self.__logger.debug("GET_REGISTER")
|
||||||
lang_class = self.lang.get_lang_class_from_node(info_query.get_node())
|
lang_class = self.lang.get_lang_class_from_node(info_query.get_node())
|
||||||
base_from_jid = unicode(info_query.get_from().bare())
|
base_from_jid = unicode(info_query.get_from().bare())
|
||||||
to_jid = info_query.get_to()
|
to_jid = info_query.get_to()
|
||||||
name = to_jid.node
|
|
||||||
info_query = info_query.make_result_response()
|
info_query = info_query.make_result_response()
|
||||||
query = info_query.new_query("jabber:iq:register")
|
query = info_query.new_query("jabber:iq:register")
|
||||||
if name is not None:
|
if to_jid.node is not None:
|
||||||
|
node_list = to_jid.node.split("/")
|
||||||
|
if (len(node_list) == 2):
|
||||||
|
_account_class = globals()[node_list[0] + "Account"]
|
||||||
|
name = node_list[1]
|
||||||
|
else:
|
||||||
|
_account_class = self.default_account_class
|
||||||
|
name = node_list[0]
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
for _account in self.account_class.select(\
|
for _account in _account_class.select(\
|
||||||
AND(self.account_class.q.name == name, \
|
AND(_account_class.q.name == name, \
|
||||||
self.account_class.q.user_jid == base_from_jid)):
|
_account_class.q.user_jid == base_from_jid)):
|
||||||
self.get_reg_form_init(lang_class, \
|
self.get_reg_form_init(lang_class, \
|
||||||
_account).attach_xml(query)
|
_account).attach_xml(query)
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
else:
|
else:
|
||||||
self.get_reg_form(lang_class).attach_xml(query)
|
self.get_reg_form(lang_class, \
|
||||||
|
self.default_account_class).attach_xml(query)
|
||||||
self.stream.send(info_query)
|
self.stream.send(info_query)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -335,8 +323,8 @@ class JCLComponent(Component, object):
|
|||||||
"""Unsubscribe all accounts associated to 'user_jid' then delete
|
"""Unsubscribe all accounts associated to 'user_jid' then delete
|
||||||
those accounts from the DataBase"""
|
those accounts from the DataBase"""
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
for _account in self.account_class.select(\
|
for _account in self.default_account_class.select(\
|
||||||
self.account_class.q.user_jid == user_jid):
|
self.default_account_class.q.user_jid == user_jid):
|
||||||
self.__logger.debug("Deleting " + _account.name \
|
self.__logger.debug("Deleting " + _account.name \
|
||||||
+ " for " + user_jid)
|
+ " for " + user_jid)
|
||||||
presence = Presence(from_jid = self.get_jid(_account), \
|
presence = Presence(from_jid = self.get_jid(_account), \
|
||||||
@@ -388,12 +376,12 @@ class JCLComponent(Component, object):
|
|||||||
self.stream.send(iq_error)
|
self.stream.send(iq_error)
|
||||||
return
|
return
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
accounts = self.account_class.select(\
|
accounts = self.default_account_class.select(\
|
||||||
AND(self.account_class.q.name == name, \
|
AND(self.default_account_class.q.name == name, \
|
||||||
self.account_class.q.user_jid == base_from_jid))
|
self.default_account_class.q.user_jid == base_from_jid))
|
||||||
accounts_count = accounts.count()
|
accounts_count = accounts.count()
|
||||||
all_accounts = self.account_class.select(\
|
all_accounts = self.default_account_class.select(\
|
||||||
self.account_class.q.user_jid == base_from_jid)
|
self.default_account_class.q.user_jid == base_from_jid)
|
||||||
all_accounts_count = all_accounts.count()
|
all_accounts_count = all_accounts.count()
|
||||||
if accounts_count > 1:
|
if accounts_count > 1:
|
||||||
# Just print a warning, only the first account will be use
|
# Just print a warning, only the first account will be use
|
||||||
@@ -402,13 +390,15 @@ class JCLComponent(Component, object):
|
|||||||
if accounts_count >= 1:
|
if accounts_count >= 1:
|
||||||
_account = list(accounts)[0]
|
_account = list(accounts)[0]
|
||||||
else:
|
else:
|
||||||
_account = self.account_class(user_jid = base_from_jid, \
|
_account = self.account_factory(\
|
||||||
|
user_jid = base_from_jid, \
|
||||||
name = name, \
|
name = name, \
|
||||||
jid = name + u"@"+unicode(self.jid))
|
jid = name + u"@" + unicode(self.jid), \
|
||||||
|
x_data = x_data)
|
||||||
field = None
|
field = None
|
||||||
try:
|
try:
|
||||||
for (field, field_type, field_options, field_post_func, \
|
for (field, field_type, field_options, field_post_func, \
|
||||||
field_default_func) in self.account_class.get_register_fields():
|
field_default_func) in _account.get_register_fields():
|
||||||
setattr(_account, field, \
|
setattr(_account, field, \
|
||||||
x_data.get_field_value(field, \
|
x_data.get_field_value(field, \
|
||||||
field_post_func, \
|
field_post_func, \
|
||||||
@@ -449,6 +439,9 @@ class JCLComponent(Component, object):
|
|||||||
|
|
||||||
def handle_presence_available(self, stanza):
|
def handle_presence_available(self, stanza):
|
||||||
"""Handle presence availability
|
"""Handle presence availability
|
||||||
|
if presence sent to the component ('if not name'), presence is sent to
|
||||||
|
all accounts for current user. Otherwise, send presence from current account.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("PRESENCE_AVAILABLE")
|
self.__logger.debug("PRESENCE_AVAILABLE")
|
||||||
from_jid = stanza.get_from()
|
from_jid = stanza.get_from()
|
||||||
@@ -461,8 +454,8 @@ class JCLComponent(Component, object):
|
|||||||
self.__logger.debug("TO : " + name + " " + base_from_jid)
|
self.__logger.debug("TO : " + name + " " + base_from_jid)
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
if not name:
|
if not name:
|
||||||
accounts = self.account_class.select(\
|
accounts = self.default_account_class.select(\
|
||||||
self.account_class.q.user_jid == base_from_jid)
|
self.default_account_class.q.user_jid == base_from_jid)
|
||||||
accounts_length = 0
|
accounts_length = 0
|
||||||
for _account in accounts:
|
for _account in accounts:
|
||||||
accounts_length += 1
|
accounts_length += 1
|
||||||
@@ -477,9 +470,9 @@ class JCLComponent(Component, object):
|
|||||||
stanza_type = "available")
|
stanza_type = "available")
|
||||||
self.stream.send(presence)
|
self.stream.send(presence)
|
||||||
else:
|
else:
|
||||||
accounts = self.account_class.select(\
|
accounts = self.default_account_class.select(\
|
||||||
AND(self.account_class.q.name == name, \
|
AND(self.default_account_class.q.name == name, \
|
||||||
self.account_class.q.user_jid == base_from_jid))
|
self.default_account_class.q.user_jid == base_from_jid))
|
||||||
if accounts.count() > 0:
|
if accounts.count() > 0:
|
||||||
self._send_presence_available(accounts[0], show, lang_class)
|
self._send_presence_available(accounts[0], show, lang_class)
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
@@ -494,8 +487,8 @@ class JCLComponent(Component, object):
|
|||||||
name = stanza.get_to().node
|
name = stanza.get_to().node
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
if not name:
|
if not name:
|
||||||
accounts = self.account_class.select(\
|
accounts = self.default_account_class.select(\
|
||||||
self.account_class.q.user_jid == base_from_jid)
|
self.default_account_class.q.user_jid == base_from_jid)
|
||||||
for _account in accounts:
|
for _account in accounts:
|
||||||
_account.status = jcl.model.account.OFFLINE
|
_account.status = jcl.model.account.OFFLINE
|
||||||
presence = Presence(from_jid = _account.jid, \
|
presence = Presence(from_jid = _account.jid, \
|
||||||
@@ -508,9 +501,9 @@ class JCLComponent(Component, object):
|
|||||||
stanza_type = "unavailable")
|
stanza_type = "unavailable")
|
||||||
self.stream.send(presence)
|
self.stream.send(presence)
|
||||||
else:
|
else:
|
||||||
accounts = self.account_class.select(\
|
accounts = self.default_account_class.select(\
|
||||||
AND(self.account_class.q.name == name, \
|
AND(self.default_account_class.q.name == name, \
|
||||||
self.account_class.q.user_jid == base_from_jid))
|
self.default_account_class.q.user_jid == base_from_jid))
|
||||||
if accounts.count() > 0:
|
if accounts.count() > 0:
|
||||||
presence = Presence(from_jid = stanza.get_to(), \
|
presence = Presence(from_jid = stanza.get_to(), \
|
||||||
to_jid = from_jid, \
|
to_jid = from_jid, \
|
||||||
@@ -529,12 +522,12 @@ class JCLComponent(Component, object):
|
|||||||
accounts = None
|
accounts = None
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
if not name:
|
if not name:
|
||||||
accounts = self.account_class.select(\
|
accounts = self.default_account_class.select(\
|
||||||
self.account_class.q.user_jid == base_from_jid)
|
self.default_account_class.q.user_jid == base_from_jid)
|
||||||
else:
|
else:
|
||||||
accounts = self.account_class.select(\
|
accounts = self.default_account_class.select(\
|
||||||
AND(self.account_class.q.name == name, \
|
AND(self.default_account_class.q.name == name, \
|
||||||
self.account_class.q.user_jid == base_from_jid))
|
self.default_account_class.q.user_jid == base_from_jid))
|
||||||
if (accounts is not None \
|
if (accounts is not None \
|
||||||
and accounts.count() > 0):
|
and accounts.count() > 0):
|
||||||
presence = stanza.make_accept_response()
|
presence = stanza.make_accept_response()
|
||||||
@@ -556,9 +549,9 @@ class JCLComponent(Component, object):
|
|||||||
from_jid = stanza.get_from()
|
from_jid = stanza.get_from()
|
||||||
base_from_jid = unicode(from_jid.bare())
|
base_from_jid = unicode(from_jid.bare())
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
accounts = self.account_class.select(\
|
accounts = self.default_account_class.select(\
|
||||||
AND(self.account_class.q.name == name, \
|
AND(self.default_account_class.q.name == name, \
|
||||||
self.account_class.q.user_jid == base_from_jid))
|
self.default_account_class.q.user_jid == base_from_jid))
|
||||||
for _account in accounts:
|
for _account in accounts:
|
||||||
presence = Presence(from_jid = _account.jid, \
|
presence = Presence(from_jid = _account.jid, \
|
||||||
to_jid = from_jid, \
|
to_jid = from_jid, \
|
||||||
@@ -591,15 +584,15 @@ class JCLComponent(Component, object):
|
|||||||
name = message.get_to().node
|
name = message.get_to().node
|
||||||
base_from_jid = unicode(message.get_from().bare())
|
base_from_jid = unicode(message.get_from().bare())
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
accounts = self.account_class.select(\
|
accounts = self.default_account_class.select(\
|
||||||
AND(self.account_class.q.name == name, \
|
AND(self.default_account_class.q.name == name, \
|
||||||
self.account_class.q.user_jid == base_from_jid))
|
self.default_account_class.q.user_jid == base_from_jid))
|
||||||
if hasattr(self.account_class, 'password') \
|
if accounts.count() == 1:
|
||||||
and hasattr(self.account_class, 'waiting_password_reply') \
|
|
||||||
and re.compile("\[PASSWORD\]").search(message.get_subject()) \
|
|
||||||
is not None \
|
|
||||||
and accounts.count() == 1:
|
|
||||||
_account = list(accounts)[0]
|
_account = list(accounts)[0]
|
||||||
|
if hasattr(_account, 'password') \
|
||||||
|
and hasattr(_account, 'waiting_password_reply') \
|
||||||
|
and re.compile("\[PASSWORD\]").search(message.get_subject()) \
|
||||||
|
is not None:
|
||||||
_account.password = message.get_body()
|
_account.password = message.get_body()
|
||||||
_account.waiting_password_reply = False
|
_account.waiting_password_reply = False
|
||||||
msg = Message(from_jid = _account.jid, \
|
msg = Message(from_jid = _account.jid, \
|
||||||
@@ -628,8 +621,8 @@ class JCLComponent(Component, object):
|
|||||||
status = _account.status_msg, \
|
status = _account.status_msg, \
|
||||||
show = show, \
|
show = show, \
|
||||||
stanza_type = "available"))
|
stanza_type = "available"))
|
||||||
if hasattr(self.account_class, 'store_password') \
|
if hasattr(_account, 'store_password') \
|
||||||
and hasattr(self.account_class, 'password') \
|
and hasattr(_account, 'password') \
|
||||||
and _account.store_password == False \
|
and _account.store_password == False \
|
||||||
and old_status == account.OFFLINE \
|
and old_status == account.OFFLINE \
|
||||||
and _account.password == None :
|
and _account.password == None :
|
||||||
@@ -638,7 +631,7 @@ class JCLComponent(Component, object):
|
|||||||
def _ask_password(self, _account, lang_class):
|
def _ask_password(self, _account, lang_class):
|
||||||
"""Send a Jabber message to ask for account password
|
"""Send a Jabber message to ask for account password
|
||||||
"""
|
"""
|
||||||
if hasattr(self.account_class, 'waiting_password_reply') \
|
if hasattr(_account, 'waiting_password_reply') \
|
||||||
and not _account.waiting_password_reply \
|
and not _account.waiting_password_reply \
|
||||||
and _account.status != account.OFFLINE:
|
and _account.status != account.OFFLINE:
|
||||||
_account.waiting_password_reply = True
|
_account.waiting_password_reply = True
|
||||||
@@ -656,7 +649,7 @@ class JCLComponent(Component, object):
|
|||||||
"""
|
"""
|
||||||
return _account.name + u"@" + unicode(self.jid)
|
return _account.name + u"@" + unicode(self.jid)
|
||||||
|
|
||||||
def get_reg_form(self, lang_class):
|
def get_reg_form(self, lang_class, _account_class):
|
||||||
"""Return register form based on language and account class
|
"""Return register form based on language and account class
|
||||||
"""
|
"""
|
||||||
reg_form = DataForm()
|
reg_form = DataForm()
|
||||||
@@ -672,12 +665,12 @@ class JCLComponent(Component, object):
|
|||||||
required = True)
|
required = True)
|
||||||
|
|
||||||
for (field_name, field_type, field_options, post_func, default_func) in \
|
for (field_name, field_type, field_options, post_func, default_func) in \
|
||||||
self.account_class.get_register_fields():
|
_account_class.get_register_fields():
|
||||||
if field_name is None:
|
if field_name is None:
|
||||||
# TODO : Add page when empty tuple given
|
# TODO : Add page when empty tuple given
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
lang_label_attr = self.account_class.__name__.lower() \
|
lang_label_attr = _account_class.__name__.lower() \
|
||||||
+ "_" + field_name
|
+ "_" + field_name
|
||||||
if hasattr(lang_class, lang_label_attr):
|
if hasattr(lang_class, lang_label_attr):
|
||||||
label = getattr(lang_class, lang_label_attr)
|
label = getattr(lang_class, lang_label_attr)
|
||||||
@@ -688,7 +681,7 @@ class JCLComponent(Component, object):
|
|||||||
var = field_name)
|
var = field_name)
|
||||||
if field_options is not None:
|
if field_options is not None:
|
||||||
for option_value in field_options:
|
for option_value in field_options:
|
||||||
lang_label_attr = self.account_class.__name__.lower() \
|
lang_label_attr = _account_class.__name__.lower() \
|
||||||
+ "_" + field_name + "_" + option_value
|
+ "_" + field_name + "_" + option_value
|
||||||
if hasattr(lang_class, lang_label_attr):
|
if hasattr(lang_class, lang_label_attr):
|
||||||
label = getattr(lang_class, lang_label_attr)
|
label = getattr(lang_class, lang_label_attr)
|
||||||
@@ -704,7 +697,7 @@ class JCLComponent(Component, object):
|
|||||||
def get_reg_form_init(self, lang_class, _account):
|
def get_reg_form_init(self, lang_class, _account):
|
||||||
"""Return register form for an existing account (update)
|
"""Return register form for an existing account (update)
|
||||||
"""
|
"""
|
||||||
reg_form = self.get_reg_form(lang_class)
|
reg_form = self.get_reg_form(lang_class, _account.__class__)
|
||||||
reg_form.fields["name"].value = _account.name
|
reg_form.fields["name"].value = _account.name
|
||||||
reg_form.fields["name"].type = "hidden"
|
reg_form.fields["name"].type = "hidden"
|
||||||
for (field_name, field) in reg_form.fields.items():
|
for (field_name, field) in reg_form.fields.items():
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class FeederComponent(JCLComponent):
|
|||||||
def handle_tick(self):
|
def handle_tick(self):
|
||||||
"""Implement main feed/send behavior"""
|
"""Implement main feed/send behavior"""
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
for _account in self.account_class.select(clauseTables = ["account"], \
|
for _account in self.default_account_class.select(clauseTables = ["account"], \
|
||||||
orderBy = "user_jid"):
|
orderBy = "user_jid"):
|
||||||
for data in self.feeder.feed(_account):
|
for data in self.feeder.feed(_account):
|
||||||
self.sender.send(_account, data)
|
self.sender.send(_account, data)
|
||||||
|
|||||||
@@ -122,7 +122,10 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
"localhost",
|
"localhost",
|
||||||
"5347",
|
"5347",
|
||||||
'sqlite://' + DB_URL)
|
'sqlite://' + DB_URL)
|
||||||
self.comp.account_class = Account
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
Account.createTable(ifNotExists = True)
|
||||||
|
AccountExample.createTable(ifNotExists = True)
|
||||||
|
del account.hub.threadConnection
|
||||||
self.max_tick_count = 1
|
self.max_tick_count = 1
|
||||||
self.saved_time_handler = None
|
self.saved_time_handler = None
|
||||||
|
|
||||||
@@ -391,9 +394,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.assertEquals(fields[0].children.name, "required")
|
self.assertEquals(fields[0].children.name, "required")
|
||||||
|
|
||||||
def test_handle_get_register_new_complex(self):
|
def test_handle_get_register_new_complex(self):
|
||||||
self.comp.account_class = AccountExample
|
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
|
self.comp.default_account_class = AccountExample
|
||||||
self.comp.handle_get_register(Iq(stanza_type = "get", \
|
self.comp.handle_get_register(Iq(stanza_type = "get", \
|
||||||
from_jid = "user1@test.com", \
|
from_jid = "user1@test.com", \
|
||||||
to_jid = "jcl.test.com"))
|
to_jid = "jcl.test.com"))
|
||||||
@@ -503,10 +506,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.assertEquals(value[0].content, "account11")
|
self.assertEquals(value[0].content, "account11")
|
||||||
|
|
||||||
def test_handle_get_register_exist_complex(self):
|
def test_handle_get_register_exist_complex(self):
|
||||||
self.comp.account_class = AccountExample
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
|
||||||
account1 = AccountExample(user_jid = "user1@test.com", \
|
account1 = AccountExample(user_jid = "user1@test.com", \
|
||||||
name = "account1", \
|
name = "account1", \
|
||||||
jid = "account1@jcl.test.com", \
|
jid = "account1@jcl.test.com", \
|
||||||
@@ -625,9 +627,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.account_class.select(\
|
accounts = self.comp.default_account_class.select(\
|
||||||
self.comp.account_class.q.user_jid == "user1@test.com" \
|
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
||||||
and self.comp.account_class.q.name == "account1")
|
and self.comp.default_account_class.q.name == "account1")
|
||||||
self.assertEquals(accounts.count(), 1)
|
self.assertEquals(accounts.count(), 1)
|
||||||
_account = accounts[0]
|
_account = accounts[0]
|
||||||
self.assertEquals(_account.user_jid, "user1@test.com")
|
self.assertEquals(_account.user_jid, "user1@test.com")
|
||||||
@@ -667,9 +669,12 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
"subscribe")
|
"subscribe")
|
||||||
|
|
||||||
def test_handle_set_register_new_complex(self):
|
def test_handle_set_register_new_complex(self):
|
||||||
self.comp.account_class = AccountExample
|
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
|
self.comp.account_factory = (lambda user_jid, name, jid, x_data: \
|
||||||
|
AccountExample(user_jid = user_jid, \
|
||||||
|
name = name, \
|
||||||
|
jid = jid))
|
||||||
x_data = DataForm()
|
x_data = DataForm()
|
||||||
x_data.xmlns = "jabber:x:data"
|
x_data.xmlns = "jabber:x:data"
|
||||||
x_data.type = "submit"
|
x_data.type = "submit"
|
||||||
@@ -699,9 +704,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.account_class.select(\
|
accounts = self.comp.default_account_class.select(\
|
||||||
self.comp.account_class.q.user_jid == "user1@test.com" \
|
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
||||||
and self.comp.account_class.q.name == "account1")
|
and self.comp.default_account_class.q.name == "account1")
|
||||||
self.assertEquals(accounts.count(), 1)
|
self.assertEquals(accounts.count(), 1)
|
||||||
_account = accounts[0]
|
_account = accounts[0]
|
||||||
self.assertEquals(_account.user_jid, "user1@test.com")
|
self.assertEquals(_account.user_jid, "user1@test.com")
|
||||||
@@ -746,9 +751,12 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
"subscribe")
|
"subscribe")
|
||||||
|
|
||||||
def test_handle_set_register_new_default_values(self):
|
def test_handle_set_register_new_default_values(self):
|
||||||
self.comp.account_class = AccountExample
|
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
|
self.comp.account_factory = (lambda user_jid, name, jid, x_data: \
|
||||||
|
AccountExample(user_jid = user_jid, \
|
||||||
|
name = name, \
|
||||||
|
jid = jid))
|
||||||
x_data = DataForm()
|
x_data = DataForm()
|
||||||
x_data.xmlns = "jabber:x:data"
|
x_data.xmlns = "jabber:x:data"
|
||||||
x_data.type = "submit"
|
x_data.type = "submit"
|
||||||
@@ -766,9 +774,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.account_class.select(\
|
accounts = self.comp.default_account_class.select(\
|
||||||
self.comp.account_class.q.user_jid == "user1@test.com" \
|
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
||||||
and self.comp.account_class.q.name == "account1")
|
and self.comp.default_account_class.q.name == "account1")
|
||||||
self.assertEquals(accounts.count(), 1)
|
self.assertEquals(accounts.count(), 1)
|
||||||
_account = accounts[0]
|
_account = accounts[0]
|
||||||
self.assertEquals(_account.user_jid, "user1@test.com")
|
self.assertEquals(_account.user_jid, "user1@test.com")
|
||||||
@@ -782,7 +790,6 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|
||||||
def test_handle_set_register_new_name_mandatory(self):
|
def test_handle_set_register_new_name_mandatory(self):
|
||||||
self.comp.account_class = AccountExample
|
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
x_data = DataForm()
|
x_data = DataForm()
|
||||||
@@ -796,9 +803,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.account_class.select(\
|
accounts = self.comp.default_account_class.select(\
|
||||||
self.comp.account_class.q.user_jid == "user1@test.com" \
|
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
||||||
and self.comp.account_class.q.name == "account1")
|
and self.comp.default_account_class.q.name == "account1")
|
||||||
self.assertEquals(accounts.count(), 0)
|
self.assertEquals(accounts.count(), 0)
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|
||||||
@@ -813,9 +820,12 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
Lang.en.mandatory_field % ("name"))
|
Lang.en.mandatory_field % ("name"))
|
||||||
|
|
||||||
def test_handle_set_register_new_field_mandatory(self):
|
def test_handle_set_register_new_field_mandatory(self):
|
||||||
self.comp.account_class = AccountExample
|
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
|
self.comp.account_factory = (lambda user_jid, name, jid, x_data: \
|
||||||
|
AccountExample(user_jid = user_jid, \
|
||||||
|
name = name, \
|
||||||
|
jid = jid))
|
||||||
x_data = DataForm()
|
x_data = DataForm()
|
||||||
x_data.xmlns = "jabber:x:data"
|
x_data.xmlns = "jabber:x:data"
|
||||||
x_data.type = "submit"
|
x_data.type = "submit"
|
||||||
@@ -830,9 +840,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.account_class.select(\
|
accounts = self.comp.default_account_class.select(\
|
||||||
self.comp.account_class.q.user_jid == "user1@test.com" \
|
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
||||||
and self.comp.account_class.q.name == "account1")
|
and self.comp.default_account_class.q.name == "account1")
|
||||||
self.assertEquals(accounts.count(), 0)
|
self.assertEquals(accounts.count(), 0)
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|
||||||
@@ -847,10 +857,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
Lang.en.mandatory_field % ("login"))
|
Lang.en.mandatory_field % ("login"))
|
||||||
|
|
||||||
def test_handle_set_register_update_complex(self):
|
def test_handle_set_register_update_complex(self):
|
||||||
self.comp.account_class = AccountExample
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
|
||||||
existing_account = AccountExample(user_jid = "user1@test.com", \
|
existing_account = AccountExample(user_jid = "user1@test.com", \
|
||||||
name = "account1", \
|
name = "account1", \
|
||||||
jid = "account1@jcl.test.com", \
|
jid = "account1@jcl.test.com", \
|
||||||
@@ -897,9 +906,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.account_class.select(\
|
accounts = self.comp.default_account_class.select(\
|
||||||
self.comp.account_class.q.user_jid == "user1@test.com" \
|
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
||||||
and self.comp.account_class.q.name == "account1")
|
and self.comp.default_account_class.q.name == "account1")
|
||||||
self.assertEquals(accounts.count(), 1)
|
self.assertEquals(accounts.count(), 1)
|
||||||
_account = accounts[0]
|
_account = accounts[0]
|
||||||
self.assertEquals(_account.user_jid, "user1@test.com")
|
self.assertEquals(_account.user_jid, "user1@test.com")
|
||||||
@@ -951,11 +960,11 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.account_class.select(\
|
accounts = self.comp.default_account_class.select(\
|
||||||
self.comp.account_class.q.user_jid == "user1@test.com")
|
self.comp.default_account_class.q.user_jid == "user1@test.com")
|
||||||
self.assertEquals(accounts.count(), 0)
|
self.assertEquals(accounts.count(), 0)
|
||||||
accounts = self.comp.account_class.select(\
|
accounts = self.comp.default_account_class.select(\
|
||||||
self.comp.account_class.q.user_jid == "user2@test.com")
|
self.comp.default_account_class.q.user_jid == "user2@test.com")
|
||||||
self.assertEquals(accounts.count(), 1)
|
self.assertEquals(accounts.count(), 1)
|
||||||
_account = accounts[0]
|
_account = accounts[0]
|
||||||
self.assertEquals(_account.user_jid, "user2@test.com")
|
self.assertEquals(_account.user_jid, "user2@test.com")
|
||||||
@@ -1154,10 +1163,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.assertEqual(presence.get_to_jid(), "user1@test.com")
|
self.assertEqual(presence.get_to_jid(), "user1@test.com")
|
||||||
|
|
||||||
def test_handle_presence_available_to_account_live_password_complex(self):
|
def test_handle_presence_available_to_account_live_password_complex(self):
|
||||||
self.comp.account_class = AccountExample
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
|
||||||
account11 = AccountExample(user_jid = "user1@test.com", \
|
account11 = AccountExample(user_jid = "user1@test.com", \
|
||||||
name = "account11", \
|
name = "account11", \
|
||||||
jid = "account11@jcl.test.com")
|
jid = "account11@jcl.test.com")
|
||||||
@@ -1487,14 +1495,14 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.assertEqual(presence.xpath_eval("@type")[0].get_content(), \
|
self.assertEqual(presence.xpath_eval("@type")[0].get_content(), \
|
||||||
"unsubscribed")
|
"unsubscribed")
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
self.assertEquals(self.comp.account_class.select(\
|
self.assertEquals(self.comp.default_account_class.select(\
|
||||||
self.comp.account_class.q.user_jid == "user1@test.com" \
|
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
||||||
and self.comp.account_class.q.name == "account11").count(), \
|
and self.comp.default_account_class.q.name == "account11").count(), \
|
||||||
0)
|
0)
|
||||||
self.assertEquals(self.comp.account_class.select(\
|
self.assertEquals(self.comp.default_account_class.select(\
|
||||||
self.comp.account_class.q.user_jid == "user1@test.com").count(), \
|
self.comp.default_account_class.q.user_jid == "user1@test.com").count(), \
|
||||||
1)
|
1)
|
||||||
self.assertEquals(self.comp.account_class.select().count(), \
|
self.assertEquals(self.comp.default_account_class.select().count(), \
|
||||||
2)
|
2)
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|
||||||
@@ -1519,7 +1527,7 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
presence_sent = self.comp.stream.sent
|
presence_sent = self.comp.stream.sent
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
self.assertEquals(self.comp.account_class.select().count(), \
|
self.assertEquals(self.comp.default_account_class.select().count(), \
|
||||||
3)
|
3)
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|
||||||
@@ -1545,7 +1553,7 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
presence_sent = self.comp.stream.sent
|
presence_sent = self.comp.stream.sent
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
self.assertEquals(self.comp.account_class.select().count(), \
|
self.assertEquals(self.comp.default_account_class.select().count(), \
|
||||||
3)
|
3)
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|
||||||
@@ -1588,10 +1596,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.assertEqual(len(messages_sent), 0)
|
self.assertEqual(len(messages_sent), 0)
|
||||||
|
|
||||||
def test_handle_message_password_complex(self):
|
def test_handle_message_password_complex(self):
|
||||||
self.comp.account_class = AccountExample
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
|
||||||
account11 = AccountExample(user_jid = "user1@test.com", \
|
account11 = AccountExample(user_jid = "user1@test.com", \
|
||||||
name = "account11", \
|
name = "account11", \
|
||||||
jid = "account11@jcl.test.com")
|
jid = "account11@jcl.test.com")
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ from jcl.jabber.feeder import FeederComponent, Feeder, Sender
|
|||||||
from jcl.model.account import Account
|
from jcl.model.account import Account
|
||||||
from jcl.model import account
|
from jcl.model import account
|
||||||
|
|
||||||
|
from tests.jcl.model.account import AccountExample
|
||||||
|
|
||||||
DB_PATH = "/tmp/test.db"
|
DB_PATH = "/tmp/test.db"
|
||||||
DB_URL = DB_PATH #+ "?debug=1&debugThreading=1"
|
DB_URL = DB_PATH #+ "?debug=1&debugThreading=1"
|
||||||
|
|
||||||
@@ -50,11 +52,15 @@ class FeederComponent_TestCase(JCLComponent_TestCase):
|
|||||||
"localhost",
|
"localhost",
|
||||||
"5347",
|
"5347",
|
||||||
'sqlite://' + DB_URL)
|
'sqlite://' + DB_URL)
|
||||||
self.comp.account_class = Account
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
Account.createTable(ifNotExists = True)
|
||||||
|
AccountExample.createTable(ifNotExists = True)
|
||||||
|
del account.hub.threadConnection
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
Account.dropTable(ifExists = True)
|
Account.dropTable(ifExists = True)
|
||||||
|
AccountExample.dropTable(ifExists = True)
|
||||||
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
|
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
|
||||||
account.hub.threadConnection.close()
|
account.hub.threadConnection.close()
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ class AccountExample(Account):
|
|||||||
|
|
||||||
get_register_fields = classmethod(_get_register_fields)
|
get_register_fields = classmethod(_get_register_fields)
|
||||||
|
|
||||||
|
|
||||||
class PresenceAccountExample(PresenceAccount):
|
class PresenceAccountExample(PresenceAccount):
|
||||||
DO_SOMETHING_ELSE = 2
|
DO_SOMETHING_ELSE = 2
|
||||||
possibles_actions = [PresenceAccount.DO_NOTHING, \
|
possibles_actions = [PresenceAccount.DO_NOTHING, \
|
||||||
|
|||||||
Reference in New Issue
Block a user