Пример #1
0
    def run(self):
        """ This method provides the main function of the daemon, i.e.
        connecting the XMPP client, and entering the application message loop.
        """

        try:
            self.__setup_logging()

            client = Client(JID(self.__usr), self.__pwd)
            client.connect()

            provider = StatusProvider()
            provider.start()

            update_handler = updates.get_update_handler()
            if update_handler:
                update_handler.start()

            client.loop(1)
        except Exception, exc:
            logger = logging.getLogger()
            logger.critical(u"encountered exception %s. terminating XMPPMote." %
                           repr(exc))

            for line in filter(None, traceback.format_exc().split("\n")):
                logger.critical(line)
Пример #2
0
    def test_xmppmotedaemon_run(self):
        """ Test the run method of the XMPPMoteDaemon, using Mox in order to
        verify proper connection procedure. """

        mock_update_handler = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(StatusProvider, "__init__")
        self.mox.StubOutWithMock(StatusProvider, "start")
        self.mox.StubOutWithMock(Client, "__init__")
        self.mox.StubOutWithMock(Client, "connect")
        self.mox.StubOutWithMock(Client, "loop")
        self.mox.StubOutWithMock(Client, "disconnect")

        self.mox.StubOutWithMock(Daemon, "start")

        self.mox.StubOutWithMock(xmppmoted.XMPPMoteDaemon,
                                 "_XMPPMoteDaemon__parse_config_file")
        self.mox.StubOutWithMock(xmppmoted.XMPPMoteDaemon,
                                 "_XMPPMoteDaemon__get_pidfile")
        self.mox.StubOutWithMock(credentials, "get_credentials")

        self.mox.StubOutWithMock(updates, "get_update_handler")

        xmppmoted.XMPPMoteDaemon._XMPPMoteDaemon__parse_config_file()
        xmppmoted.XMPPMoteDaemon._XMPPMoteDaemon__get_pidfile().AndReturn(None)

        Daemon.start(mox.IgnoreArg())

        credentials.get_credentials().AndReturn((self.__usr, self.__pwd))

        StatusProvider.__init__()
        StatusProvider.start()

        updates.get_update_handler().AndReturn(mock_update_handler)
        mock_update_handler.start()

        Client.__init__(JID(self.__usr), self.__pwd)

        Client.connect()
        Client.loop(1)
        Client.disconnect()
        self.mox.ReplayAll()

        daemon = xmppmoted.XMPPMoteDaemon()
        daemon.start()
        daemon.run()