@@ -315,13 +315,7 @@ def test_no_overwrite_flag_when_object_exists_on_target(self):
315315 # Set up the response to simulate a PreconditionFailed error
316316 self .http_response .status_code = 412
317317 self .parsed_responses = [
318- {
319- 'Error' : {
320- 'Code' : 'PreconditionFailed' ,
321- 'Message' : 'At least one of the pre-conditions you specified did not hold' ,
322- 'Condition' : 'If-None-Match' ,
323- }
324- }
318+ self .precondition_failed_error_response (),
325319 ]
326320 self .run_cmd (cmdline , expected_rc = 0 )
327321 # Verify PutObject was attempted with IfNoneMatch
@@ -367,13 +361,7 @@ def test_no_overwrite_flag_multipart_upload_when_object_exists_on_target(
367361 {'UploadId' : 'foo' }, # CreateMultipartUpload response
368362 {'ETag' : '"foo-1"' }, # UploadPart response
369363 {'ETag' : '"foo-2"' }, # UploadPart response
370- {
371- 'Error' : {
372- 'Code' : 'PreconditionFailed' ,
373- 'Message' : 'At least one of the pre-conditions you specified did not hold' ,
374- 'Condition' : 'If-None-Match' ,
375- }
376- }, # PreconditionFailed error for CompleteMultipart Upload
364+ self .precondition_failed_error_response (), # PreconditionFailed error for CompleteMultipart Upload
377365 {}, # AbortMultipartUpload response
378366 ]
379367 # Checking for success as file is skipped
@@ -550,6 +538,40 @@ def test_no_overwrite_flag_on_copy_when_large_object_does_not_exist_on_target(
550538 # Verify the IfNoneMatch condition was set in the CompleteMultipartUpload request
551539 self .assertEqual (self .operations_called [5 ][1 ]['IfNoneMatch' ], '*' )
552540
541+ def test_no_overwrite_flag_on_download_when_single_object_already_exists_at_target (
542+ self ,
543+ ):
544+ full_path = self .files .create_file ('foo.txt' , 'existing content' )
545+ cmdline = (
546+ f'{ self .prefix } s3://bucket/foo.txt { full_path } --no-overwrite'
547+ )
548+ self .parsed_responses = [
549+ self .head_object_response (),
550+ ]
551+ self .run_cmd (cmdline , expected_rc = 0 )
552+ self .assertEqual (len (self .operations_called ), 1 )
553+ self .assertEqual (self .operations_called [0 ][0 ].name , 'HeadObject' )
554+ with open (full_path ) as f :
555+ self .assertEqual (f .read (), 'existing content' )
556+
557+ def test_no_overwrite_flag_on_download_when_single_object_does_not_exist_at_target (
558+ self ,
559+ ):
560+ full_path = self .files .full_path ('foo.txt' )
561+ cmdline = (
562+ f'{ self .prefix } s3://bucket/foo.txt { full_path } --no-overwrite'
563+ )
564+ self .parsed_responses = [
565+ self .head_object_response (),
566+ self .get_object_response (),
567+ ]
568+ self .run_cmd (cmdline , expected_rc = 0 )
569+ self .assertEqual (len (self .operations_called ), 2 )
570+ self .assertEqual (self .operations_called [0 ][0 ].name , 'HeadObject' )
571+ self .assertEqual (self .operations_called [1 ][0 ].name , 'GetObject' )
572+ with open (full_path ) as f :
573+ self .assertEqual (f .read (), 'foo' )
574+
553575 def test_dryrun_download (self ):
554576 self .parsed_responses = [self .head_object_response ()]
555577 target = self .files .full_path ('file.txt' )
@@ -1428,6 +1450,15 @@ def test_streaming_download_error(self):
14281450 )
14291451 self .assertIn (error_message , stderr )
14301452
1453+ def test_no_overwrite_cannot_be_used_with_streaming_download (self ):
1454+ command = "s3 cp s3://bucket/streaming.txt - --no-overwrite"
1455+ _ , stderr , _ = self .run_cmd (command , expected_rc = 252 )
1456+ error_message = (
1457+ "--no-overwrite parameter is not supported for "
1458+ "streaming downloads"
1459+ )
1460+ self .assertIn (error_message , stderr )
1461+
14311462
14321463class TestCpCommandWithRequesterPayer (BaseCPCommandTest ):
14331464 def setUp (self ):
0 commit comments