def test_do_command_no_args(self):
        """ Test executing a command without arguments. """
        command = "ls"
        args = None

        method_args = [command]

        response = "foobar"

        self.mox.StubOutWithMock(RestrictedCommandHandler, "make_syscall")

        RestrictedCommandHandler.make_syscall(method_args).AndReturn(response)

        self.mox.ReplayAll()

        restricted_handler = RestrictedCommandHandler()
        self.assertEquals(response,
                restricted_handler.do_command(command, args))
    def test_do_command_popen_raises(self):
        """ Ensure proper behavior when Popen raises an assertion upon command
            execution. """
        command = "ls"
        args = "-al"

        method_args = [command]
        method_args.extend(args)

        self.mox.StubOutWithMock(RestrictedCommandHandler, "make_syscall")

        RestrictedCommandHandler.make_syscall(method_args).AndRaise(
                OSError(2, None, 'File not found'))

        self.mox.ReplayAll()

        restricted_handler = RestrictedCommandHandler()
        self.assertEqual(type(""),
                type(restricted_handler.do_command(command, args)))