|
22 | 22 |
|
23 | 23 | __author__ = "[email protected] (Joe Gregorio)"
|
24 | 24 |
|
| 25 | +import io |
25 | 26 | import httplib2
|
26 | 27 | import json
|
27 | 28 | import pkg_resources
|
|
31 | 32 |
|
32 | 33 | import googleapiclient.model
|
33 | 34 |
|
34 |
| - |
35 | 35 | from googleapiclient.errors import HttpError
|
36 | 36 | from googleapiclient.model import JsonModel
|
37 | 37 |
|
38 | 38 | _LIBRARY_VERSION = pkg_resources.get_distribution("google-api-python-client").version
|
| 39 | +CSV_TEXT_MOCK = 'column1,column2,column3\nstring1,1.2,string2' |
39 | 40 |
|
40 | 41 |
|
41 | 42 | class Model(unittest.TestCase):
|
@@ -290,6 +291,24 @@ def test_no_data_wrapper_deserialize(self):
|
290 | 291 | content = model.response(resp, content)
|
291 | 292 | self.assertEqual(content, {"data": "is good"})
|
292 | 293 |
|
| 294 | + def test_no_data_wrapper_deserialize_text_format(self): |
| 295 | + model = JsonModel(data_wrapper=False) |
| 296 | + resp = httplib2.Response({"status": "200"}) |
| 297 | + resp.reason = "OK" |
| 298 | + content = CSV_TEXT_MOCK |
| 299 | + content = model.response(resp, content) |
| 300 | + self.assertEqual(content, CSV_TEXT_MOCK) |
| 301 | + |
| 302 | + def test_no_data_wrapper_deserialize_raise_type_error(self): |
| 303 | + buffer = io.StringIO() |
| 304 | + buffer.write('String buffer') |
| 305 | + model = JsonModel(data_wrapper=False) |
| 306 | + resp = httplib2.Response({"status": "500"}) |
| 307 | + resp.reason = "The JSON object must be str, bytes or bytearray, not StringIO" |
| 308 | + content = buffer |
| 309 | + with self.assertRaises(TypeError): |
| 310 | + model.response(resp, content) |
| 311 | + |
293 | 312 | def test_data_wrapper_deserialize(self):
|
294 | 313 | model = JsonModel(data_wrapper=True)
|
295 | 314 | resp = httplib2.Response({"status": "200"})
|
|
0 commit comments