class EventDrivenShellClusterBotTest(unittest.TestCase): def setUp(self): self.testobj = EventDrivenShellClusterBot("testuser","testpwd",[], None, None, None, debug=True) self.subscriber="testsubscriber" self.nonexistentEvent="NoneExistantEvent" self.existentEvent="ExceedingCPUTempEvent" def tearDown(self): self.testobj.quit(); self.testobj = None; def test_subscribe_eventdoesnotexist(self): ret = self.testobj.subscribe(Message(frm=self.subscriber), self.nonexistentEvent) self.assertEquals(ret, "The event %s is not available for subscription." % self.nonexistentEvent, "the event should not exist and hence not be available for subscription") ret = self.testobj.unsubscribe(Message(frm=self.subscriber), self.nonexistentEvent) self.assertEquals(ret, "The event %s is not available for subscription." % self.nonexistentEvent, "the event should not exist and hence noone should have been able to subscribe to it") def test_subscribe_eventdoesexist(self): self.testobj.importnewevents(None,[]); ret = self.testobj.unsubscribe(Message(frm=self.subscriber), self.existentEvent) self.assertEquals(ret, 'You are not subscribed to the event '+self.existentEvent, "this user has not yet subscribed to the event") ret = self.testobj.subscribe(Message(frm=self.subscriber), self.existentEvent) self.assertEquals(ret, 'You are now subscribed to the event: '+ self.existentEvent, "the event should exist and be available for subscription") ret = self.testobj.subscribe(Message(frm=self.subscriber), self.existentEvent) self.assertEquals(ret, 'You are already subscribed to the event: '+ self.existentEvent, "the user should already be subscribed to the event") ret = self.testobj.unsubscribe(Message(frm=self.subscriber), self.existentEvent) self.assertEquals(ret, 'You are now unsubscribed from the event '+ self.existentEvent, "the user should be unsubscribed to the event") ret = self.testobj.unsubscribe(Message(frm=self.subscriber), self.existentEvent) self.assertEquals(ret, 'You are not subscribed to the event '+self.existentEvent, "this user should have been unsubscribed from the event")
config = MyXMLReader(xmlFile); #The defaults of "" allow for a connection via private key if headnodePW == "": headnodePW = getXMLConfigurationParameterWithDefault(config, "headnode", "password") headnodeUser = getXMLConfigurationParameterWithDefault(config, "headnode","user") headnodeIP = config.getAttribute("headnode","ip"); jabberID = config.getAttribute("jabber","jid"); if jabberPW == None: jabberPW = config.getAttribute("jabber","password"); jabberWhitelist = config.getAttribute("whitelist","jid"); return (headnodeIP, headnodeUser, headnodePW, jabberID, jabberPW, jabberWhitelist) def isXMLFile(file): return os.path.basename(sys.argv[1]).endswith(".xml"); if __name__ == "__main__": headnodeIP, headnodeUser, headnodePW, jabberID, jabberPW, jabberWhitelist = getConfigurationParameters(); bot = None #print "ping frequency: "+str(JabberBot.PING_FREQUENCY) JabberBot.PING_FREQUENCY = 20 #print "ping frequency: "+str(JabberBot.PING_FREQUENCY) bot = EventDrivenShellClusterBot(jabberID, jabberPW, headnodeIP, headnodeUser, headnodePW, debug=True) print repr(jabberWhitelist) bot.set_whitelist(jabberWhitelist) try: bot.serve_forever(connect_callback = bot.connect_callback); finally: if bot: bot.quit()