Chore: State the test directory layout in one place (#14171)

The temp directory layout used by the tests was written out four separate
times: once in the documents conftest, once in the paperless checks tests,
once in a fixture local to the NFC upload tests, and once in the helper
behind the old paperless_environment context manager. Each copy covered a
different subset of the settings, so which directories a test actually got
depended on which copy it happened to reach.

The layout now lives in paperless_testing.dirs. build_paperless_dirs owns
where things go and creates them, dirs_settings maps them onto Django
setting names and is pure, and a paperless_dirs fixture in the root conftest
applies that mapping through pytest-django's settings fixture so every app
can reach it. Tests that need a second environment part way through a test
body use the paperless_environment context manager from the same module,
which expresses the identical layout through override_settings. The three
redundant implementations and the old media settings fixture are gone, and
their consumers now take paperless_dirs.
This commit is contained in:
Trenton H authored and GitHub committed 2026-09-21 10:57:11 -07:00
1 parent 48d97b78bb
commit 4c264651e8
10 files changed
+215 -129

No files matched your search

+9 -38
View File
@@ -1,6 +1,5 @@
import os
from collections.abc import Callable
from dataclasses import dataclass
from pathlib import Path
from unittest import mock
@@ -19,35 +18,7 @@ from paperless.checks import check_v3_minimum_upgrade_version
from paperless.checks import debug_mode_check
from paperless.checks import paths_check
from paperless.checks import settings_values_check
@dataclass(frozen=True, slots=True)
class PaperlessTestDirs:
data_dir: Path
media_dir: Path
consumption_dir: Path
# TODO: consolidate with documents/tests/conftest.py PaperlessDirs/paperless_dirs
# once the paperless and documents test suites are ready to share fixtures.
@pytest.fixture()
def directories(tmp_path: Path, settings: Settings) -> PaperlessTestDirs:
data_dir = tmp_path / "data"
media_dir = tmp_path / "media"
consumption_dir = tmp_path / "consumption"
for d in (data_dir, media_dir, consumption_dir):
d.mkdir()
settings.DATA_DIR = data_dir
settings.MEDIA_ROOT = media_dir
settings.CONSUMPTION_DIR = consumption_dir
return PaperlessTestDirs(
data_dir=data_dir,
media_dir=media_dir,
consumption_dir=consumption_dir,
)
from paperless_testing.dirs import PaperlessDirs
class TestChecks:
@@ -58,7 +29,7 @@ class TestChecks:
settings.CONVERT_BINARY = "uuuhh"
assert len(binaries_check(None)) == 1
@pytest.mark.usefixtures("directories")
@pytest.mark.usefixtures("paperless_dirs")
def test_paths_check(self) -> None:
assert paths_check(None) == []
@@ -73,17 +44,17 @@ class TestChecks:
for msg in msgs:
assert msg.msg.endswith("is set but doesn't exist.")
def test_paths_check_no_access(self, directories: PaperlessTestDirs) -> None:
directories.data_dir.chmod(0o000)
directories.media_dir.chmod(0o000)
directories.consumption_dir.chmod(0o000)
def test_paths_check_no_access(self, paperless_dirs: PaperlessDirs) -> None:
paperless_dirs.data_dir.chmod(0o000)
paperless_dirs.media_dir.chmod(0o000)
paperless_dirs.consumption_dir.chmod(0o000)
try:
msgs = paths_check(None)
finally:
directories.data_dir.chmod(0o777)
directories.media_dir.chmod(0o777)
directories.consumption_dir.chmod(0o777)
paperless_dirs.data_dir.chmod(0o777)
paperless_dirs.media_dir.chmod(0o777)
paperless_dirs.consumption_dir.chmod(0o777)
assert len(msgs) == 3
for msg in msgs: