@@ -260,7 +260,7 @@ def test_generate_signed_url_w_method_arg(self):
260
260
def test_exists_miss (self ):
261
261
from six .moves .http_client import NOT_FOUND
262
262
NONESUCH = 'nonesuch'
263
- not_found_response = {'status' : NOT_FOUND }
263
+ not_found_response = ( {'status' : NOT_FOUND }, b'' )
264
264
connection = _Connection (not_found_response )
265
265
client = _Client (connection )
266
266
bucket = _Bucket (client )
@@ -270,7 +270,7 @@ def test_exists_miss(self):
270
270
def test_exists_hit (self ):
271
271
from six .moves .http_client import OK
272
272
BLOB_NAME = 'blob-name'
273
- found_response = {'status' : OK }
273
+ found_response = ( {'status' : OK }, b'' )
274
274
connection = _Connection (found_response )
275
275
client = _Client (connection )
276
276
bucket = _Bucket (client )
@@ -281,7 +281,7 @@ def test_exists_hit(self):
281
281
def test_delete (self ):
282
282
from six .moves .http_client import NOT_FOUND
283
283
BLOB_NAME = 'blob-name'
284
- not_found_response = {'status' : NOT_FOUND }
284
+ not_found_response = ( {'status' : NOT_FOUND }, b'' )
285
285
connection = _Connection (not_found_response )
286
286
client = _Client (connection )
287
287
bucket = _Bucket (client )
@@ -291,6 +291,32 @@ def test_delete(self):
291
291
self .assertFalse (blob .exists ())
292
292
self .assertEqual (bucket ._deleted , [(BLOB_NAME , None )])
293
293
294
+ def test_download_to_file_wo_media_link (self ):
295
+ from six .moves .http_client import OK
296
+ from six .moves .http_client import PARTIAL_CONTENT
297
+ from io import BytesIO
298
+ BLOB_NAME = 'blob-name'
299
+ MEDIA_LINK = 'http://example.com/media/'
300
+ chunk1_response = {'status' : PARTIAL_CONTENT ,
301
+ 'content-range' : 'bytes 0-2/6' }
302
+ chunk2_response = {'status' : OK ,
303
+ 'content-range' : 'bytes 3-5/6' }
304
+ connection = _Connection (
305
+ (chunk1_response , b'abc' ),
306
+ (chunk2_response , b'def' ),
307
+ )
308
+ # Only the 'reload' request hits on this side: the others are done
309
+ # through the 'http' object.
310
+ reload_response = {'status' : OK , 'content-type' : 'application/json' }
311
+ connection ._responses = [(reload_response , {"mediaLink" : MEDIA_LINK })]
312
+ client = _Client (connection )
313
+ bucket = _Bucket (client )
314
+ blob = self ._makeOne (BLOB_NAME , bucket = bucket )
315
+ fh = BytesIO ()
316
+ blob .download_to_file (fh )
317
+ self .assertEqual (fh .getvalue (), b'abcdef' )
318
+ self .assertEqual (blob .media_link , MEDIA_LINK )
319
+
294
320
def _download_to_file_helper (self , chunk_size = None ):
295
321
from six .moves .http_client import OK
296
322
from six .moves .http_client import PARTIAL_CONTENT
@@ -749,10 +775,11 @@ def test_upload_from_string_w_text(self):
749
775
self .assertEqual (rq [0 ]['body' ], ENCODED )
750
776
751
777
def test_make_public (self ):
778
+ from six .moves .http_client import OK
752
779
from gcloud .storage .acl import _ACLEntity
753
780
BLOB_NAME = 'blob-name'
754
781
permissive = [{'entity' : 'allUsers' , 'role' : _ACLEntity .READER_ROLE }]
755
- after = { ' acl' : permissive }
782
+ after = ({ 'status' : OK }, { ' acl' : permissive })
756
783
connection = _Connection (after )
757
784
client = _Client (connection )
758
785
bucket = _Bucket (client = client )
@@ -1092,10 +1119,10 @@ def __init__(self, *responses):
1092
1119
def api_request (self , ** kw ):
1093
1120
from six .moves .http_client import NOT_FOUND
1094
1121
from gcloud .exceptions import NotFound
1095
- result = self ._respond (** kw )
1096
- if result .get ('status' ) == NOT_FOUND :
1097
- raise NotFound (result )
1098
- return result
1122
+ info , content = self ._respond (** kw )
1123
+ if info .get ('status' ) == NOT_FOUND :
1124
+ raise NotFound (info )
1125
+ return content
1099
1126
1100
1127
def build_api_url (self , path , query_params = None ,
1101
1128
api_base_url = API_BASE_URL ):
0 commit comments