2121from botocore .exceptions import ClientError
2222
2323from s3transfer .compat import SOCKET_ERROR
24- from s3transfer .exceptions import RetriesExceededError , S3DownloadFailedError
24+ from s3transfer .exceptions import RetriesExceededError
2525from s3transfer .manager import TransferConfig , TransferManager
2626from tests import (
2727 BaseGeneralInterfaceTest ,
@@ -48,7 +48,6 @@ def setUp(self):
4848 # Initialize some default arguments
4949 self .bucket = 'mybucket'
5050 self .key = 'mykey'
51- self .etag = 'myetag'
5251 self .extra_args = {}
5352 self .subscribers = []
5453
@@ -85,10 +84,7 @@ def create_stubbed_responses(self):
8584 return [
8685 {
8786 'method' : 'head_object' ,
88- 'service_response' : {
89- 'ContentLength' : len (self .content ),
90- 'ETag' : self .etag ,
91- },
87+ 'service_response' : {'ContentLength' : len (self .content )},
9288 },
9389 {
9490 'method' : 'get_object' ,
@@ -295,7 +291,6 @@ def test_retry_rewinds_callbacks(self):
295291 self .assertEqual (- 3 , progress_byte_amts [1 ])
296292
297293 def test_can_provide_file_size (self ):
298- self .add_head_object_response ()
299294 self .add_successful_get_object_responses ()
300295
301296 call_kwargs = self .create_call_kwargs ()
@@ -304,6 +299,8 @@ def test_can_provide_file_size(self):
304299 future = self .manager .download (** call_kwargs )
305300 future .result ()
306301
302+ # The HeadObject should have not happened and should have been able
303+ # to successfully download the file.
307304 self .stubber .assert_no_pending_responses ()
308305 with open (self .filename , 'rb' ) as f :
309306 self .assertEqual (self .content , f .read ())
@@ -472,10 +469,7 @@ def create_stubbed_responses(self):
472469 return [
473470 {
474471 'method' : 'head_object' ,
475- 'service_response' : {
476- 'ContentLength' : len (self .content ),
477- 'ETag' : self .etag ,
478- },
472+ 'service_response' : {'ContentLength' : len (self .content )},
479473 },
480474 {
481475 'method' : 'get_object' ,
@@ -508,7 +502,7 @@ def test_download(self):
508502 expected_ranges = ['bytes=0-3' , 'bytes=4-7' , 'bytes=8-' ]
509503 self .add_head_object_response (expected_params )
510504 self .add_successful_get_object_responses (
511- { ** expected_params , 'IfMatch' : self . etag } , expected_ranges
505+ expected_params , expected_ranges
512506 )
513507
514508 future = self .manager .download (
@@ -529,76 +523,6 @@ def test_download_with_checksum_enabled(self):
529523 }
530524 expected_ranges = ['bytes=0-3' , 'bytes=4-7' , 'bytes=8-' ]
531525 self .add_head_object_response (expected_params )
532- self .add_successful_get_object_responses (
533- {** expected_params , 'IfMatch' : self .etag }, expected_ranges
534- )
535-
536- future = self .manager .download (
537- self .bucket , self .key , self .filename , self .extra_args
538- )
539- future .result ()
540-
541- # Ensure that the contents are correct
542- with open (self .filename , 'rb' ) as f :
543- self .assertEqual (self .content , f .read ())
544-
545- def test_download_raises_if_etag_validation_fails (self ):
546- expected_params = {
547- 'Bucket' : self .bucket ,
548- 'Key' : self .key ,
549- }
550- expected_ranges = ['bytes=0-3' , 'bytes=4-7' ]
551- self .add_head_object_response (expected_params )
552-
553- # Add successful GetObject responses for the first 2 requests.
554- for i , stubbed_response in enumerate (
555- self .create_stubbed_responses ()[1 :3 ]
556- ):
557- stubbed_response ['expected_params' ] = copy .deepcopy (
558- {** expected_params , 'IfMatch' : self .etag }
559- )
560- stubbed_response ['expected_params' ]['Range' ] = expected_ranges [i ]
561- self .stubber .add_response (** stubbed_response )
562-
563- # Simulate ETag validation failure by adding a
564- # client error for the last GetObject request.
565- self .stubber .add_client_error (
566- method = 'get_object' ,
567- service_error_code = 'PreconditionFailed' ,
568- service_message = (
569- 'At least one of the pre-conditions you specified did not hold'
570- ),
571- http_status_code = 412 ,
572- )
573-
574- future = self .manager .download (
575- self .bucket , self .key , self .filename , self .extra_args
576- )
577- with self .assertRaises (S3DownloadFailedError ) as e :
578- future .result ()
579- self .assertIn ('did not match expected ETag' , str (e .exception ))
580-
581- # Ensure no data is written to disk.
582- self .assertFalse (os .path .exists (self .filename ))
583-
584- def test_download_without_etag (self ):
585- expected_params = {
586- 'Bucket' : self .bucket ,
587- 'Key' : self .key ,
588- }
589- expected_ranges = ['bytes=0-3' , 'bytes=4-7' , 'bytes=8-' ]
590-
591- # Stub HeadObject response with no ETag
592- head_object_response = {
593- 'method' : 'head_object' ,
594- 'service_response' : {
595- 'ContentLength' : len (self .content ),
596- },
597- 'expected_params' : expected_params ,
598- }
599- self .stubber .add_response (** head_object_response )
600-
601- # This asserts that IfMatch isn't in the GetObject requests.
602526 self .add_successful_get_object_responses (
603527 expected_params , expected_ranges
604528 )
0 commit comments