Account for thumbnail deletion as well

This commit is contained in:
Daniel Quinn 2016-08-20 14:03:42 +01:00
parent f5daded930
commit 3bbcd562fc
2 changed files with 9 additions and 5 deletions

View File

@ -85,7 +85,8 @@ def run_post_consume_script(sender, document, **kwargs):
def cleanup_document_deletion(sender, instance, using, **kwargs):
for f in (instance.source_path, instance.thumbnail_path):
try:
os.unlink(instance.source_path)
os.unlink(f)
except FileNotFoundError:
pass # The file's already gone, so we're cool with it.

View File

@ -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)