From 61e7e256f03881f1b38bc26c7d27b209cb1c61fa Mon Sep 17 00:00:00 2001 From: David Rousselie Date: Tue, 4 Sep 2007 08:42:15 +0200 Subject: [PATCH] 'delete-motd' ad-hoc command implementation darcs-hash:20070904064215-86b55-c4cd4112307311ba86b0810859dafb7e6dc2f7a4.gz --- src/jcl/jabber/command.py | 5 ++- src/jcl/jabber/tests/command.py | 55 ++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/jcl/jabber/command.py b/src/jcl/jabber/command.py index 66aa057..5580e16 100644 --- a/src/jcl/jabber/command.py +++ b/src/jcl/jabber/command.py @@ -829,7 +829,10 @@ class JCLCommandManager(CommandManager): def execute_delete_motd_1(self, info_query, session_context, command_node, lang_class): - return [] + self.__logger.debug("Executing command 'del motd' step 1") + self.component.del_motd() + command_node.setProp("status", STATUS_COMPLETED) + return (None, []) def execute_set_welcome(self, info_query): return [] diff --git a/src/jcl/jabber/tests/command.py b/src/jcl/jabber/tests/command.py index 6e6b0a4..2b8fba6 100644 --- a/src/jcl/jabber/tests/command.py +++ b/src/jcl/jabber/tests/command.py @@ -2452,14 +2452,53 @@ class JCLCommandManager_TestCase(JCLTestCase): "Message Of The Day") os.unlink(config_file) -# def test_execute_delete_motd(self): -# #TODO : implement command -# info_query = Iq(stanza_type="set", -# from_jid="user1@test.com", -# to_jid="jcl.test.com") -# result = self.command_manager.execute_add_user(info_query) -# self.assertNotEquals(result, None) -# self.assertEquals(len(result), 1) + def test_execute_delete_motd(self): + self.comp.account_manager.account_classes = (ExampleAccount, + Example2Account) + config_file = tempfile.mktemp(".conf", "jcltest", jcl.tests.DB_DIR) + self.comp.config_file = config_file + self.comp.config = ConfigParser() + self.comp.set_motd("test motd") + model.db_connect() + user1 = User(jid="test1@test.com") + account11 = ExampleAccount(user=user1, + name="account11", + jid="account11@jcl.test.com") + account11.status = account.ONLINE + account12 = Example2Account(user=user1, + name="account12", + jid="account12@jcl.test.com") + account12.status = "away" + user2 = User(jid="test2@test.com") + account21 = ExampleAccount(user=user2, + name="account21", + jid="account21@jcl.test.com") + account21.status = account.OFFLINE + account22 = ExampleAccount(user=user2, + name="account11", + jid="account11@jcl.test.com") + account22.status = account.OFFLINE + model.db_disconnect() + info_query = Iq(stanza_type="set", + from_jid="user1@test.com", + to_jid="jcl.test.com") + command_node = info_query.set_new_content(command.COMMAND_NS, "command") + command_node.setProp("node", + "http://jabber.org/protocol/admin#delete-motd") + result = self.command_manager.apply_command_action(\ + info_query, + "http://jabber.org/protocol/admin#delete-motd", + "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]) + self.comp.config.read(self.comp.config_file) + self.assertFalse(self.comp.config.has_option("component", "motd")) + os.unlink(config_file) # def test_execute_set_welcome(self): # #TODO : implement command