Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v26.10.3

- Fixed an issue where renaming when uploading a file did not actually rename the file

## v26.10.2

- Add support for document libraries in Sharepoint
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "otf-addons-o365"
version = "v26.10.2"
version = "v26.10.3"
authors = [{ name = "Adam McDonagh", email = "adam@elitemonkey.net" }]
license = { text = "GPLv3" }
classifiers = [
Expand Down Expand Up @@ -46,7 +46,7 @@ dev = [
profile = 'black'

[tool.bumpver]
current_version = "v26.10.2"
current_version = "v26.10.3"
version_pattern = "vYY.WW.PATCH[-TAG]"
commit_message = "bump version {old_version} -> {new_version}"
commit = true
Expand Down
5 changes: 2 additions & 3 deletions src/opentaskpy/addons/o365/remotehandlers/sharepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,6 @@ def push_files_from_worker(
for file in files:
# Strip the directory from the file
file_name = file.split("/")[-1]
file_url = self.get_file_url_from_path(
self.spec["directory"] + "/" + file_name
)

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

file_url = self.get_file_url_from_path(file_name)

self.logger.info(
f"Uploading file: {file} to site {self.spec['siteName']} with path: {file_name}"
)
Expand Down
50 changes: 50 additions & 0 deletions tests/test_taskhandler_transfer_sharepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,56 @@ def test_local_to_sharepoint_transfer(tmpdir, o365_creds):
assert transfer_obj.run()


def test_local_to_sharepoint_with_file_rename(tmpdir, o365_creds):

task_definition = {
"type": "transfer",
"source": deepcopy(local_source_definition),
"destination": [deepcopy(sharepoint_destination_definition)],
}

task_definition = setup_creds_for_transfer(task_definition, o365_creds)

# Set the directory to the temp directory
task_definition["source"]["directory"] = tmpdir
task_definition["source"]["fileRegex"] = "^test.txt$"

random = randint(1000, 9999)

# Set the directory to the temp directory
task_definition["destination"][0]["rename"] = {
"pattern": "\\.txt$",
"sub": f".{random}",
}

# Create a file in the tmpdir
with open(f"{tmpdir}/test.txt", "w") as f:
f.write("test")

transfer_obj = transfer.Transfer(
None, "local-to-sharepoint-rename", task_definition
)

assert transfer_obj.run()

# Make sure that the file was renamed on Sharepoint
# Call the transfer obj again and use list files to get the files, we need to change the spec
# to point the source at the destination directory
transfer_obj = transfer.Transfer(None, "sharepoint-list-files", task_definition)

transfer_obj._set_remote_handlers()

files = transfer_obj.dest_remote_handlers[0].list_files(
task_definition["destination"][0]["directory"]
)
# Loop through files and assert that the file we expect is there and has been renamed
for file in files:
if file == f"test.{random}":
break

assert file == f"test.{random}"


def test_local_to_sharepoint_transfer_document_library(tmpdir, o365_creds):

task_definition = {
Expand Down
Loading