Reverts most files to dev while keeping the exception assert fixes

This commit is contained in:
Trenton H 2025-11-18 09:54:06 -08:00
parent 7b220f737f
commit ee2693e6e4
10 changed files with 15 additions and 77 deletions

View file

@ -152,19 +152,6 @@ $ ng build --configuration production
configuration. This is not ideal. But for now, make sure no settings configuration. This is not ideal. But for now, make sure no settings
except for DEBUG are overridden when testing. except for DEBUG are overridden when testing.
- Testing under docker is possible (but generally unsupported) if a
bare-metal environment cannot be setup. To run tests under docker, use
this command:
```bash
# paperless-ngx/
$ docker run --rm -i -t \
-v $PWD:/usr/src/paperless \
--entrypoint=uv paperlessngx/paperless-ngx:latest \
run pytest
```
!!! note !!! note
The line length rule E501 is generally useful for getting multiple The line length rule E501 is generally useful for getting multiple

View file

@ -250,22 +250,10 @@ class Command(BaseCommand):
if options["oneshot"]: if options["oneshot"]:
return return
inotify = None
if settings.CONSUMER_POLLING == 0 and INotify: if settings.CONSUMER_POLLING == 0 and INotify:
try: self.handle_inotify(directory, recursive, is_testing=options["testing"])
inotify = INotify()
except OSError:
logger.exception("inotify failed to instantiate")
if inotify:
self.handle_inotify(
inotify,
directory,
recursive,
is_testing=options["testing"],
)
else: else:
if inotify is None and settings.CONSUMER_POLLING == 0: # pragma: no cover if INotify is None and settings.CONSUMER_POLLING == 0: # pragma: no cover
logger.warning("Using polling as INotify import failed") logger.warning("Using polling as INotify import failed")
self.handle_polling(directory, recursive, is_testing=options["testing"]) self.handle_polling(directory, recursive, is_testing=options["testing"])
@ -298,7 +286,7 @@ class Command(BaseCommand):
observer.stop() observer.stop()
observer.join() observer.join()
def handle_inotify(self, inotify, directory, recursive, *, is_testing: bool): def handle_inotify(self, directory, recursive, *, is_testing: bool):
logger.info(f"Using inotify to watch directory for changes: {directory}") logger.info(f"Using inotify to watch directory for changes: {directory}")
timeout_ms = None timeout_ms = None
@ -306,6 +294,7 @@ class Command(BaseCommand):
timeout_ms = self.testing_timeout_ms timeout_ms = self.testing_timeout_ms
logger.debug(f"Configuring timeout to {timeout_ms}ms") logger.debug(f"Configuring timeout to {timeout_ms}ms")
inotify = INotify()
inotify_flags = flags.CLOSE_WRITE | flags.MOVED_TO | flags.MODIFY inotify_flags = flags.CLOSE_WRITE | flags.MOVED_TO | flags.MODIFY
if recursive: if recursive:
inotify.add_watch_recursive(directory, inotify_flags) inotify.add_watch_recursive(directory, inotify_flags)

View file

@ -34,7 +34,7 @@ class TestSystemStatus(APITestCase):
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["pngx_version"], version.__full_version_str__) self.assertEqual(response.data["pngx_version"], version.__full_version_str__)
self.assertIsNotNone(response.data["server_os"]) self.assertIsNotNone(response.data["server_os"])
self.assertIn(response.data["install_type"], ["bare-metal", "docker"]) self.assertEqual(response.data["install_type"], "bare-metal")
self.assertIsNotNone(response.data["storage"]["total"]) self.assertIsNotNone(response.data["storage"]["total"])
self.assertIsNotNone(response.data["storage"]["available"]) self.assertIsNotNone(response.data["storage"]["available"])
self.assertEqual(response.data["database"]["type"], "sqlite") self.assertEqual(response.data["database"]["type"], "sqlite")

View file

