]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Python3: do not set Request.body to a text string
authorCyril Roelandt <cyril@redhat.com>
Mon, 22 Jun 2015 14:59:59 +0000 (14:59 +0000)
committerCyril Roelandt <cyril@redhat.com>
Mon, 22 Jun 2015 15:59:26 +0000 (17:59 +0200)
In Python 3, Request.body must be set to a bytes object.

Change-Id: I17785d1e9eb253a1c6cae300b207fb0a08873b0e
Blueprint: neutron-python3

neutron/tests/unit/api/v2/test_resource.py
neutron/tests/unit/test_wsgi.py
neutron/tests/unit/testlib_api.py

index 6d728ec13a50eebec21bac10d2e0bd78de3514cd..96c7d2da29d1b6d8dce0773a0abc383e2071e4f5 100644 (file)
@@ -32,7 +32,7 @@ class RequestTestCase(base.BaseTestCase):
 
     def test_content_type_missing(self):
         request = wsgi.Request.blank('/tests/123', method='POST')
-        request.body = "<body />"
+        request.body = b"<body />"
         self.assertIsNone(request.get_content_type())
 
     def test_content_type_with_charset(self):
index 68c3c64cf4a9a981e95381c3c62cbaf11f426fe5..0f94a14ca233809d22751eaa10c2503e3bf32ada 100644 (file)
@@ -358,14 +358,14 @@ class RequestTest(base.BaseTestCase):
 
     def test_content_type_missing(self):
         request = wsgi.Request.blank('/tests/123', method='POST')
-        request.body = "<body />"
+        request.body = b"<body />"
 
         self.assertIsNone(request.get_content_type())
 
     def test_content_type_unsupported(self):
         request = wsgi.Request.blank('/tests/123', method='POST')
         request.headers["Content-Type"] = "text/html"
-        request.body = "fake<br />"
+        request.body = b"fake<br />"
 
         self.assertIsNone(request.get_content_type())
 
@@ -618,7 +618,7 @@ class ResourceTest(base.BaseTestCase):
     def test_malformed_request_body_throws_bad_request(self):
         resource = wsgi.Resource(None, self.my_fault_body_function)
         request = wsgi.Request.blank(
-            "/", body="{mal:formed", method='POST',
+            "/", body=b"{mal:formed", method='POST',
             headers={'Content-Type': "application/json"})
 
         response = resource(request)
@@ -627,7 +627,7 @@ class ResourceTest(base.BaseTestCase):
     def test_wrong_content_type_throws_unsupported_media_type_error(self):
         resource = wsgi.Resource(None, self.my_fault_body_function)
         request = wsgi.Request.blank(
-            "/", body="{some:json}", method='POST',
+            "/", body=b"{some:json}", method='POST',
             headers={'Content-Type': "xxx"})
 
         response = resource(request)
index 90e5bbeeba0b037c2ffdeb1df092892d2ff75c20..27fc8a426f04c61ac2b070a3442e84978742a065 100644 (file)
@@ -14,6 +14,7 @@
 #    under the License.
 
 import fixtures
+import six
 import testtools
 
 from neutron.db import api as db_api
@@ -47,7 +48,10 @@ def create_request(path, body, content_type, method='GET',
     req.method = method
     req.headers = {}
     req.headers['Accept'] = content_type
-    req.body = body
+    if isinstance(body, six.text_type):
+        req.body = body.encode()
+    else:
+        req.body = body
     if context:
         req.environ['neutron.context'] = context
     return req