paperless-ngx/src/documents/tests/test_document_model.py

27 lines
785 B
Python
Raw Normal View History

from unittest import mock
from django.test import TestCase
from ..models import Document, Correspondent
class TestDocument(TestCase):
def test_file_deletion(self):
document = Document.objects.create(
correspondent=Correspondent.objects.create(name="Test0"),
title="Title",
content="content",
checksum="checksum",
2020-11-20 13:31:03 +01:00
mime_type="application/pdf"
)
2020-11-20 13:31:03 +01:00
file_path = document.source_path
2016-08-20 14:03:42 +01:00
thumb_path = document.thumbnail_path
2020-11-20 13:31:03 +01:00
with mock.patch("documents.signals.handlers.os.unlink") as mock_unlink:
document.delete()
2016-08-20 14:03:42 +01:00
mock_unlink.assert_any_call(file_path)
mock_unlink.assert_any_call(thumb_path)
self.assertEqual(mock_unlink.call_count, 2)