Fix unicode issues in HttpError and BatchHttpRequest
1) HttpError parses http response by json.loads. It accepts only
unicode on PY3 while response is bytes. So decode response first.
2) BatchHttpRequest uses email.parser.FeedParser. It accepts only
unicode on PY3, too. So encode parsed response to emulate normal
http response.
diff --git a/tests/test_mocks.py b/tests/test_mocks.py
index 6ccc427..a456b9e 100644
--- a/tests/test_mocks.py
+++ b/tests/test_mocks.py
@@ -134,7 +134,7 @@
def test_errors(self):
errorResponse = httplib2.Response({'status': 500, 'reason': 'Server Error'})
requestBuilder = RequestMockBuilder({
- 'plus.activities.list': (errorResponse, '{}')
+ 'plus.activities.list': (errorResponse, b'{}')
})
plus = build('plus', 'v1', http=self.http, requestBuilder=requestBuilder)
@@ -142,7 +142,7 @@
activity = plus.activities().list(collection='public', userId='me').execute()
self.fail('An exception should have been thrown')
except HttpError as e:
- self.assertEqual('{}', e.content)
+ self.assertEqual(b'{}', e.content)
self.assertEqual(500, e.resp.status)
self.assertEqual('Server Error', e.resp.reason)