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')
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')
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}
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)
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)
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, {})