def test_parse_body_help_existing_command(self):
        """ Test the help function for an existing command. """
        command = "foobar"
        args = "some command arguments"
        hlp = "command help"

        command_set = [(command, args, hlp)]

        self.mox.StubOutWithMock(RestrictedCommandHandler, "__init__")
        self.mox.StubOutWithMock(configuration.commands, "restricted_set")

        RestrictedCommandHandler.__init__()
        configuration.commands.restricted_set().AndReturn(command_set)
        configuration.commands.restricted_set().AndReturn(command_set)
        configuration.commands.restricted_set().AndReturn(command_set)
        configuration.commands.restricted_set().AndReturn(command_set)

        self.mox.ReplayAll()

        restricted_handler = RestrictedCommandHandler()
        self.assertEquals("foobar - command help",
                restricted_handler.parse_body("help foobar"))
        self.assertEquals("foobar - command help",
                restricted_handler.parse_body("help	foobar"))
        self.assertEquals("foobar - command help",
                restricted_handler.parse_body("help	foobar	"))
        self.assertEquals("foobar - command help",
                restricted_handler.parse_body("help foobar "))
    def test_parse_body_empty_body(self):
        """ Ensure proper behavior on a None command. """
        self.mox.StubOutWithMock(RestrictedCommandHandler, "__init__")

        RestrictedCommandHandler.__init__()

        self.mox.ReplayAll()

        restricted_handler = RestrictedCommandHandler()
        self.assertEquals(None, restricted_handler.parse_body(None))
    def test_parse_body_disallowed_command(self):
        """ Test for a disallowed command with some arguments. """
        command = "foobar"
        args = "some command arguments"
        hlp = "command help"

        command_set = [(command, args, hlp)]

        self.mox.StubOutWithMock(RestrictedCommandHandler, "__init__")
        self.mox.StubOutWithMock(configuration.commands, "restricted_set")

        RestrictedCommandHandler.__init__()
        configuration.commands.restricted_set().AndReturn(command_set)

        self.mox.ReplayAll()

        restricted_handler = RestrictedCommandHandler()
        self.assertEquals(None,
                restricted_handler.parse_body("disallowed command"))
    def test_parse_body_command_in_set_args(self):
        """ Test for an allowed command with arguments. """
        command = "foobar"
        args = "some command arguments"
        hlp = "command help"

        command_set = [(command, args, hlp)]

        response = "a response"

        self.mox.StubOutWithMock(RestrictedCommandHandler, "__init__")
        self.mox.StubOutWithMock(RestrictedCommandHandler, "do_command")
        self.mox.StubOutWithMock(configuration.commands, "restricted_set")

        RestrictedCommandHandler.__init__()
        configuration.commands.restricted_set().AndReturn(command_set)
        RestrictedCommandHandler.do_command(command, args).AndReturn(response)

        self.mox.ReplayAll()

        restricted_handler = RestrictedCommandHandler()
        self.assertEquals(response, restricted_handler.parse_body(command))