]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix bad request response code on extra_specs create.
authorMatthew Treinish <treinish@linux.vnet.ibm.com>
Mon, 11 Mar 2013 20:51:24 +0000 (16:51 -0400)
committerMatthew Treinish <treinish@linux.vnet.ibm.com>
Mon, 11 Mar 2013 20:54:30 +0000 (16:54 -0400)
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

cinder/api/contrib/types_extra_specs.py
cinder/tests/api/contrib/test_types_extra_specs.py

index e3a4804309bb53233b620e822f54e10f8dff53e3..9721c150e75296d9c2b394b758715f4c5ac74bde 100644 (file)
@@ -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)
 
index 49a6da6e44bec553a582fc6c084ca1101a876b67..a879390379ef0af69472fb4331a7f0ad69092d7c 100644 (file)
@@ -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)