Skip to content

Commit e2947e3

Browse files
authored
Fix rename bug in file upload process (#16)
* Fix rename bug * bump version v26.10.2 -> v26.10.3
1 parent a5ba093 commit e2947e3

4 files changed

Lines changed: 58 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v26.10.3
4+
5+
- Fixed an issue where renaming when uploading a file did not actually rename the file
6+
37
## v26.10.2
48

59
- Add support for document libraries in Sharepoint

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "otf-addons-o365"
7-
version = "v26.10.2"
7+
version = "v26.10.3"
88
authors = [{ name = "Adam McDonagh", email = "adam@elitemonkey.net" }]
99
license = { text = "GPLv3" }
1010
classifiers = [
@@ -46,7 +46,7 @@ dev = [
4646
profile = 'black'
4747

4848
[tool.bumpver]
49-
current_version = "v26.10.2"
49+
current_version = "v26.10.3"
5050
version_pattern = "vYY.WW.PATCH[-TAG]"
5151
commit_message = "bump version {old_version} -> {new_version}"
5252
commit = true

src/opentaskpy/addons/o365/remotehandlers/sharepoint.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,6 @@ def push_files_from_worker(
431431
for file in files:
432432
# Strip the directory from the file
433433
file_name = file.split("/")[-1]
434-
file_url = self.get_file_url_from_path(
435-
self.spec["directory"] + "/" + file_name
436-
)
437434

438435
# Handle any rename that might be specified in the spec
439436
if "rename" in self.spec:
@@ -447,6 +444,8 @@ def push_files_from_worker(
447444
if "directory" in self.spec:
448445
file_name = f"{self.spec['directory']}/{file_name}"
449446

447+
file_url = self.get_file_url_from_path(file_name)
448+
450449
self.logger.info(
451450
f"Uploading file: {file} to site {self.spec['siteName']} with path: {file_name}"
452451
)

tests/test_taskhandler_transfer_sharepoint.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
285335
def test_local_to_sharepoint_transfer_document_library(tmpdir, o365_creds):
286336

287337
task_definition = {

0 commit comments

Comments
 (0)