Store error in account instead of just a boolean (in_error)

darcs-hash:20071204163906-86b55-a552731ba162d51b7a6451027bb5991594348611.gz
This commit is contained in:
David Rousselie
2007-12-04 17:39:06 +01:00
parent edc152010e
commit 05c3358feb
5 changed files with 15 additions and 11 deletions

View File

@@ -573,11 +573,11 @@ class AccountManager(object):
return result
def send_error_from_account(self, _account, exception):
"""Send an error message only one time until _account.in_error
has been reset to False"""
"""Send an error message only one time until _account.error
has been reset to None"""
result = []
if _account.in_error == False:
_account.in_error = True
if _account.error == None:
_account.error = str(exception)
result.append(Message(from_jid=_account.jid,
to_jid=_account.user.jid,
stanza_type="error",

View File

@@ -83,11 +83,12 @@ class AccountPresenceHandler(Handler):
class AccountPresenceAvailableHandler(AccountPresenceHandler):
def get_account_presence(self, stanza, lang_class, _account):
show_status = account.ONLINE
if _account.in_error:
if _account.error is not None:
show_status = account.DND
elif not _account.enabled:
show_status = account.XA
return self.component.account_manager.send_presence_available(_account,
return self.component.account_manager.send_presence_available(\
_account,
show_status,
lang_class)

View File

@@ -2781,6 +2781,7 @@ class JCLComponent_TestCase(JCLTestCase):
name="account11",
jid="account11@jcl.test.com")
exception = Exception("test exception")
self.assertEqual(_account.error, None)
self.comp.send_error(_account, exception)
self.assertEqual(len(self.comp.stream.sent), 1)
error_sent = self.comp.stream.sent[0]
@@ -2790,6 +2791,7 @@ class JCLComponent_TestCase(JCLTestCase):
self.assertEqual(error_sent.get_subject(), _account.default_lang_class.error_subject)
self.assertEqual(error_sent.get_body(), _account.default_lang_class.error_body \
% (exception))
self.assertEqual(_account.error, "test exception")
model.db_disconnect()
def test_send_error_second(self):
@@ -2799,9 +2801,10 @@ class JCLComponent_TestCase(JCLTestCase):
_account = Account(user=User(jid="user1@test.com"),
name="account11",
jid="account11@jcl.test.com")
_account.in_error = True
_account.error = "test exception"
exception = Exception("test exception")
self.comp.send_error(_account, exception)
self.assertEqual(_account.error, "test exception")
self.assertEqual(len(self.comp.stream.sent), 0)
def test_send_stanzas(self):

View File

@@ -246,7 +246,7 @@ class AccountPresenceAvailableHandler_TestCase(JCLTestCase):
account11 = Account(user=user1,
name="account11",
jid="account11@jcl.test.com")
account11.in_error = True
account11.error = "Error"
account12 = Account(user=user1,
name="account12",
jid="account12@jcl.test.com")

View File

@@ -91,7 +91,7 @@ class Account(InheritableSQLObject):
name = StringCol()
jid = StringCol()
_status = StringCol(default=OFFLINE, dbName="status")
in_error = BoolCol(default=False)
error = StringCol(default=None)
legacy_jids = MultipleJoin('LegacyJID')
enabled = BoolCol(default=True)
lastlogin = DateTimeCol(default=datetime.datetime.today())