예제 #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)