@@ -282,6 +282,56 @@ def test_local_to_sharepoint_transfer(tmpdir, o365_creds):
282282 assert transfer_obj .run ()
283283
284284
285+ def test_local_to_sharepoint_with_file_rename (tmpdir , o365_creds ):
286+
287+ task_definition = {
288+ "type" : "transfer" ,
289+ "source" : deepcopy (local_source_definition ),
290+ "destination" : [deepcopy (sharepoint_destination_definition )],
291+ }
292+
293+ task_definition = setup_creds_for_transfer (task_definition , o365_creds )
294+
295+ # Set the directory to the temp directory
296+ task_definition ["source" ]["directory" ] = tmpdir
297+ task_definition ["source" ]["fileRegex" ] = "^test.txt$"
298+
299+ random = randint (1000 , 9999 )
300+
301+ # Set the directory to the temp directory
302+ task_definition ["destination" ][0 ]["rename" ] = {
303+ "pattern" : "\\ .txt$" ,
304+ "sub" : f".{ random } " ,
305+ }
306+
307+ # Create a file in the tmpdir
308+ with open (f"{ tmpdir } /test.txt" , "w" ) as f :
309+ f .write ("test" )
310+
311+ transfer_obj = transfer .Transfer (
312+ None , "local-to-sharepoint-rename" , task_definition
313+ )
314+
315+ assert transfer_obj .run ()
316+
317+ # Make sure that the file was renamed on Sharepoint
318+ # Call the transfer obj again and use list files to get the files, we need to change the spec
319+ # to point the source at the destination directory
320+ transfer_obj = transfer .Transfer (None , "sharepoint-list-files" , task_definition )
321+
322+ transfer_obj ._set_remote_handlers ()
323+
324+ files = transfer_obj .dest_remote_handlers [0 ].list_files (
325+ task_definition ["destination" ][0 ]["directory" ]
326+ )
327+ # Loop through files and assert that the file we expect is there and has been renamed
328+ for file in files :
329+ if file == f"test.{ random } " :
330+ break
331+
332+ assert file == f"test.{ random } "
333+
334+
285335def test_local_to_sharepoint_transfer_document_library (tmpdir , o365_creds ):
286336
287337 task_definition = {
0 commit comments