]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
fix bug 814012, add unit tests for it
authorDan Wendlandt <dan@nicira.com>
Wed, 27 Jul 2011 16:33:21 +0000 (09:33 -0700)
committerDan Wendlandt <dan@nicira.com>
Wed, 27 Jul 2011 16:33:21 +0000 (09:33 -0700)
quantum/common/wsgi.py
tests/unit/test_api.py

index d883746acb50b4ff38e8b7af34f8cbe1e1aab338..6a5d350552f97b1f645337a3c204949ed37cb93a 100644 (file)
@@ -425,7 +425,10 @@ class Serializer(object):
         The string must be in the format of a supported MIME type.
 
         """
-        return self.get_deserialize_handler(content_type)(datastring)
+        try:
+            return self.get_deserialize_handler(content_type)(datastring)
+        except Exception:
+            raise webob.exc.HTTPBadRequest("Could not deserialize data")
 
     def get_deserialize_handler(self, content_type):
         handlers = {
index c09af76990e7c0371fcc07d6815d00d5fca98bc5..ad9a216be25a3437702a4bceeb6977c77426eb36 100644 (file)
@@ -614,6 +614,23 @@ class APITest(unittest.TestCase):
         LOG.debug("_test_delete_attachment_portnotfound - " \
                   "format:%s - END", format)
 
+    def _test_unparsable_data(self, format):
+        LOG.debug("_test_unparsable_data - " \
+                  " format:%s - START", format)
+
+        data = "this is not json or xml"
+        method = 'POST'
+        content_type = "application/%s" % format
+        tenant_id = self.tenant_id
+        path = "/tenants/%(tenant_id)s/networks.%(format)s" % locals()
+        network_req = testlib.create_request(path, data, content_type, method)
+        network_res = network_req.get_response(self.api)
+        self.assertEqual(network_res.status_int, 400)
+
+        LOG.debug("_test_unparsable_data - " \
+                  "format:%s - END", format)
+
+
     def setUp(self):
         options = {}
         options['plugin_provider'] = 'quantum.plugins.SamplePlugin.FakePlugin'
@@ -829,3 +846,10 @@ class APITest(unittest.TestCase):
 
     def test_delete_attachment_portnotfound_json(self):
         self._test_delete_attachment_portnotfound('json')
+
+    def test_unparsable_data_xml(self):
+        self._test_unparsable_data('xml')
+
+    def test_unparsable_data_json(self):
+        self._test_unparsable_data('json')
+