Ejemplo n.º 1
0
    def test_args_from_body(self):

        funcdef = mock.MagicMock()
        body = mock.MagicMock()
        mimetype = "application/json"
        funcdef.ignore_extra_args = True
        json.parse = mock.MagicMock()
        json.parse.side_effect = (exc.UnknownArgument(""))
        resp = args.args_from_body(funcdef, body, mimetype)
        self.assertEqual(resp, ((), {}))
Ejemplo n.º 2
0
        def callfunction(*args):
            if with_self:
                if len(args) == 1:
                    self = args[0]
                    request = self.request
                elif len(args) == 2:
                    self, request = args
                else:
                    raise ValueError("Cannot do anything with these arguments")
            else:
                request = args[0]
            request.override_renderer = 'wsme' + get_outputformat(request)
            try:
                args, kwargs = combine_args(funcdef, (
                    args_from_args(funcdef, (), request.matchdict),
                    args_from_params(funcdef, request.params),
                    args_from_body(funcdef, request.body, request.content_type)
                ))
                wsme.runtime.check_arguments(funcdef, args, kwargs)
                if funcdef.pass_request:
                    kwargs[funcdef.pass_request] = request
                if with_self:
                    args.insert(0, self)

                result = f(*args, **kwargs)
                return {
                    'datatype': funcdef.return_type,
                    'result': result
                }
            except:
                try:
                    exception_info = sys.exc_info()
                    orig_exception = exception_info[1]
                    orig_code = getattr(orig_exception, 'code', None)
                    data = wsme.api.format_exception(exception_info)
                    if orig_code is not None:
                        data['orig_code'] = orig_code
                    return data
                finally:
                    del exception_info