@@ -161,12 +161,12 @@ def test__make_request_no_data_no_content_type_no_headers(self):
161
161
URI = 'http://example.com/test'
162
162
http = conn ._http = _Http (
163
163
{'status' : '200' , 'content-type' : 'text/plain' },
164
- '' ,
164
+ b '' ,
165
165
)
166
166
headers , content = conn ._make_request ('GET' , URI )
167
167
self .assertEqual (headers ['status' ], '200' )
168
168
self .assertEqual (headers ['content-type' ], 'text/plain' )
169
- self .assertEqual (content , '' )
169
+ self .assertEqual (content , b '' )
170
170
self .assertEqual (http ._called_with ['method' ], 'GET' )
171
171
self .assertEqual (http ._called_with ['uri' ], URI )
172
172
self .assertEqual (http ._called_with ['body' ], None )
@@ -182,7 +182,7 @@ def test__make_request_w_data_no_extra_headers(self):
182
182
URI = 'http://example.com/test'
183
183
http = conn ._http = _Http (
184
184
{'status' : '200' , 'content-type' : 'text/plain' },
185
- '' ,
185
+ b '' ,
186
186
)
187
187
conn ._make_request ('GET' , URI , {}, 'application/json' )
188
188
self .assertEqual (http ._called_with ['method' ], 'GET' )
@@ -201,7 +201,7 @@ def test__make_request_w_extra_headers(self):
201
201
URI = 'http://example.com/test'
202
202
http = conn ._http = _Http (
203
203
{'status' : '200' , 'content-type' : 'text/plain' },
204
- '' ,
204
+ b '' ,
205
205
)
206
206
conn ._make_request ('GET' , URI , headers = {'X-Foo' : 'foo' })
207
207
self .assertEqual (http ._called_with ['method' ], 'GET' )
@@ -226,7 +226,7 @@ def test_api_request_defaults(self):
226
226
])
227
227
http = conn ._http = _Http (
228
228
{'status' : '200' , 'content-type' : 'application/json' },
229
- '{}' ,
229
+ b '{}' ,
230
230
)
231
231
self .assertEqual (conn .api_request ('GET' , PATH ), {})
232
232
self .assertEqual (http ._called_with ['method' ], 'GET' )
@@ -243,7 +243,7 @@ def test_api_request_w_non_json_response(self):
243
243
conn = self ._makeMockOne ()
244
244
conn ._http = _Http (
245
245
{'status' : '200' , 'content-type' : 'text/plain' },
246
- 'CONTENT' ,
246
+ b 'CONTENT' ,
247
247
)
248
248
249
249
self .assertRaises (TypeError , conn .api_request , 'GET' , '/' )
@@ -252,18 +252,18 @@ def test_api_request_wo_json_expected(self):
252
252
conn = self ._makeMockOne ()
253
253
conn ._http = _Http (
254
254
{'status' : '200' , 'content-type' : 'text/plain' },
255
- 'CONTENT' ,
255
+ b 'CONTENT' ,
256
256
)
257
257
self .assertEqual (conn .api_request ('GET' , '/' , expect_json = False ),
258
- 'CONTENT' )
258
+ b 'CONTENT' )
259
259
260
260
def test_api_request_w_query_params (self ):
261
261
from six .moves .urllib .parse import parse_qsl
262
262
from six .moves .urllib .parse import urlsplit
263
263
conn = self ._makeMockOne ()
264
264
http = conn ._http = _Http (
265
265
{'status' : '200' , 'content-type' : 'application/json' },
266
- '{}' ,
266
+ b '{}' ,
267
267
)
268
268
self .assertEqual (conn .api_request ('GET' , '/' , {'foo' : 'bar' }), {})
269
269
self .assertEqual (http ._called_with ['method' ], 'GET' )
@@ -302,7 +302,7 @@ def test_api_request_w_data(self):
302
302
])
303
303
http = conn ._http = _Http (
304
304
{'status' : '200' , 'content-type' : 'application/json' },
305
- '{}' ,
305
+ b '{}' ,
306
306
)
307
307
self .assertEqual (conn .api_request ('POST' , '/' , data = DATA ), {})
308
308
self .assertEqual (http ._called_with ['method' ], 'POST' )
@@ -321,7 +321,7 @@ def test_api_request_w_404(self):
321
321
conn = self ._makeMockOne ()
322
322
conn ._http = _Http (
323
323
{'status' : '404' , 'content-type' : 'text/plain' },
324
- '{}'
324
+ b '{}'
325
325
)
326
326
self .assertRaises (NotFound , conn .api_request , 'GET' , '/' )
327
327
@@ -330,10 +330,35 @@ def test_api_request_w_500(self):
330
330
conn = self ._makeMockOne ()
331
331
conn ._http = _Http (
332
332
{'status' : '500' , 'content-type' : 'text/plain' },
333
- '{}' ,
333
+ b '{}' ,
334
334
)
335
335
self .assertRaises (InternalServerError , conn .api_request , 'GET' , '/' )
336
336
337
+ def test_api_request_non_binary_response (self ):
338
+ conn = self ._makeMockOne ()
339
+ http = conn ._http = _Http (
340
+ {'status' : '200' , 'content-type' : 'application/json' },
341
+ u'{}' ,
342
+ )
343
+ result = conn .api_request ('GET' , '/' )
344
+ # Intended to emulate self.mock_template
345
+ URI = '/' .join ([
346
+ conn .API_BASE_URL ,
347
+ 'mock' ,
348
+ conn .API_VERSION ,
349
+ '' ,
350
+ ])
351
+ self .assertEqual (result , {})
352
+ self .assertEqual (http ._called_with ['method' ], 'GET' )
353
+ self .assertEqual (http ._called_with ['uri' ], URI )
354
+ self .assertEqual (http ._called_with ['body' ], None )
355
+ expected_headers = {
356
+ 'Accept-Encoding' : 'gzip' ,
357
+ 'Content-Length' : 0 ,
358
+ 'User-Agent' : conn .USER_AGENT ,
359
+ }
360
+ self .assertEqual (http ._called_with ['headers' ], expected_headers )
361
+
337
362
338
363
class _Http (object ):
339
364
0 commit comments