@@ -1429,7 +1429,7 @@ def test_stream_file_already_complete_w_seekable_stream_unsynced(self):
14291429 with self .assertRaises (CommunicationError ):
14301430 upload .stream_file ()
14311431
1432- def test_stream_file_already_complete_w_seekable_stream_synced (self ):
1432+ def test_stream_file_already_complete_wo_seekable_method_synced (self ):
14331433 import os
14341434 from gcloud .streaming .transfer import RESUMABLE_UPLOAD
14351435 CONTENT = b'ABCDEFGHIJ'
@@ -1445,6 +1445,38 @@ def test_stream_file_already_complete_w_seekable_stream_synced(self):
14451445 upload ._complete = True
14461446 self .assertTrue (upload .stream_file (use_chunks = False ) is response )
14471447
1448+ def test_stream_file_already_complete_w_seekable_method_true_synced (self ):
1449+ import os
1450+ from gcloud .streaming .transfer import RESUMABLE_UPLOAD
1451+ CONTENT = b'ABCDEFGHIJ'
1452+ http = object ()
1453+ stream = _StreamWithSeekableMethod (CONTENT , True )
1454+ stream .seek (0 , os .SEEK_END )
1455+ response = object ()
1456+ upload = self ._makeOne (stream , chunksize = 1024 )
1457+ upload .strategy = RESUMABLE_UPLOAD
1458+ upload ._server_chunk_granularity = 128
1459+ upload ._initialize (http , _Request .URL )
1460+ upload ._final_response = response
1461+ upload ._complete = True
1462+ self .assertTrue (upload .stream_file (use_chunks = False ) is response )
1463+
1464+ def test_stream_file_already_complete_w_seekable_method_false (self ):
1465+ import os
1466+ from gcloud .streaming .transfer import RESUMABLE_UPLOAD
1467+ CONTENT = b'ABCDEFGHIJ'
1468+ http = object ()
1469+ stream = _StreamWithSeekableMethod (CONTENT , False )
1470+ stream .seek (0 , os .SEEK_END )
1471+ response = object ()
1472+ upload = self ._makeOne (stream , chunksize = 1024 )
1473+ upload .strategy = RESUMABLE_UPLOAD
1474+ upload ._server_chunk_granularity = 128
1475+ upload ._initialize (http , _Request .URL )
1476+ upload ._final_response = response
1477+ upload ._complete = True
1478+ self .assertTrue (upload .stream_file (use_chunks = False ) is response )
1479+
14481480 def test_stream_file_incomplete (self ):
14491481 from six .moves import http_client
14501482 from gcloud ._testing import _Monkey
@@ -1835,6 +1867,16 @@ def close(self):
18351867 self ._closed = True
18361868
18371869
1870+ class _StreamWithSeekableMethod (_Stream ):
1871+
1872+ def __init__ (self , to_read = b'' , seekable = True ):
1873+ super (_StreamWithSeekableMethod , self ).__init__ (to_read )
1874+ self ._seekable = seekable
1875+
1876+ def seekable (self ):
1877+ return self ._seekable
1878+
1879+
18381880class _Request (object ):
18391881 __slots__ = ('url' , 'http_method' , 'body' , 'headers' , 'loggable_body' )
18401882 URL = 'http://example.com/api'
0 commit comments