Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gcloud/storage/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def api_request(self, method, path, query_params=None,
content_type = response.get('content-type', '')
if not content_type.startswith('application/json'):
raise TypeError('Expected JSON, got %s' % content_type)
return json.loads(content)
return json.loads(content.decode('utf-8'))

return content

Expand Down
32 changes: 16 additions & 16 deletions gcloud/storage/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test__make_request_no_data_no_content_type_no_headers(self):
URI = 'http://example.com/test'
http = conn._http = Http(
{'status': '200', 'content-type': 'text/plain'},
'',
b'',
)
headers, content = conn._make_request('GET', URI)
self.assertEqual(headers['status'], '200')
Expand All @@ -128,7 +128,7 @@ def test__make_request_w_data_no_extra_headers(self):
URI = 'http://example.com/test'
http = conn._http = Http(
{'status': '200', 'content-type': 'text/plain'},
'',
b'',
)
conn._make_request('GET', URI, {}, 'application/json')
self.assertEqual(http._called_with['method'], 'GET')
Expand All @@ -148,7 +148,7 @@ def test__make_request_w_extra_headers(self):
URI = 'http://example.com/test'
http = conn._http = Http(
{'status': '200', 'content-type': 'text/plain'},
'',
b'',
)
conn._make_request('GET', URI, headers={'X-Foo': 'foo'})
self.assertEqual(http._called_with['method'], 'GET')
Expand All @@ -173,7 +173,7 @@ def test_api_request_defaults(self):
])
http = conn._http = Http(
{'status': '200', 'content-type': 'application/json'},
'{}',
b'{}',
)
self.assertEqual(conn.api_request('GET', PATH), {})
self.assertEqual(http._called_with['method'], 'GET')
Expand All @@ -191,7 +191,7 @@ def test_api_request_w_non_json_response(self):
conn = self._makeOne(PROJECT)
conn._http = Http(
{'status': '200', 'content-type': 'text/plain'},
'CONTENT',
b'CONTENT',
)

self.assertRaises(TypeError, conn.api_request, 'GET', '/')
Expand All @@ -201,7 +201,7 @@ def test_api_request_wo_json_expected(self):
conn = self._makeOne(PROJECT)
conn._http = Http(
{'status': '200', 'content-type': 'text/plain'},
'CONTENT',
b'CONTENT',
)
self.assertEqual(conn.api_request('GET', '/', expect_json=False),
'CONTENT')
Expand All @@ -213,7 +213,7 @@ def test_api_request_w_query_params(self):
conn = self._makeOne(PROJECT)
http = conn._http = Http(
{'status': '200', 'content-type': 'application/json'},
'{}',
b'{}',
)
self.assertEqual(conn.api_request('GET', '/', {'foo': 'bar'}), {})
self.assertEqual(http._called_with['method'], 'GET')
Expand Down Expand Up @@ -247,7 +247,7 @@ def test_api_request_w_data(self):
])
http = conn._http = Http(
{'status': '200', 'content-type': 'application/json'},
'{}',
b'{}',
)
self.assertEqual(conn.api_request('POST', '/', data=DATA), {})
self.assertEqual(http._called_with['method'], 'POST')
Expand All @@ -267,7 +267,7 @@ def test_api_request_w_404(self):
conn = self._makeOne(PROJECT)
conn._http = Http(
{'status': '404', 'content-type': 'text/plain'},
'{}'
b'{}',
)
self.assertRaises(NotFound, conn.api_request, 'GET', '/')

Expand All @@ -277,7 +277,7 @@ def test_api_request_w_500(self):
conn = self._makeOne(PROJECT)
conn._http = Http(
{'status': '500', 'content-type': 'text/plain'},
'{}',
b'{}',
)
self.assertRaises(InternalServerError, conn.api_request, 'GET', '/')

Expand All @@ -292,7 +292,7 @@ def test_get_all_buckets_empty(self):
])
http = conn._http = Http(
{'status': '200', 'content-type': 'application/json'},
'{}',
b'{}',
)
buckets = list(conn.get_all_buckets())
self.assertEqual(len(buckets), 0)
Expand All @@ -311,7 +311,7 @@ def test_get_all_buckets_non_empty(self):
])
http = conn._http = Http(
{'status': '200', 'content-type': 'application/json'},
'{"items": [{"name": "%s"}]}' % BUCKET_NAME,
b'{"items": [{"name": "%s"}]}' % BUCKET_NAME,
)
buckets = list(conn.get_all_buckets())
self.assertEqual(len(buckets), 1)
Expand All @@ -333,7 +333,7 @@ def test_get_bucket_miss(self):
])
http = conn._http = Http(
{'status': '404', 'content-type': 'application/json'},
'{}',
b'{}',
)
self.assertRaises(NotFound, conn.get_bucket, NONESUCH)
self.assertEqual(http._called_with['method'], 'GET')
Expand All @@ -353,7 +353,7 @@ def test_get_bucket_hit(self):
])
http = conn._http = Http(
{'status': '200', 'content-type': 'application/json'},
'{"name": "%s"}' % BLOB_NAME,
b'{"name": "%s"}' % BLOB_NAME,
)
bucket = conn.get_bucket(BLOB_NAME)
self.assertTrue(isinstance(bucket, Bucket))
Expand All @@ -375,7 +375,7 @@ def test_create_bucket_ok(self):
])
http = conn._http = Http(
{'status': '200', 'content-type': 'application/json'},
'{"name": "%s"}' % BLOB_NAME,
b'{"name": "%s"}' % BLOB_NAME,
)
bucket = conn.create_bucket(BLOB_NAME)
self.assertTrue(isinstance(bucket, Bucket))
Expand All @@ -399,7 +399,7 @@ def test_delete_bucket_defaults_miss(self):
])
http = conn._http = Http(
{'status': '200', 'content-type': 'application/json'},
'{}',
b'{}',
)

self.assertEqual(conn.delete_bucket(BLOB_NAME), None)
Expand Down