@ -26,7 +26,6 @@ from documents.tasks import empty_trash
from documents.tests.factories import DocumentFactory from documents.tests.factories import DocumentFactory
from documents.tests.utils import DirectoriesMixin from documents.tests.utils import DirectoriesMixin
from documents.tests.utils import FileSystemAssertsMixin from documents.tests.utils import FileSystemAssertsMixin
from documents.tests.utils import skip_if_root
class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase): class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
@ -90,7 +89,6 @@ class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
settings.ORIGINALS_DIR / "test" / "test.pdf.gpg", settings.ORIGINALS_DIR / "test" / "test.pdf.gpg",
) )
@skip_if_root
@override_settings(FILENAME_FORMAT="{correspondent}/{correspondent}") @override_settings(FILENAME_FORMAT="{correspondent}/{correspondent}")
def test_file_renaming_missing_permissions(self): def test_file_renaming_missing_permissions(self):
document = Document() document = Document()

View file

@ -5,7 +5,6 @@ from threading import Thread
from time import sleep from time import sleep
from unittest import mock from unittest import mock
import pytest
from django.conf import settings from django.conf import settings
from django.core.management import CommandError from django.core.management import CommandError
from django.core.management import call_command from django.core.management import call_command
@ -19,14 +18,6 @@ from documents.models import Tag
from documents.tests.utils import DirectoriesMixin from documents.tests.utils import DirectoriesMixin
from documents.tests.utils import DocumentConsumeDelayMixin from documents.tests.utils import DocumentConsumeDelayMixin
try:
from inotifyrecursive import INotify
INotify()
SKIP_INOTIFY_TESTS = False
except (ImportError, OSError):
SKIP_INOTIFY_TESTS = True
class ConsumerThread(Thread): class ConsumerThread(Thread):
def __init__(self): def __init__(self):
@ -117,10 +108,10 @@ class ConsumerThreadMixin(DocumentConsumeDelayMixin):
print("file completed.") # noqa: T201 print("file completed.") # noqa: T201
class _TestConsumerBase(DirectoriesMixin, ConsumerThreadMixin): @override_settings(
# Note: adding TransactionTestCase as a base makes pytest discover this CONSUMER_INOTIFY_DELAY=0.01,
# class. Only add it to the actual test classes. )
class TestConsumer(DirectoriesMixin, ConsumerThreadMixin, TransactionTestCase):
def test_consume_file(self): def test_consume_file(self):
self.t_start() self.t_start()
@ -374,14 +365,6 @@ class _TestConsumerBase(DirectoriesMixin, ConsumerThreadMixin):
self.consume_file_mock.assert_not_called() self.consume_file_mock.assert_not_called()
@override_settings(
CONSUMER_INOTIFY_DELAY=0.01,
)
@pytest.mark.skipif(SKIP_INOTIFY_TESTS, reason="no inotify")
class TestConsumer(_TestConsumerBase, TransactionTestCase):
pass
@override_settings( @override_settings(
CONSUMER_POLLING=1, CONSUMER_POLLING=1,
# please leave the delay here and down below # please leave the delay here and down below
@ -389,14 +372,13 @@ class TestConsumer(_TestConsumerBase, TransactionTestCase):
CONSUMER_POLLING_DELAY=3, CONSUMER_POLLING_DELAY=3,
CONSUMER_POLLING_RETRY_COUNT=20, CONSUMER_POLLING_RETRY_COUNT=20,
) )
class TestConsumerPolling(_TestConsumerBase, TransactionTestCase): class TestConsumerPolling(TestConsumer):
# just do all the tests with polling # just do all the tests with polling
pass pass
@override_settings(CONSUMER_INOTIFY_DELAY=0.01, CONSUMER_RECURSIVE=True) @override_settings(CONSUMER_INOTIFY_DELAY=0.01, CONSUMER_RECURSIVE=True)
@pytest.mark.skipif(SKIP_INOTIFY_TESTS, reason="no inotify") class TestConsumerRecursive(TestConsumer):
class TestConsumerRecursive(_TestConsumerBase, TransactionTestCase):
# just do all the tests with recursive # just do all the tests with recursive
pass pass
@ -407,14 +389,14 @@ class TestConsumerRecursive(_TestConsumerBase, TransactionTestCase):
CONSUMER_POLLING_DELAY=3, CONSUMER_POLLING_DELAY=3,
CONSUMER_POLLING_RETRY_COUNT=20, CONSUMER_POLLING_RETRY_COUNT=20,
) )
class TestConsumerRecursivePolling(_TestConsumerBase, TransactionTestCase): class TestConsumerRecursivePolling(TestConsumer):
# just do all the tests with polling and recursive # just do all the tests with polling and recursive
pass pass
@override_settings(CONSUMER_RECURSIVE=True, CONSUMER_SUBDIRS_AS_TAGS=True)
class TestConsumerTags(DirectoriesMixin, ConsumerThreadMixin, TransactionTestCase): class TestConsumerTags(DirectoriesMixin, ConsumerThreadMixin, TransactionTestCase):
def _test_consume_file_with_path_tags(self): @override_settings(CONSUMER_RECURSIVE=True, CONSUMER_SUBDIRS_AS_TAGS=True)
def test_consume_file_with_path_tags(self):
tag_names = ("existingTag", "Space Tag") tag_names = ("existingTag", "Space Tag")
# Create a Tag prior to consuming a file using it in path # Create a Tag prior to consuming a file using it in path
tag_ids = [ tag_ids = [
@ -447,14 +429,10 @@ class TestConsumerTags(DirectoriesMixin, ConsumerThreadMixin, TransactionTestCas
# their order. # their order.
self.assertCountEqual(overrides.tag_ids, tag_ids) self.assertCountEqual(overrides.tag_ids, tag_ids)
@pytest.mark.skipif(SKIP_INOTIFY_TESTS, reason="no inotify")
def test_consume_file_with_path_tags(self):
self._test_consume_file_with_path_tags()
@override_settings( @override_settings(
CONSUMER_POLLING=1, CONSUMER_POLLING=1,
CONSUMER_POLLING_DELAY=3, CONSUMER_POLLING_DELAY=3,
CONSUMER_POLLING_RETRY_COUNT=20, CONSUMER_POLLING_RETRY_COUNT=20,
) )
def test_consume_file_with_path_tags_polling(self): def test_consume_file_with_path_tags_polling(self):
self._test_consume_file_with_path_tags() self.test_consume_file_with_path_tags()

View file

@ -42,7 +42,6 @@ from documents.tests.utils import DirectoriesMixin
from documents.tests.utils import FileSystemAssertsMixin from documents.tests.utils import FileSystemAssertsMixin
from documents.tests.utils import SampleDirMixin from documents.tests.utils import SampleDirMixin
from documents.tests.utils import paperless_environment from documents.tests.utils import paperless_environment
from documents.tests.utils import skip_if_root
from paperless_mail.models import MailAccount from paperless_mail.models import MailAccount
@ -592,7 +591,6 @@ class TestExportImport(
self.assertEqual("That path isn't a directory", str(e.exception)) self.assertEqual("That path isn't a directory", str(e.exception))
@skip_if_root
def test_export_target_not_writable(self): def test_export_target_not_writable(self):
""" """
GIVEN: GIVEN:

View file

@ -16,7 +16,6 @@ from documents.settings import EXPORTER_FILE_NAME
from documents.tests.utils import DirectoriesMixin from documents.tests.utils import DirectoriesMixin
from documents.tests.utils import FileSystemAssertsMixin from documents.tests.utils import FileSystemAssertsMixin
from documents.tests.utils import SampleDirMixin from documents.tests.utils import SampleDirMixin
from documents.tests.utils import skip_if_root
class TestCommandImport( class TestCommandImport(
@ -98,7 +97,6 @@ class TestCommandImport(
) )
self.assertIn('The manifest file refers to "noexist.pdf"', str(e.exception)) self.assertIn('The manifest file refers to "noexist.pdf"', str(e.exception))
@skip_if_root
def test_import_permission_error(self): def test_import_permission_error(self):
""" """
GIVEN: GIVEN:
@ -153,7 +151,6 @@ class TestCommandImport(
call_command("document_importer", Path("/tmp/notapath")) call_command("document_importer", Path("/tmp/notapath"))
self.assertIn("That path doesn't exist", str(cm.exception)) self.assertIn("That path doesn't exist", str(cm.exception))
@skip_if_root
def test_import_source_not_readable(self): def test_import_source_not_readable(self):
""" """
GIVEN: GIVEN:

View file

@ -10,7 +10,6 @@ from django.test import override_settings
from documents.models import Document from documents.models import Document
from documents.sanity_checker import check_sanity from documents.sanity_checker import check_sanity
from documents.tests.utils import DirectoriesMixin from documents.tests.utils import DirectoriesMixin
from documents.tests.utils import skip_if_root
class TestSanityCheck(DirectoriesMixin, TestCase): class TestSanityCheck(DirectoriesMixin, TestCase):
@ -96,7 +95,6 @@ class TestSanityCheck(DirectoriesMixin, TestCase):
Path(doc.thumbnail_path).unlink() Path(doc.thumbnail_path).unlink()
self.assertSanityError(doc, "Thumbnail of document does not exist") self.assertSanityError(doc, "Thumbnail of document does not exist")
@skip_if_root
def test_thumbnail_no_access(self): def test_thumbnail_no_access(self):
doc = self.make_test_data() doc = self.make_test_data()
Path(doc.thumbnail_path).chmod(0o000) Path(doc.thumbnail_path).chmod(0o000)
@ -108,7 +106,6 @@ class TestSanityCheck(DirectoriesMixin, TestCase):
Path(doc.source_path).unlink() Path(doc.source_path).unlink()
self.assertSanityError(doc, "Original of document does not exist.") self.assertSanityError(doc, "Original of document does not exist.")
@skip_if_root
def test_original_no_access(self): def test_original_no_access(self):
doc = self.make_test_data() doc = self.make_test_data()
Path(doc.source_path).chmod(0o000) Path(doc.source_path).chmod(0o000)
@ -126,7 +123,6 @@ class TestSanityCheck(DirectoriesMixin, TestCase):
Path(doc.archive_path).unlink() Path(doc.archive_path).unlink()
self.assertSanityError(doc, "Archived version of document does not exist.") self.assertSanityError(doc, "Archived version of document does not exist.")
@skip_if_root
def test_archive_no_access(self): def test_archive_no_access(self):
doc = self.make_test_data() doc = self.make_test_data()
Path(doc.archive_path).chmod(0o000) Path(doc.archive_path).chmod(0o000)

View file

@ -1,4 +1,3 @@
import os
import shutil import shutil
import tempfile import tempfile
import time import time
@ -29,8 +28,6 @@ from documents.data_models import DocumentSource
from documents.parsers import ParseError from documents.parsers import ParseError
from documents.plugins.helpers import ProgressStatusOptions from documents.plugins.helpers import ProgressStatusOptions
skip_if_root = pytest.mark.skipif(os.getuid() == 0, reason="running as root")
def setup_directories(): def setup_directories():
dirs = namedtuple("Dirs", ()) dirs = namedtuple("Dirs", ())

View file

@ -7,7 +7,6 @@ from django.test import override_settings
from documents.tests.utils import DirectoriesMixin from documents.tests.utils import DirectoriesMixin
from documents.tests.utils import FileSystemAssertsMixin from documents.tests.utils import FileSystemAssertsMixin
from documents.tests.utils import skip_if_root
from paperless.checks import audit_log_check from paperless.checks import audit_log_check
from paperless.checks import binaries_check from paperless.checks import binaries_check
from paperless.checks import debug_mode_check from paperless.checks import debug_mode_check
@ -38,7 +37,6 @@ class TestChecks(DirectoriesMixin, TestCase):
for msg in msgs: for msg in msgs:
self.assertTrue(msg.msg.endswith("is set but doesn't exist.")) self.assertTrue(msg.msg.endswith("is set but doesn't exist."))
@skip_if_root
def test_paths_check_no_access(self): def test_paths_check_no_access(self):
Path(self.dirs.data_dir).chmod(0o000) Path(self.dirs.data_dir).chmod(0o000)
Path(self.dirs.media_dir).chmod(0o000) Path(self.dirs.media_dir).chmod(0o000)