mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	fixed up a test case
This commit is contained in:
		@@ -1,12 +1,29 @@
 | 
			
		||||
import os
 | 
			
		||||
import shutil
 | 
			
		||||
import tempfile
 | 
			
		||||
from pathlib import Path
 | 
			
		||||
from unittest import mock
 | 
			
		||||
 | 
			
		||||
from django.test import TestCase
 | 
			
		||||
from django.test import TestCase, override_settings
 | 
			
		||||
 | 
			
		||||
from ..models import Document, Correspondent
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestDocument(TestCase):
 | 
			
		||||
 | 
			
		||||
    def setUp(self) -> None:
 | 
			
		||||
        self.originals_dir = tempfile.mkdtemp()
 | 
			
		||||
        self.thumb_dir = tempfile.mkdtemp()
 | 
			
		||||
 | 
			
		||||
        override_settings(
 | 
			
		||||
            ORIGINALS_DIR=self.originals_dir,
 | 
			
		||||
            THUMBNAIL_DIR=self.thumb_dir,
 | 
			
		||||
        ).enable()
 | 
			
		||||
 | 
			
		||||
    def tearDown(self) -> None:
 | 
			
		||||
        shutil.rmtree(self.originals_dir)
 | 
			
		||||
        shutil.rmtree(self.thumb_dir)
 | 
			
		||||
 | 
			
		||||
    def test_file_deletion(self):
 | 
			
		||||
        document = Document.objects.create(
 | 
			
		||||
            correspondent=Correspondent.objects.create(name="Test0"),
 | 
			
		||||
@@ -19,6 +36,9 @@ class TestDocument(TestCase):
 | 
			
		||||
        file_path = document.source_path
 | 
			
		||||
        thumb_path = document.thumbnail_path
 | 
			
		||||
 | 
			
		||||
        Path(file_path).touch()
 | 
			
		||||
        Path(thumb_path).touch()
 | 
			
		||||
 | 
			
		||||
        with mock.patch("documents.signals.handlers.os.unlink") as mock_unlink:
 | 
			
		||||
            document.delete()
 | 
			
		||||
            mock_unlink.assert_any_call(file_path)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user