From 3bbcd562fcae6f3948a9c6ca095e31211214eda1 Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Sat, 20 Aug 2016 14:03:42 +0100 Subject: [PATCH] Account for thumbnail deletion as well --- src/documents/signals/handlers.py | 9 +++++---- src/documents/tests/test_document_model.py | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py index f5fbe8527..666bcbeb3 100644 --- a/src/documents/signals/handlers.py +++ b/src/documents/signals/handlers.py @@ -85,7 +85,8 @@ def run_post_consume_script(sender, document, **kwargs): def cleanup_document_deletion(sender, instance, using, **kwargs): - try: - os.unlink(instance.source_path) - except FileNotFoundError: - pass # The file's already gone, so we're cool with it. + for f in (instance.source_path, instance.thumbnail_path): + try: + os.unlink(f) + except FileNotFoundError: + pass # The file's already gone, so we're cool with it. diff --git a/src/documents/tests/test_document_model.py b/src/documents/tests/test_document_model.py index f531f50bb..2da674527 100644 --- a/src/documents/tests/test_document_model.py +++ b/src/documents/tests/test_document_model.py @@ -15,6 +15,9 @@ class TestDocument(TestCase): checksum="checksum", ) file_path = document.source_path + thumb_path = document.thumbnail_path with mock.patch("documents.signals.handlers.os.unlink") as mock_unlink: document.delete() - mock_unlink.assert_called_with(file_path) + mock_unlink.assert_any_call(file_path) + mock_unlink.assert_any_call(thumb_path) + self.assertEqual(mock_unlink.call_count, 2)