mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	more tests
This commit is contained in:
		@@ -13,18 +13,18 @@ writeable_hint = (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def path_check(env_var):
 | 
			
		||||
def path_check(var, directory):
 | 
			
		||||
    messages = []
 | 
			
		||||
    directory = os.getenv(env_var)
 | 
			
		||||
    print(directory)
 | 
			
		||||
    if directory:
 | 
			
		||||
        if not os.path.exists(directory):
 | 
			
		||||
            messages.append(Error(
 | 
			
		||||
                exists_message.format(env_var),
 | 
			
		||||
                exists_message.format(var),
 | 
			
		||||
                exists_hint.format(directory)
 | 
			
		||||
            ))
 | 
			
		||||
        elif not os.access(directory, os.W_OK | os.X_OK):
 | 
			
		||||
            messages.append(Error(
 | 
			
		||||
                writeable_message.format(env_var),
 | 
			
		||||
                writeable_message.format(var),
 | 
			
		||||
                writeable_hint.format(directory)
 | 
			
		||||
            ))
 | 
			
		||||
    return messages
 | 
			
		||||
@@ -36,10 +36,10 @@ def paths_check(app_configs, **kwargs):
 | 
			
		||||
    Check the various paths for existence, readability and writeability
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    check_messages = path_check("PAPERLESS_DATA_DIR") + \
 | 
			
		||||
        path_check("PAPERLESS_MEDIA_ROOT") + \
 | 
			
		||||
        path_check("PAPERLESS_CONSUMPTION_DIR") + \
 | 
			
		||||
        path_check("PAPERLESS_STATICDIR")
 | 
			
		||||
    check_messages = path_check("PAPERLESS_DATA_DIR", settings.DATA_DIR) + \
 | 
			
		||||
        path_check("PAPERLESS_MEDIA_ROOT", settings.MEDIA_ROOT) + \
 | 
			
		||||
        path_check("PAPERLESS_CONSUMPTION_DIR", settings.CONSUMPTION_DIR) + \
 | 
			
		||||
        path_check("PAPERLESS_STATICDIR", settings.STATIC_ROOT)
 | 
			
		||||
 | 
			
		||||
    return check_messages
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										55
									
								
								src/paperless/tests/test_checks.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								src/paperless/tests/test_checks.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
import os
 | 
			
		||||
import shutil
 | 
			
		||||
 | 
			
		||||
from django.test import TestCase, override_settings
 | 
			
		||||
 | 
			
		||||
from documents.tests.utils import DirectoriesMixin
 | 
			
		||||
from paperless import binaries_check, paths_check
 | 
			
		||||
from paperless.checks import debug_mode_check
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestChecks(DirectoriesMixin, TestCase):
 | 
			
		||||
 | 
			
		||||
    def test_binaries(self):
 | 
			
		||||
        self.assertEqual(binaries_check(None), [])
 | 
			
		||||
 | 
			
		||||
    @override_settings(CONVERT_BINARY="uuuhh", OPTIPNG_BINARY="forgot")
 | 
			
		||||
    def test_binaries_fail(self):
 | 
			
		||||
        self.assertEqual(len(binaries_check(None)), 2)
 | 
			
		||||
 | 
			
		||||
    def test_paths_check(self):
 | 
			
		||||
        self.assertEqual(paths_check(None), [])
 | 
			
		||||
 | 
			
		||||
    @override_settings(MEDIA_ROOT="uuh",
 | 
			
		||||
                       STATIC_ROOT="somewhere",
 | 
			
		||||
                       DATA_DIR="whatever",
 | 
			
		||||
                       CONSUMPTION_DIR="idontcare")
 | 
			
		||||
    def test_paths_check_dont_exist(self):
 | 
			
		||||
        msgs = paths_check(None)
 | 
			
		||||
        self.assertEqual(len(msgs), 4)
 | 
			
		||||
 | 
			
		||||
        for msg in msgs:
 | 
			
		||||
            self.assertTrue(msg.msg.endswith("is set but doesn't exist."))
 | 
			
		||||
 | 
			
		||||
    def test_paths_check_no_access(self):
 | 
			
		||||
        os.chmod(self.dirs.data_dir, 0o000)
 | 
			
		||||
        os.chmod(self.dirs.media_dir, 0o000)
 | 
			
		||||
        os.chmod(self.dirs.consumption_dir, 0o000)
 | 
			
		||||
 | 
			
		||||
        self.addCleanup(os.chmod, self.dirs.data_dir, 0o777)
 | 
			
		||||
        self.addCleanup(os.chmod, self.dirs.media_dir, 0o777)
 | 
			
		||||
        self.addCleanup(os.chmod, self.dirs.consumption_dir, 0o777)
 | 
			
		||||
 | 
			
		||||
        msgs = paths_check(None)
 | 
			
		||||
        self.assertEqual(len(msgs), 3)
 | 
			
		||||
 | 
			
		||||
        for msg in msgs:
 | 
			
		||||
            self.assertTrue(msg.msg.endswith("is not writeable"))
 | 
			
		||||
 | 
			
		||||
    @override_settings(DEBUG=False)
 | 
			
		||||
    def test_debug_disabled(self):
 | 
			
		||||
        self.assertEqual(debug_mode_check(None), [])
 | 
			
		||||
 | 
			
		||||
    @override_settings(DEBUG=True)
 | 
			
		||||
    def test_debug_enabled(self):
 | 
			
		||||
        self.assertEqual(len(debug_mode_check(None)), 1)
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
import subprocess
 | 
			
		||||
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.core.checks import Error, register
 | 
			
		||||
from django.core.checks import Error, Warning, register
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_tesseract_langs():
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								src/paperless_tesseract/tests/test_checks.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/paperless_tesseract/tests/test_checks.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
from unittest import mock
 | 
			
		||||
 | 
			
		||||
from django.core.checks import ERROR
 | 
			
		||||
from django.test import TestCase, override_settings
 | 
			
		||||
 | 
			
		||||
from paperless_tesseract import check_default_language_available
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestChecks(TestCase):
 | 
			
		||||
 | 
			
		||||
    def test_default_language(self):
 | 
			
		||||
        msgs = check_default_language_available(None)
 | 
			
		||||
 | 
			
		||||
    @override_settings(OCR_LANGUAGE="")
 | 
			
		||||
    def test_no_language(self):
 | 
			
		||||
        msgs = check_default_language_available(None)
 | 
			
		||||
        self.assertEqual(len(msgs), 1)
 | 
			
		||||
        self.assertTrue(msgs[0].msg.startswith("No OCR language has been specified with PAPERLESS_OCR_LANGUAGE"))
 | 
			
		||||
 | 
			
		||||
    @override_settings(OCR_LANGUAGE="ita")
 | 
			
		||||
    @mock.patch("paperless_tesseract.checks.get_tesseract_langs")
 | 
			
		||||
    def test_invalid_language(self, m):
 | 
			
		||||
        m.return_value = ["deu", "eng"]
 | 
			
		||||
        msgs = check_default_language_available(None)
 | 
			
		||||
        self.assertEqual(len(msgs), 1)
 | 
			
		||||
        self.assertEqual(msgs[0].level, ERROR)
 | 
			
		||||
		Reference in New Issue
	
	Block a user