@@ -69,6 +69,41 @@ def test_ctor_explicit(self):
6969 self .assertFalse (blob ._acl .loaded )
7070 self .assertTrue (blob ._acl .blob is blob )
7171
72+ def test_chunk_size_ctor (self ):
73+ from gcloud .storage .blob import Blob
74+ BLOB_NAME = 'blob-name'
75+ BUCKET = object ()
76+ chunk_size = 10 * Blob ._CHUNK_SIZE_MULTIPLE
77+ blob = self ._makeOne (BLOB_NAME , bucket = BUCKET , chunk_size = chunk_size )
78+ self .assertEqual (blob ._chunk_size , chunk_size )
79+
80+ def test_chunk_size_getter (self ):
81+ BLOB_NAME = 'blob-name'
82+ BUCKET = object ()
83+ blob = self ._makeOne (BLOB_NAME , bucket = BUCKET )
84+ self .assertEqual (blob .chunk_size , None )
85+ VALUE = object ()
86+ blob ._chunk_size = VALUE
87+ self .assertTrue (blob .chunk_size is VALUE )
88+
89+ def test_chunk_size_setter (self ):
90+ BLOB_NAME = 'blob-name'
91+ BUCKET = object ()
92+ blob = self ._makeOne (BLOB_NAME , bucket = BUCKET )
93+ self .assertEqual (blob ._chunk_size , None )
94+ blob ._CHUNK_SIZE_MULTIPLE = 10
95+ blob .chunk_size = 20
96+ self .assertEqual (blob ._chunk_size , 20 )
97+
98+ def test_chunk_size_setter_bad_value (self ):
99+ BLOB_NAME = 'blob-name'
100+ BUCKET = object ()
101+ blob = self ._makeOne (BLOB_NAME , bucket = BUCKET )
102+ self .assertEqual (blob ._chunk_size , None )
103+ blob ._CHUNK_SIZE_MULTIPLE = 10
104+ with self .assertRaises (ValueError ):
105+ blob .chunk_size = 11
106+
72107 def test_acl_property (self ):
73108 from gcloud .storage .acl import ObjectACL
74109 FAKE_BUCKET = _Bucket (None )
@@ -242,7 +277,7 @@ def test_delete(self):
242277 blob .delete ()
243278 self .assertFalse (blob .exists ())
244279
245- def test_download_to_file (self ):
280+ def _download_to_file_helper (self , chunk_size = None ):
246281 from six .moves .http_client import OK
247282 from six .moves .http_client import PARTIAL_CONTENT
248283 from io import BytesIO
@@ -259,11 +294,19 @@ def test_download_to_file(self):
259294 MEDIA_LINK = 'http://example.com/media/'
260295 properties = {'mediaLink' : MEDIA_LINK }
261296 blob = self ._makeOne (BLOB_NAME , bucket = bucket , properties = properties )
262- blob .CHUNK_SIZE = 3
297+ if chunk_size is not None :
298+ blob ._CHUNK_SIZE_MULTIPLE = 1
299+ blob .chunk_size = chunk_size
263300 fh = BytesIO ()
264301 blob .download_to_file (fh )
265302 self .assertEqual (fh .getvalue (), b'abcdef' )
266303
304+ def test_download_to_file_default (self ):
305+ self ._download_to_file_helper ()
306+
307+ def test_download_to_file_with_chunk_size (self ):
308+ self ._download_to_file_helper (chunk_size = 3 )
309+
267310 def test_download_to_filename (self ):
268311 import os
269312 import time
@@ -284,7 +327,8 @@ def test_download_to_filename(self):
284327 properties = {'mediaLink' : MEDIA_LINK ,
285328 'updated' : '2014-12-06T13:13:50.690Z' }
286329 blob = self ._makeOne (BLOB_NAME , bucket = bucket , properties = properties )
287- blob .CHUNK_SIZE = 3
330+ blob ._CHUNK_SIZE_MULTIPLE = 1
331+ blob .chunk_size = 3
288332 with NamedTemporaryFile () as f :
289333 blob .download_to_filename (f .name )
290334 f .flush ()
@@ -311,7 +355,8 @@ def test_download_as_string(self):
311355 MEDIA_LINK = 'http://example.com/media/'
312356 properties = {'mediaLink' : MEDIA_LINK }
313357 blob = self ._makeOne (BLOB_NAME , bucket = bucket , properties = properties )
314- blob .CHUNK_SIZE = 3
358+ blob ._CHUNK_SIZE_MULTIPLE = 1
359+ blob .chunk_size = 3
315360 fetched = blob .download_as_string ()
316361 self .assertEqual (fetched , b'abcdef' )
317362
@@ -330,7 +375,8 @@ def _upload_from_file_simple_test_helper(self, properties=None,
330375 )
331376 bucket = _Bucket (connection )
332377 blob = self ._makeOne (BLOB_NAME , bucket = bucket , properties = properties )
333- blob .CHUNK_SIZE = 5
378+ blob ._CHUNK_SIZE_MULTIPLE = 1
379+ blob .chunk_size = 5
334380 with NamedTemporaryFile () as fh :
335381 fh .write (DATA )
336382 fh .flush ()
@@ -398,7 +444,8 @@ def test_upload_from_file_resumable(self):
398444 )
399445 bucket = _Bucket (connection )
400446 blob = self ._makeOne (BLOB_NAME , bucket = bucket )
401- blob .CHUNK_SIZE = 5
447+ blob ._CHUNK_SIZE_MULTIPLE = 1
448+ blob .chunk_size = 5
402449 # Set the threshhold low enough that we force a resumable uploada.
403450 with _Monkey (transfer , _RESUMABLE_UPLOAD_THRESHOLD = 5 ):
404451 with NamedTemporaryFile () as fh :
@@ -455,7 +502,8 @@ def test_upload_from_file_w_slash_in_name(self):
455502 )
456503 bucket = _Bucket (connection )
457504 blob = self ._makeOne (BLOB_NAME , bucket = bucket )
458- blob .CHUNK_SIZE = 5
505+ blob ._CHUNK_SIZE_MULTIPLE = 1
506+ blob .chunk_size = 5
459507 with NamedTemporaryFile () as fh :
460508 fh .write (DATA )
461509 fh .flush ()
@@ -502,7 +550,8 @@ def _upload_from_filename_test_helper(self, properties=None,
502550 bucket = _Bucket (connection )
503551 blob = self ._makeOne (BLOB_NAME , bucket = bucket ,
504552 properties = properties )
505- blob .CHUNK_SIZE = 5
553+ blob ._CHUNK_SIZE_MULTIPLE = 1
554+ blob .chunk_size = 5
506555 with NamedTemporaryFile (suffix = '.jpeg' ) as fh :
507556 fh .write (DATA )
508557 fh .flush ()
@@ -565,7 +614,8 @@ def test_upload_from_string_w_bytes(self):
565614 )
566615 bucket = _Bucket (connection )
567616 blob = self ._makeOne (BLOB_NAME , bucket = bucket )
568- blob .CHUNK_SIZE = 5
617+ blob ._CHUNK_SIZE_MULTIPLE = 1
618+ blob .chunk_size = 5
569619 blob .upload_from_string (DATA )
570620 rq = connection .http ._requested
571621 self .assertEqual (len (rq ), 1 )
@@ -603,7 +653,8 @@ def test_upload_from_string_w_text(self):
603653 )
604654 bucket = _Bucket (connection )
605655 blob = self ._makeOne (BLOB_NAME , bucket = bucket )
606- blob .CHUNK_SIZE = 5
656+ blob ._CHUNK_SIZE_MULTIPLE = 1
657+ blob .chunk_size = 5
607658 blob .upload_from_string (DATA )
608659 rq = connection .http ._requested
609660 self .assertEqual (len (rq ), 1 )
0 commit comments