Ejemplo n.º 1
0
    def test_message_subject(self):
        """ Ensure proper handling of a subject stanza. """
        mock_stanza = self.mox.CreateMockAnything()
        mock_body = self.mox.CreateMockAnything()
        mock_client = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(CommandHandler, "__init__")
        self.mox.StubOutWithMock(CommandHandler, "parse_body")
        self.mox.StubOutWithMock(CommandHandler, "log_message")

        self.mox.StubOutWithMock(Message, "__init__")
        self.mox.StubOutWithMock(Message, "__del__")

        CommandHandler.__init__(mock_client)

        mock_stanza.get_subject().AndReturn("subject")
        mock_stanza.get_body().AndReturn(mock_body)
        mock_stanza.get_type().AndReturn("body")
        
        CommandHandler.log_message(mock_stanza, "subject", mock_body, "body")

        mock_stanza.get_type().AndReturn("body")

        CommandHandler.parse_body(mock_body).AndReturn("response")

        mock_stanza.get_from().AndReturn("from")
        mock_stanza.get_to().AndReturn("to")

        Message.__init__(
                to_jid = "from",
                from_jid = "to",
                stanza_type = "body",
                subject = u"Re: subject",
                body = "response")

        Message.__del__()

        self.mox.ReplayAll()

        cmdhandler = CommandHandler(mock_client)
        self.assertNotEqual(None, cmdhandler.message(mock_stanza))
Ejemplo n.º 2
0
    def test_message_no_response(self):
        """ Test a mesage that does not yield a parse result. """
        mock_stanza = self.mox.CreateMockAnything()
        mock_body = self.mox.CreateMockAnything()
        mock_client = self.mox.CreateMockAnything()
        self.mox.StubOutWithMock(CommandHandler, "__init__")
        self.mox.StubOutWithMock(CommandHandler, "parse_body")
        self.mox.StubOutWithMock(CommandHandler, "log_message")

        self.mox.StubOutWithMock(Message, "__init__")
        self.mox.StubOutWithMock(Message, "__del__")

        CommandHandler.__init__(mock_client)

        mock_stanza.get_subject()
        mock_stanza.get_body().AndReturn(mock_body)
        mock_stanza.get_type().AndReturn("body")
        
        CommandHandler.log_message(mock_stanza, None, mock_body, "body")

        mock_stanza.get_type().AndReturn("body")

        CommandHandler.parse_body(mock_body).AndReturn(None)

        mock_stanza.get_from().AndReturn("from")
        mock_stanza.get_to().AndReturn("to")

        Message.__init__(
                to_jid = "from",
                from_jid = "to",
                stanza_type = "body",
                subject = None,
                body = "unknown command")

        self.mox.ReplayAll()

        cmdhandler = CommandHandler(mock_client)
        self.assertNotEqual(None, cmdhandler.message(mock_stanza))