예제 #1
0
 def test_put_precondition(self, EmptyParamsClass):
     EmptyParamsClass.return_value = 'params'
     with self.assertRaises(PreConditionError):
         resource = Mock(name='resource', allowed_methods=['PUT'])
         resource.get.return_value = {}
         ctx = Mock(name='ctx')
         helpers.process_put_request(ctx, resource, {'data': 'data'}, expected_hash='123')
     resource.put.assert_called_with(ctx, {'data': 'data'})
     resource.get.assert_called_with(ctx, 'params')
예제 #2
0
 def test_put_precondition(self, EmptyParamsClass):
     EmptyParamsClass.return_value = 'params'
     with self.assertRaises(PreConditionError):
         resource = Mock(name='resource', allowed_methods=['PUT'])
         resource.get.return_value = {}
         ctx = Mock(name='ctx')
         helpers.process_put_request(ctx,
                                     resource, {'data': 'data'},
                                     expected_hash='123')
     resource.put.assert_called_with(ctx, {'data': 'data'})
     resource.get.assert_called_with(ctx, 'params')
예제 #3
0
 def test_put(self):
     resource = Mock(name='resource', allowed_methods=['PUT'])
     resource.get.return_value = {}
     resource.put.return_value = 'some value'
     ctx = Mock(name='ctx')
     result = helpers.process_put_request(ctx, resource, {'data': 'data'})
     resource.put.assert_called_with(ctx, {'data': 'data'})
     self.assertEqual(result, 'some value')
예제 #4
0
 def test_put(self):
     resource = Mock(name='resource', allowed_methods=['PUT'])
     resource.get.return_value = {}
     resource.put.return_value = 'some value'
     ctx = Mock(name='ctx')
     result = helpers.process_put_request(ctx, resource, {'data': 'data'})
     resource.put.assert_called_with(ctx, {'data': 'data'})
     self.assertEqual(result, 'some value')
예제 #5
0
파일: views.py 프로젝트: MShel/savory-pie
    def _put_request_for_batch(ctx, resource, data):

        resource_result = {}
        try:

            content_dict = process_put_request(ctx, resource, data)
        except PreConditionError:
            resource_result['status'] = 412
        except KeyError, ke:
            resource_result['status'] = 400
            resource_result['validation_errors'] = {'missingData': ke.message}
예제 #6
0
파일: views.py 프로젝트: wware/savory-pie
    def _put_request_for_batch(ctx, resource, data):

        resource_result = {}
        try:

            content_dict = process_put_request(ctx, resource, data)
        except PreConditionError:
            resource_result['status'] = 412
        except KeyError, ke:
            resource_result['status'] = 400
            resource_result['validation_errors'] = {'missingData': ke.message}
예제 #7
0
파일: views.py 프로젝트: MShel/savory-pie
def _process_put(ctx, resource, request):
    try:
        data = ctx.formatter.read_from(request)
        content_dict = process_put_request(
            ctx,
            resource,
            data,
            expected_hash=request.META.get('HTTP_IF_MATCH'))
        if content_dict:
            return _content_success(ctx, resource, request, content_dict)
        return _no_content_success(ctx, resource, request)
    except PreConditionError:
        return _precondition_failed(ctx, resource, request)
    except MethodNotAllowedError:
        return _not_allowed_method(ctx, resource, request)
    except validators.ValidationError, ve:
        return _validation_errors(ctx, resource, request, ve.errors)
예제 #8
0
파일: views.py 프로젝트: wware/savory-pie
def _process_put(ctx, resource, request):
    try:
        data = ctx.formatter.read_from(request)
        content_dict = process_put_request(
            ctx,
            resource,
            data,
            expected_hash=request.META.get('HTTP_IF_MATCH')
        )
        if content_dict:
            return _content_success(ctx, resource, request, content_dict)
        return _no_content_success(ctx, resource, request)
    except PreConditionError:
        return _precondition_failed(ctx, resource, request)
    except MethodNotAllowedError:
        return _not_allowed_method(ctx, resource, request)
    except validators.ValidationError, ve:
        return _validation_errors(ctx, resource, request, ve.errors)
예제 #9
0
 def test_put_not_allowed(self):
     with self.assertRaises(MethodNotAllowedError):
         resource = Mock(name='resource', allowed_methods=['POST'])
         helpers.process_put_request(Mock(name='ctx'), resource, {})
예제 #10
0
 def test_put_not_allowed(self):
     with self.assertRaises(MethodNotAllowedError):
         resource = Mock(name='resource', allowed_methods=['POST'])
         helpers.process_put_request(Mock(name='ctx'), resource, {})