send error implementation
send an error to a user only if he has not already been notified darcs-hash:20070222172740-86b55-7032fdab46f54932c222c36a68bad0915120e92c.gz
This commit is contained in:
@@ -58,7 +58,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_get_register_exist_complex'))
|
# jcl_suite.addTest(JCLComponent_TestCase('test_send_error_second'))
|
||||||
# jcl_suite = unittest.TestSuite((component_suite))
|
# jcl_suite = unittest.TestSuite((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, \
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import time
|
|||||||
import logging
|
import logging
|
||||||
import signal
|
import signal
|
||||||
import re
|
import re
|
||||||
|
import traceback
|
||||||
|
|
||||||
from Queue import Queue
|
from Queue import Queue
|
||||||
|
|
||||||
@@ -328,11 +329,12 @@ class JCLComponent(Component, object):
|
|||||||
def get_reg_form_for_account(_account_class, name, base_from_jid):
|
def get_reg_form_for_account(_account_class, name, base_from_jid):
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
# TODO : do it only one time
|
# TODO : do it only one time
|
||||||
for _account in _account_class.select(\
|
_accounts = _account_class.select(\
|
||||||
AND(_account_class.q.name == name, \
|
AND(_account_class.q.name == name, \
|
||||||
_account_class.q.user_jid == base_from_jid)):
|
_account_class.q.user_jid == base_from_jid))
|
||||||
|
if _accounts is not None:
|
||||||
self.get_reg_form_init(lang_class, \
|
self.get_reg_form_init(lang_class, \
|
||||||
_account).as_xml(query)
|
_accounts[0]).as_xml(query)
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
|
|
||||||
self.__logger.debug("GET_REGISTER")
|
self.__logger.debug("GET_REGISTER")
|
||||||
@@ -719,6 +721,23 @@ class JCLComponent(Component, object):
|
|||||||
(_account.name))
|
(_account.name))
|
||||||
self.stream.send(msg)
|
self.stream.send(msg)
|
||||||
|
|
||||||
|
def _send_error(self, _account, exception):
|
||||||
|
"""Send an error message only one time until _account.in_error
|
||||||
|
has been reset to False"""
|
||||||
|
if _account.in_error == False:
|
||||||
|
_account.in_error = True
|
||||||
|
msg = Message(from_jid = _account.jid, \
|
||||||
|
to_jid = _account.user_jid, \
|
||||||
|
stanza_type = "error", \
|
||||||
|
subject = _account.default_lang_class.check_error_subject, \
|
||||||
|
body = _account.default_lang_class.check_error_body \
|
||||||
|
% (exception))
|
||||||
|
self.stream.send(msg)
|
||||||
|
type, value, stack = sys.exc_info()
|
||||||
|
self.__logger.debug("Error while first checking mail : %s\n%s" \
|
||||||
|
% (exception, "".join(traceback.format_exception
|
||||||
|
(type, value, stack, 5))))
|
||||||
|
|
||||||
def get_jid(self, _account):
|
def get_jid(self, _account):
|
||||||
"""Return account jid based on account instance and component jid
|
"""Return account jid based on account instance and component jid
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -107,8 +107,8 @@ class Lang:
|
|||||||
# connection_label = u"%s connection '%s'"
|
# connection_label = u"%s connection '%s'"
|
||||||
# update_account_message_subject = u"Updated account '%s'"
|
# update_account_message_subject = u"Updated account '%s'"
|
||||||
# update_account_message_body = u"Updated account"
|
# update_account_message_body = u"Updated account"
|
||||||
# check_error_subject = u"Error while checking emails."
|
check_error_subject = u"Error while checking emails."
|
||||||
# check_error_body = u"An error appears while checking emails:\n\t%s"
|
check_error_body = u"An error appears while checking emails:\n\t%s"
|
||||||
# new_mail_subject = u"New email from %s"
|
# new_mail_subject = u"New email from %s"
|
||||||
# new_digest_subject = u"%i new email(s)"
|
# new_digest_subject = u"%i new email(s)"
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
__revision__ = "$Id: account.py,v 1.3 2005/09/18 20:24:07 dax Exp $"
|
__revision__ = "$Id: account.py,v 1.3 2005/09/18 20:24:07 dax Exp $"
|
||||||
|
|
||||||
from sqlobject.inheritance import InheritableSQLObject
|
from sqlobject.inheritance import InheritableSQLObject
|
||||||
from sqlobject.col import StringCol, EnumCol, IntCol
|
from sqlobject.col import StringCol, EnumCol, IntCol, BoolCol
|
||||||
from sqlobject.dbconnection import ConnectionHub
|
from sqlobject.dbconnection import ConnectionHub
|
||||||
|
|
||||||
from jcl.lang import Lang
|
from jcl.lang import Lang
|
||||||
@@ -68,6 +68,7 @@ class Account(InheritableSQLObject):
|
|||||||
jid = StringCol()
|
jid = StringCol()
|
||||||
## Not yet used first_check = BoolCol(default = True)
|
## Not yet used first_check = BoolCol(default = True)
|
||||||
__status = StringCol(default = OFFLINE, dbName = "status")
|
__status = StringCol(default = OFFLINE, dbName = "status")
|
||||||
|
in_error = BoolCol(default = False)
|
||||||
|
|
||||||
## Use these attributs to support volatile password
|
## Use these attributs to support volatile password
|
||||||
## login = StringCol(default = "")
|
## login = StringCol(default = "")
|
||||||
@@ -211,3 +212,17 @@ class PresenceAccount(Account):
|
|||||||
is_action_possible, mandatory_field)]
|
is_action_possible, mandatory_field)]
|
||||||
|
|
||||||
get_register_fields = classmethod(_get_register_fields)
|
get_register_fields = classmethod(_get_register_fields)
|
||||||
|
|
||||||
|
def get_action(self):
|
||||||
|
"""Get apropriate action depending on current status"""
|
||||||
|
mapping = {"online": self.online_action,
|
||||||
|
"chat": self.chat_action,
|
||||||
|
"away": self.away_action,
|
||||||
|
"xa": self.xa_action,
|
||||||
|
"dnd": self.dnd_action,
|
||||||
|
"offline": self.offline_action}
|
||||||
|
if mapping.has_key(self.status):
|
||||||
|
return mapping[self.status]
|
||||||
|
return PresenceAccount.DO_NOTHING
|
||||||
|
|
||||||
|
action = property(get_action)
|
||||||
|
|||||||
@@ -1836,3 +1836,34 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
|
|
||||||
def test_handle_tick(self):
|
def test_handle_tick(self):
|
||||||
self.assertRaises(NotImplementedError, self.comp.handle_tick)
|
self.assertRaises(NotImplementedError, self.comp.handle_tick)
|
||||||
|
|
||||||
|
def test_send_error_first(self):
|
||||||
|
self.comp.stream = MockStream()
|
||||||
|
self.comp.stream_class = MockStream
|
||||||
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
_account = Account(user_jid = "user1@test.com", \
|
||||||
|
name = "account11", \
|
||||||
|
jid = "account11@jcl.test.com")
|
||||||
|
exception = Exception("test exception")
|
||||||
|
self.comp._send_error(_account, exception)
|
||||||
|
self.assertEqual(len(self.comp.stream.sent), 1)
|
||||||
|
error_sent = self.comp.stream.sent[0]
|
||||||
|
self.assertEqual(error_sent.get_to(), _account.user_jid)
|
||||||
|
self.assertEqual(error_sent.get_from(), _account.jid)
|
||||||
|
self.assertEqual(error_sent.get_type(), "error")
|
||||||
|
self.assertEqual(error_sent.get_subject(), _account.default_lang_class.check_error_subject)
|
||||||
|
self.assertEqual(error_sent.get_body(), _account.default_lang_class.check_error_body \
|
||||||
|
% (exception))
|
||||||
|
del account.hub.threadConnection
|
||||||
|
|
||||||
|
def test_send_error_second(self):
|
||||||
|
self.comp.stream = MockStream()
|
||||||
|
self.comp.stream_class = MockStream
|
||||||
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
_account = Account(user_jid = "user1@test.com", \
|
||||||
|
name = "account11", \
|
||||||
|
jid = "account11@jcl.test.com")
|
||||||
|
_account.in_error = True
|
||||||
|
exception = Exception("test exception")
|
||||||
|
self.comp._send_error(_account, exception)
|
||||||
|
self.assertEqual(len(self.comp.stream.sent), 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user