mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-17 10:13:56 -05:00
moved consumption dir check into the correct spot
This commit is contained in:
parent
6b3ec52ed4
commit
d04b54140c
@ -8,7 +8,6 @@ from django.conf import settings
|
|||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from paperless.db import GnuPG
|
|
||||||
from .classifier import DocumentClassifier, IncompatibleClassifierVersionError
|
from .classifier import DocumentClassifier, IncompatibleClassifierVersionError
|
||||||
from .file_handling import generate_filename, create_source_path_directory
|
from .file_handling import generate_filename, create_source_path_directory
|
||||||
from .loggers import LoggingMixin
|
from .loggers import LoggingMixin
|
||||||
@ -40,17 +39,6 @@ class Consumer(LoggingMixin):
|
|||||||
raise ConsumerError("Cannot consume {}: It is not a file".format(
|
raise ConsumerError("Cannot consume {}: It is not a file".format(
|
||||||
self.path))
|
self.path))
|
||||||
|
|
||||||
def pre_check_consumption_dir(self):
|
|
||||||
if not settings.CONSUMPTION_DIR:
|
|
||||||
raise ConsumerError(
|
|
||||||
"The CONSUMPTION_DIR settings variable does not appear to be "
|
|
||||||
"set.")
|
|
||||||
|
|
||||||
if not os.path.isdir(settings.CONSUMPTION_DIR):
|
|
||||||
raise ConsumerError(
|
|
||||||
"Consumption directory {} does not exist".format(
|
|
||||||
settings.CONSUMPTION_DIR))
|
|
||||||
|
|
||||||
def pre_check_duplicate(self):
|
def pre_check_duplicate(self):
|
||||||
with open(self.path, "rb") as f:
|
with open(self.path, "rb") as f:
|
||||||
checksum = hashlib.md5(f.read()).hexdigest()
|
checksum = hashlib.md5(f.read()).hexdigest()
|
||||||
@ -92,7 +80,6 @@ class Consumer(LoggingMixin):
|
|||||||
# Make sure that preconditions for consuming the file are met.
|
# Make sure that preconditions for consuming the file are met.
|
||||||
|
|
||||||
self.pre_check_file_exists()
|
self.pre_check_file_exists()
|
||||||
self.pre_check_consumption_dir()
|
|
||||||
self.pre_check_directories()
|
self.pre_check_directories()
|
||||||
self.pre_check_duplicate()
|
self.pre_check_duplicate()
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import os
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django_q.tasks import async_task
|
from django_q.tasks import async_task
|
||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
from watchdog.observers.polling import PollingObserver
|
from watchdog.observers.polling import PollingObserver
|
||||||
@ -95,6 +95,15 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
directory = options["directory"]
|
directory = options["directory"]
|
||||||
|
|
||||||
|
if not directory:
|
||||||
|
raise CommandError(
|
||||||
|
"CONSUMPTION_DIR does not appear to be set."
|
||||||
|
)
|
||||||
|
|
||||||
|
if not os.path.isdir(directory):
|
||||||
|
raise CommandError(
|
||||||
|
f"Consumption directory {directory} does not exist")
|
||||||
|
|
||||||
for entry in os.scandir(directory):
|
for entry in os.scandir(directory):
|
||||||
_consume(entry.path)
|
_consume(entry.path)
|
||||||
|
|
||||||
|
@ -502,26 +502,6 @@ class TestConsumer(TestCase):
|
|||||||
|
|
||||||
self.fail("Should throw exception")
|
self.fail("Should throw exception")
|
||||||
|
|
||||||
@override_settings(CONSUMPTION_DIR=None)
|
|
||||||
def testConsumptionDirUnset(self):
|
|
||||||
try:
|
|
||||||
self.consumer.try_consume_file(self.get_test_file())
|
|
||||||
except ConsumerError as e:
|
|
||||||
self.assertEqual(str(e), "The CONSUMPTION_DIR settings variable does not appear to be set.")
|
|
||||||
return
|
|
||||||
|
|
||||||
self.fail("Should throw exception")
|
|
||||||
|
|
||||||
@override_settings(CONSUMPTION_DIR="asd")
|
|
||||||
def testNoConsumptionDir(self):
|
|
||||||
try:
|
|
||||||
self.consumer.try_consume_file(self.get_test_file())
|
|
||||||
except ConsumerError as e:
|
|
||||||
self.assertEqual(str(e), "Consumption directory asd does not exist")
|
|
||||||
return
|
|
||||||
|
|
||||||
self.fail("Should throw exception")
|
|
||||||
|
|
||||||
def testDuplicates(self):
|
def testDuplicates(self):
|
||||||
self.consumer.try_consume_file(self.get_test_file())
|
self.consumer.try_consume_file(self.get_test_file())
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ from time import sleep
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.management import call_command, CommandError
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
|
||||||
from documents.consumer import ConsumerError
|
from documents.consumer import ConsumerError
|
||||||
@ -193,3 +194,13 @@ class TestConsumer(TestCase):
|
|||||||
@override_settings(CONSUMER_POLLING=1)
|
@override_settings(CONSUMER_POLLING=1)
|
||||||
def test_slow_write_incomplete_polling(self):
|
def test_slow_write_incomplete_polling(self):
|
||||||
self.test_slow_write_incomplete()
|
self.test_slow_write_incomplete()
|
||||||
|
|
||||||
|
@override_settings(CONSUMPTION_DIR="does_not_exist")
|
||||||
|
def test_consumption_directory_invalid(self):
|
||||||
|
|
||||||
|
self.assertRaises(CommandError, call_command, 'document_consumer', '--oneshot')
|
||||||
|
|
||||||
|
@override_settings(CONSUMPTION_DIR="")
|
||||||
|
def test_consumption_directory_unset(self):
|
||||||
|
|
||||||
|
self.assertRaises(CommandError, call_command, 'document_consumer', '--oneshot')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user