Replace usages of os.rename with shutil.move to properly handle cases where the source and dest arent't on the same filesystem

This commit is contained in:
Trenton Holmes
2023-04-30 17:55:25 -07:00
committed by Trenton H
parent 613b71d23b
commit b7577038a0
4 changed files with 13 additions and 9 deletions

View File

@@ -697,7 +697,7 @@ class TestFileHandlingWithArchive(DirectoriesMixin, FileSystemAssertsMixin, Test
self.assertIsFile(doc.archive_path)
@override_settings(FILENAME_FORMAT="{correspondent}/{title}")
@mock.patch("documents.signals.handlers.os.rename")
@mock.patch("documents.signals.handlers.shutil.move")
def test_move_archive_error(self, m):
def fake_rename(src, dst):
if "archive" in str(src):
@@ -748,7 +748,7 @@ class TestFileHandlingWithArchive(DirectoriesMixin, FileSystemAssertsMixin, Test
self.assertIsFile(doc.archive_path)
@override_settings(FILENAME_FORMAT="{correspondent}/{title}")
@mock.patch("documents.signals.handlers.os.rename")
@mock.patch("documents.signals.handlers.shutil.move")
def test_move_file_error(self, m):
def fake_rename(src, dst):
if "original" in str(src):

View File

@@ -47,12 +47,16 @@ class TestMakeThumbnails(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
self.assertIsFile(self.d1.thumbnail_path)
@mock.patch("documents.management.commands.document_thumbnails.shutil.move")
def test_process_document_invalid_mime_type(self, m):
def test_process_document_invalid_mime_type(self, m: mock.Mock):
self.d1.mime_type = "asdasdasd"
self.d1.save()
# .save() triggers filename handling
m.reset_mock()
_process_document(self.d1.id)
# Not called during processing of document
m.assert_not_called()
def test_command(self):