示例#1
0
文件: views.py 项目: MShel/savory-pie
    def resource_dispatch(request, uri, data, host):

        resource_path = compute_resource_path(uri, host)
        ctx = compute_context(resource_path, request, root_resource)

        resource = ctx.resolve_resource_path(resource_path)

        resource_result = {'uri': uri}

        if resource is None:
            resource_result['status'] = 404
            return resource_result

        try:
            if request.method == 'GET':
                resource_result.update(
                    _get_request_for_batch(ctx, resource, data))
            elif request.method == 'POST':
                resource_result.update(
                    _post_request_for_batch(ctx, resource, data))
            elif request.method == 'PUT':
                resource_result.update(
                    _put_request_for_batch(ctx, resource, data))
            elif request.method == 'DELETE':
                process_delete_request(ctx, resource)
                resource_result['status'] = 200
            else:
                raise MethodNotAllowedError(method=request.method)
        except MethodNotAllowedError:
            resource_result['status'] = 405
            resource_result['allowed'] = ','.join(resource.allowed_methods)
        except validators.ValidationError, ve:
            resource_result['status'] = 400
            resource_result['validation_errors'] = ve.errors
示例#2
0
文件: views.py 项目: wware/savory-pie
    def resource_dispatch(request, uri, data, host):

        resource_path = compute_resource_path(uri, host)
        ctx = compute_context(resource_path, request, root_resource)

        resource = ctx.resolve_resource_path(resource_path)

        resource_result = {'uri': uri}

        if resource is None:
            resource_result['status'] = 404
            return resource_result

        try:
            if request.method == 'GET':
                resource_result.update(
                    _get_request_for_batch(ctx, resource, data)
                )
            elif request.method == 'POST':
                resource_result.update(
                    _post_request_for_batch(ctx, resource, data)
                )
            elif request.method == 'PUT':
                resource_result.update(
                    _put_request_for_batch(ctx, resource, data)
                )
            elif request.method == 'DELETE':
                process_delete_request(ctx, resource)
                resource_result['status'] = 200
            else:
                raise MethodNotAllowedError(method=request.method)
        except MethodNotAllowedError:
            resource_result['status'] = 405
            resource_result['allowed'] = ','.join(resource.allowed_methods)
        except validators.ValidationError, ve:
            resource_result['status'] = 400
            resource_result['validation_errors'] = ve.errors
示例#3
0
文件: views.py 项目: MShel/savory-pie
def _process_delete(ctx, resource, request):
    try:
        process_delete_request(ctx, resource)
        return _success(ctx, request, request)
    except MethodNotAllowedError:
        return _not_allowed_method(ctx, resource, request)
示例#4
0
 def test_delete(self, ParamsImplClass):
     ParamsImplClass.return_value = 'getparams'
     resource = Mock(name='resource', allowed_methods=['DELETE'])
     ctx = Mock(name='ctx')
     helpers.process_delete_request(ctx, resource)
     resource.delete.assert_called_with(ctx)
示例#5
0
 def test_delete_not_allowed(self):
     with self.assertRaises(MethodNotAllowedError):
         resource = Mock(name='resource', allowed_methods=['GET'])
         helpers.process_delete_request(Mock(name='ctx'), resource)
示例#6
0
文件: views.py 项目: wware/savory-pie
def _process_delete(ctx, resource, request):
    try:
        process_delete_request(ctx, resource)
        return _success(ctx, request, request)
    except MethodNotAllowedError:
        return _not_allowed_method(ctx, resource, request)
示例#7
0
 def test_delete(self, ParamsImplClass):
     ParamsImplClass.return_value = 'getparams'
     resource = Mock(name='resource', allowed_methods=['DELETE'])
     ctx = Mock(name='ctx')
     helpers.process_delete_request(ctx, resource)
     resource.delete.assert_called_with(ctx)
示例#8
0
 def test_delete_not_allowed(self):
     with self.assertRaises(MethodNotAllowedError):
         resource = Mock(name='resource', allowed_methods=['GET'])
         helpers.process_delete_request(Mock(name='ctx'), resource)