@@ -315,7 +315,69 @@ def test_download_with_checksum_mode_crc32(self):
315315 self .assertEqual (
316316 self .operations_called [1 ][1 ]['ChecksumMode' ], 'ENABLED'
317317 )
318-
318+
319+ def test_mv_no_overwrite_flag_when_object_not_exists_on_target (self ):
320+ """Testing mv when object doesnt exist using no-overwrite"""
321+ full_path = self .files .create_file ('foo.txt' , 'contents' )
322+ cmdline = f'{ self .prefix } { full_path } s3://bucket --no-overwrite'
323+ self .run_cmd (cmdline , expected_rc = 0 )
324+ # Verify putObject was called
325+ self .assertEqual (len (self .operations_called ),1 )
326+ self .assertEqual (self .operations_called [0 ][0 ].name , 'PutObject' )
327+ # Verify the IfNoneMatch condition was set in the request
328+ self .assertEqual (self .operations_called [0 ][1 ]['IfNoneMatch' ], '*' )
329+ # Verify source file was deleted (move operation)
330+ self .assertFalse (os .path .exists (full_path ))
331+
332+ def test_mv_no_overwrite_flag_when_object_exists_on_target (self ):
333+ """Testing mv when object already exists using no-overwrite"""
334+ full_path = self .files .create_file ('foo.txt' , 'mycontent' )
335+ cmdline = '%s %s s3://bucket/foo.txt --no-overwrite' % (self .prefix , full_path )
336+ # Set up the response to simulate a PreconditionFailed error
337+ self .http_response .status_code = 412
338+ self .parsed_responses = [
339+ {
340+ 'Error' : {
341+ 'Code' : 'PreconditionFailed' ,
342+ 'Message' : 'At least one of the pre-conditions you specified did not hold'
343+ }
344+ }
345+ ]
346+ stdout , stderr , rc = self .run_cmd (cmdline , expected_rc = 2 )
347+ # Verify PutObject was attempted with IfNoneMatch
348+ self .assertEqual (len (self .operations_called ), 1 )
349+ self .assertEqual (self .operations_called [0 ][0 ].name , 'PutObject' )
350+ self .assertEqual (self .operations_called [0 ][1 ]['IfNoneMatch' ], '*' )
351+ # Verify source file was not deleted
352+ self .assertTrue (os .path .exists (full_path ))
353+
354+ def test_mv_no_overwrite_flag_multipart_upload_when_object_not_exists_on_target (self ):
355+ """Testing mv multipart upload with no-overwrite flag when object doesn't exist"""
356+ # Create a large file that will trigger multipart upload
357+ full_path = self .files .create_file ('foo.txt' , 'a' * 10 * (1024 ** 2 ))
358+ cmdline = '%s %s s3://bucket/foo.txt --no-overwrite' % (self .prefix , full_path )
359+
360+ # Set up responses for multipart upload
361+ self .parsed_responses = [
362+ {'UploadId' : 'foo' }, # CreateMultipartUpload response
363+ {'ETag' : '"foo-1"' }, # UploadPart response
364+ {'ETag' : '"foo-2"' }, # UploadPart response
365+ {} # CompleteMultipartUpload response
366+ ]
367+
368+ self .run_cmd (cmdline , expected_rc = 0 )
369+
370+ # Verify all multipart operations were called
371+ self .assertEqual (len (self .operations_called ), 4 )
372+ self .assertEqual (self .operations_called [0 ][0 ].name , 'CreateMultipartUpload' )
373+ self .assertEqual (self .operations_called [1 ][0 ].name , 'UploadPart' )
374+ self .assertEqual (self .operations_called [2 ][0 ].name , 'UploadPart' )
375+ self .assertEqual (self .operations_called [3 ][0 ].name , 'CompleteMultipartUpload' )
376+
377+ # Verify the IfNoneMatch condition was set in the CompleteMultipartUpload request
378+ self .assertEqual (self .operations_called [3 ][1 ]['IfNoneMatch' ], '*' )
379+ # Verify source file was deleted (successful move operation)
380+ self .assertFalse (os .path .exists (full_path ))
319381
320382class TestMvWithCRTClient (BaseCRTTransferClientTest ):
321383 def test_upload_move_using_crt_client (self ):
0 commit comments