From: Matthew Treinish Date: Mon, 11 Mar 2013 20:51:24 +0000 (-0400) Subject: Fix bad request response code on extra_specs create. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6a7e93dfc750e08e95c6b53b122407c763883c6c;p=openstack-build%2Fcinder-build.git Fix bad request response code on extra_specs create. This commit changes the error response on a bad body from 422 to 400 for an extra spec create request. Fixes bug 1090356 Change-Id: I7925bbd53fb9647440532b206feee3421fb9f38b --- diff --git a/cinder/api/contrib/types_extra_specs.py b/cinder/api/contrib/types_extra_specs.py index e3a480430..9721c150e 100644 --- a/cinder/api/contrib/types_extra_specs.py +++ b/cinder/api/contrib/types_extra_specs.py @@ -80,7 +80,7 @@ class VolumeTypeExtraSpecsController(wsgi.Controller): authorize(context) if not self.is_valid_body(body, 'extra_specs'): - raise webob.exc.HTTPUnprocessableEntity() + raise webob.exc.HTTPBadRequest() self._check_type(context, type_id) diff --git a/cinder/tests/api/contrib/test_types_extra_specs.py b/cinder/tests/api/contrib/test_types_extra_specs.py index 49a6da6e4..a87939037 100644 --- a/cinder/tests/api/contrib/test_types_extra_specs.py +++ b/cinder/tests/api/contrib/test_types_extra_specs.py @@ -162,6 +162,23 @@ class VolumeTypesExtraSpecsTest(test.TestCase): def test_update_empty_body(self): self._extra_specs_empty_update(body={}) + def _extra_specs_create_bad_body(self, body): + req = fakes.HTTPRequest.blank('/v2/fake/types/1/extra_specs') + req.method = 'POST' + self.assertRaises(webob.exc.HTTPBadRequest, + self.controller.create, req, '1', body) + + def test_create_no_body(self): + self._extra_specs_create_bad_body(body=None) + + def test_create_missing_volume(self): + body = {'foo': {'a': 'b'}} + self._extra_specs_create_bad_body(body=body) + + def test_create_malformed_entity(self): + body = {'extra_specs': 'string'} + self._extra_specs_create_bad_body(body=body) + class VolumeTypeExtraSpecsSerializerTest(test.TestCase): def test_index_create_serializer(self): @@ -195,32 +212,3 @@ class VolumeTypeExtraSpecsSerializerTest(test.TestCase): self.assertEqual('key1', tree.tag) self.assertEqual('value1', tree.text) self.assertEqual(0, len(tree)) - - -class VolumeTypeExtraSpecsUnprocessableEntityTestCase(test.TestCase): - - """ - Tests of places we throw 422 Unprocessable Entity from - """ - - def setUp(self): - super(VolumeTypeExtraSpecsUnprocessableEntityTestCase, self).setUp() - self.controller = types_extra_specs.VolumeTypeExtraSpecsController() - - def _unprocessable_extra_specs_create(self, body): - req = fakes.HTTPRequest.blank('/v2/fake/types/1/extra_specs') - req.method = 'POST' - - self.assertRaises(webob.exc.HTTPUnprocessableEntity, - self.controller.create, req, '1', body) - - def test_create_no_body(self): - self._unprocessable_extra_specs_create(body=None) - - def test_create_missing_volume(self): - body = {'foo': {'a': 'b'}} - self._unprocessable_extra_specs_create(body=body) - - def test_create_malformed_entity(self): - body = {'extra_specs': 'string'} - self._unprocessable_extra_specs_create(body=body)