Merge "Python3: httpretty.last_request().body is now bytes"

This commit is contained in:
Jenkins
2014-02-08 23:25:18 +00:00
committed by Gerrit Code Review
4 changed files with 17 additions and 5 deletions

View File

@@ -116,7 +116,7 @@ class ClientTest(utils.TestCase):
cl.post("/hi", body=[1, 2, 3]) cl.post("/hi", body=[1, 2, 3])
self.assertEqual(httpretty.last_request().method, 'POST') self.assertEqual(httpretty.last_request().method, 'POST')
self.assertEqual(httpretty.last_request().body, '[1, 2, 3]') self.assertEqual(httpretty.last_request().body, b'[1, 2, 3]')
self.assertRequestHeaderEqual('X-Auth-Token', 'token') self.assertRequestHeaderEqual('X-Auth-Token', 'token')
self.assertRequestHeaderEqual('Content-Type', 'application/json') self.assertRequestHeaderEqual('Content-Type', 'application/json')

View File

@@ -65,11 +65,15 @@ class TestCase(testtools.TestCase):
httpretty.register_uri(method, url, **kwargs) httpretty.register_uri(method, url, **kwargs)
def assertRequestBodyIs(self, body=None, json=None): def assertRequestBodyIs(self, body=None, json=None):
last_request_body = httpretty.last_request().body
if six.PY3:
last_request_body = last_request_body.decode('utf-8')
if json: if json:
val = jsonutils.loads(httpretty.last_request().body) val = jsonutils.loads(last_request_body)
self.assertEqual(json, val) self.assertEqual(json, val)
elif body: elif body:
self.assertEqual(body, httpretty.last_request().body) self.assertEqual(body, last_request_body)
def assertQueryStringIs(self, qs=''): def assertQueryStringIs(self, qs=''):
"""Verify the QueryString matches what is expected. """Verify the QueryString matches what is expected.

View File

@@ -16,6 +16,7 @@ import datetime
import json import json
import httpretty import httpretty
import six
from keystoneclient import exceptions from keystoneclient import exceptions
from keystoneclient.openstack.common import jsonutils from keystoneclient.openstack.common import jsonutils
@@ -170,7 +171,10 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
cl = client.Client(auth_url=self.TEST_URL, cl = client.Client(auth_url=self.TEST_URL,
token=fake_token) token=fake_token)
body = jsonutils.loads(httpretty.last_request().body) body = httpretty.last_request().body
if six.PY3:
body = body.decode('utf-8')
body = jsonutils.loads(body)
self.assertEqual(body['auth']['token']['id'], fake_token) self.assertEqual(body['auth']['token']['id'], fake_token)
resp, body = cl.get(fake_url) resp, body = cl.get(fake_url)

View File

@@ -13,6 +13,7 @@
# under the License. # under the License.
import httpretty import httpretty
import six
from keystoneclient import exceptions from keystoneclient import exceptions
from keystoneclient.openstack.common import jsonutils from keystoneclient.openstack.common import jsonutils
@@ -237,7 +238,10 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
cl = client.Client(auth_url=self.TEST_URL, cl = client.Client(auth_url=self.TEST_URL,
token=fake_token) token=fake_token)
body = jsonutils.loads(httpretty.last_request().body) body = httpretty.last_request().body
if six.PY3:
body = body.decode('utf-8')
body = jsonutils.loads(body)
self.assertEqual(body['auth']['identity']['token']['id'], fake_token) self.assertEqual(body['auth']['identity']['token']['id'], fake_token)
resp, body = cl.get(fake_url) resp, body = cl.get(fake_url)