Implement 'get-last-error' ad-hoc command
darcs-hash:20071205172510-86b55-e013c564e730d9e979c4800f73fd9570a8aa7f74.gz
This commit is contained in:
@@ -318,6 +318,7 @@ class JCLCommandManager(CommandManager):
|
|||||||
(True, root_node_re)
|
(True, root_node_re)
|
||||||
self.commands["http://jabber.org/protocol/admin#shutdown"] = \
|
self.commands["http://jabber.org/protocol/admin#shutdown"] = \
|
||||||
(True, root_node_re)
|
(True, root_node_re)
|
||||||
|
self.commands["jcl#get-last-error"] = (False, account_node_re)
|
||||||
|
|
||||||
def get_name_and_jid(self, mixed_name_and_jid):
|
def get_name_and_jid(self, mixed_name_and_jid):
|
||||||
return mixed_name_and_jid.split("/", 1)[:2]
|
return mixed_name_and_jid.split("/", 1)[:2]
|
||||||
@@ -1219,6 +1220,24 @@ class JCLCommandManager(CommandManager):
|
|||||||
restart_thread.start()
|
restart_thread.start()
|
||||||
return (None, result)
|
return (None, result)
|
||||||
|
|
||||||
|
def execute_get_last_error_1(self, info_query, session_context,
|
||||||
|
command_node, lang_class):
|
||||||
|
self.__logger.debug("Executing command 'get-last-error' step 1")
|
||||||
|
result_form = Form(xmlnode_or_type="result")
|
||||||
|
bare_from_jid = info_query.get_from().bare()
|
||||||
|
account_name = info_query.get_to().node
|
||||||
|
_account = account.get_account(bare_from_jid, account_name)
|
||||||
|
if _account is not None and _account.error is not None:
|
||||||
|
last_error = _account.error
|
||||||
|
else:
|
||||||
|
last_error = lang_class.account_no_error
|
||||||
|
result_form.add_field(field_type="text-single",
|
||||||
|
label=lang_class.field_last_error,
|
||||||
|
value=last_error)
|
||||||
|
result_form.as_xml(command_node)
|
||||||
|
command_node.setProp("status", STATUS_COMPLETED)
|
||||||
|
return (result_form, [])
|
||||||
|
|
||||||
class CommandRootDiscoGetInfoHandler(RootDiscoGetInfoHandler):
|
class CommandRootDiscoGetInfoHandler(RootDiscoGetInfoHandler):
|
||||||
|
|
||||||
def handle(self, info_query, lang_class, node, disco_obj, data):
|
def handle(self, info_query, lang_class, node, disco_obj, data):
|
||||||
|
|||||||
@@ -3472,6 +3472,97 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
|||||||
self.assertFalse(self.comp.restart)
|
self.assertFalse(self.comp.restart)
|
||||||
self.assertFalse(self.comp.running)
|
self.assertFalse(self.comp.running)
|
||||||
|
|
||||||
|
def test_execute_get_last_error_no_error(self):
|
||||||
|
self.comp.account_manager.account_classes = (Account,)
|
||||||
|
user1 = User(jid="test1@test.com")
|
||||||
|
user2 = User(jid="test2@test.com")
|
||||||
|
account11 = Account(user=user1,
|
||||||
|
name="account11",
|
||||||
|
jid="account11@" + unicode(self.comp.jid))
|
||||||
|
account12 = Account(user=user1,
|
||||||
|
name="account12",
|
||||||
|
jid="account12@" + unicode(self.comp.jid))
|
||||||
|
account21 = Account(user=user2,
|
||||||
|
name="account21",
|
||||||
|
jid="account21@" + unicode(self.comp.jid))
|
||||||
|
account22 = Account(user=user2,
|
||||||
|
name="account11",
|
||||||
|
jid="account11@" + unicode(self.comp.jid))
|
||||||
|
info_query = Iq(stanza_type="set",
|
||||||
|
from_jid="test1@test.com",
|
||||||
|
to_jid="account11@" + unicode(self.comp.jid))
|
||||||
|
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||||
|
command_node.setProp("node", "jcl#get-last-error")
|
||||||
|
result = self.command_manager.apply_command_action(info_query,
|
||||||
|
"jcl#get-last-error",
|
||||||
|
"execute")
|
||||||
|
self.assertNotEquals(result, None)
|
||||||
|
self.assertEquals(len(result), 1)
|
||||||
|
xml_command = result[0].xpath_eval("c:command",
|
||||||
|
{"c": "http://jabber.org/protocol/commands"})[0]
|
||||||
|
self.assertEquals(xml_command.prop("status"), "completed")
|
||||||
|
self.assertNotEquals(xml_command.prop("sessionid"), None)
|
||||||
|
self._check_actions(result[0])
|
||||||
|
x_data = result[0].xpath_eval("c:command/data:x",
|
||||||
|
{"c": "http://jabber.org/protocol/commands",
|
||||||
|
"data": "jabber:x:data"})
|
||||||
|
self.assertEquals(len(x_data), 1)
|
||||||
|
self.assertEquals(x_data[0].prop("type"), "result")
|
||||||
|
fields = result[0].xpath_eval("c:command/data:x/data:field",
|
||||||
|
{"c": "http://jabber.org/protocol/commands",
|
||||||
|
"data": "jabber:x:data"})
|
||||||
|
self.assertEquals(len(fields), 1)
|
||||||
|
self.assertEquals(fields[0].prop("type"), "text-single")
|
||||||
|
self.assertEquals(fields[0].prop("label"), Lang.en.field_last_error)
|
||||||
|
self.assertEquals(fields[0].children.name, "value")
|
||||||
|
self.assertEquals(fields[0].children.content, Lang.en.account_no_error)
|
||||||
|
|
||||||
|
def test_execute_get_last_error(self):
|
||||||
|
self.comp.account_manager.account_classes = (Account,)
|
||||||
|
user1 = User(jid="test1@test.com")
|
||||||
|
user2 = User(jid="test2@test.com")
|
||||||
|
account11 = Account(user=user1,
|
||||||
|
name="account11",
|
||||||
|
jid="account11@" + unicode(self.comp.jid))
|
||||||
|
account11.error = "Current error"
|
||||||
|
account12 = Account(user=user1,
|
||||||
|
name="account12",
|
||||||
|
jid="account12@" + unicode(self.comp.jid))
|
||||||
|
account21 = Account(user=user2,
|
||||||
|
name="account21",
|
||||||
|
jid="account21@" + unicode(self.comp.jid))
|
||||||
|
account22 = Account(user=user2,
|
||||||
|
name="account11",
|
||||||
|
jid="account11@" + unicode(self.comp.jid))
|
||||||
|
info_query = Iq(stanza_type="set",
|
||||||
|
from_jid="test1@test.com",
|
||||||
|
to_jid="account11@" + unicode(self.comp.jid))
|
||||||
|
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||||
|
command_node.setProp("node", "jcl#get-last-error")
|
||||||
|
result = self.command_manager.apply_command_action(info_query,
|
||||||
|
"jcl#get-last-error",
|
||||||
|
"execute")
|
||||||
|
self.assertNotEquals(result, None)
|
||||||
|
self.assertEquals(len(result), 1)
|
||||||
|
xml_command = result[0].xpath_eval("c:command",
|
||||||
|
{"c": "http://jabber.org/protocol/commands"})[0]
|
||||||
|
self.assertEquals(xml_command.prop("status"), "completed")
|
||||||
|
self.assertNotEquals(xml_command.prop("sessionid"), None)
|
||||||
|
self._check_actions(result[0])
|
||||||
|
x_data = result[0].xpath_eval("c:command/data:x",
|
||||||
|
{"c": "http://jabber.org/protocol/commands",
|
||||||
|
"data": "jabber:x:data"})
|
||||||
|
self.assertEquals(len(x_data), 1)
|
||||||
|
self.assertEquals(x_data[0].prop("type"), "result")
|
||||||
|
fields = result[0].xpath_eval("c:command/data:x/data:field",
|
||||||
|
{"c": "http://jabber.org/protocol/commands",
|
||||||
|
"data": "jabber:x:data"})
|
||||||
|
self.assertEquals(len(fields), 1)
|
||||||
|
self.assertEquals(fields[0].prop("type"), "text-single")
|
||||||
|
self.assertEquals(fields[0].prop("label"), Lang.en.field_last_error)
|
||||||
|
self.assertEquals(fields[0].children.name, "value")
|
||||||
|
self.assertEquals(fields[0].children.content, "Current error")
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
test_suite = unittest.TestSuite()
|
test_suite = unittest.TestSuite()
|
||||||
test_suite.addTest(unittest.makeSuite(CommandManager_TestCase, 'test'))
|
test_suite.addTest(unittest.makeSuite(CommandManager_TestCase, 'test'))
|
||||||
|
|||||||
@@ -240,6 +240,9 @@ class Lang:
|
|||||||
help_message_subject = u"Help"
|
help_message_subject = u"Help"
|
||||||
help_message_body = u"No help"
|
help_message_body = u"No help"
|
||||||
|
|
||||||
|
field_last_error = u"Last error"
|
||||||
|
account_no_error = u"This account has no error"
|
||||||
|
|
||||||
class fr:
|
class fr:
|
||||||
component_name = u"composant générique Jabber Component Library"
|
component_name = u"composant générique Jabber Component Library"
|
||||||
register_title = u"Enregistrement d'un nouveau compte"
|
register_title = u"Enregistrement d'un nouveau compte"
|
||||||
@@ -425,6 +428,9 @@ class Lang:
|
|||||||
help_message_subject = u"Aide"
|
help_message_subject = u"Aide"
|
||||||
help_message_body = u"Pas d'aide !"
|
help_message_body = u"Pas d'aide !"
|
||||||
|
|
||||||
|
field_last_error = u"Dernière erreur"
|
||||||
|
account_no_error = u"Ce compte n'a pas d'erreur"
|
||||||
|
|
||||||
class nl:
|
class nl:
|
||||||
# TODO: when finish, delete this line and uncomment in tests/lang.py the makeSuite(Language_nl_TestCase, 'test') line
|
# TODO: when finish, delete this line and uncomment in tests/lang.py the makeSuite(Language_nl_TestCase, 'test') line
|
||||||
register_title = u"Registratie van verbindingen voor Jabber Mail"
|
register_title = u"Registratie van verbindingen voor Jabber Mail"
|
||||||
|
|||||||
@@ -242,6 +242,9 @@ class Language_TestCase(unittest.TestCase):
|
|||||||
self.assertNotEquals(self.lang_class.help_message_subject, None)
|
self.assertNotEquals(self.lang_class.help_message_subject, None)
|
||||||
self.assertNotEquals(self.lang_class.help_message_body, None)
|
self.assertNotEquals(self.lang_class.help_message_body, None)
|
||||||
|
|
||||||
|
self.assertNotEquals(self.lang_class.field_last_error, None)
|
||||||
|
self.assertNotEquals(self.lang_class.account_no_error, None)
|
||||||
|
|
||||||
class Language_fr_TestCase(Language_TestCase):
|
class Language_fr_TestCase(Language_TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.lang_class = Lang.fr
|
self.lang_class = Lang.fr
|
||||||
|
|||||||
Reference in New Issue
Block a user