mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-09-24 02:10:33 +00:00
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:
@@ -5,8 +5,20 @@ this file is imported for every session, so anything heavy belongs inside
|
||||
the fixture body that needs it.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Generator
|
||||
from pathlib import Path
|
||||
|
||||
from pytest_django.fixtures import Settings
|
||||
|
||||
from paperless_testing.dirs import PaperlessDirs
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def faker_session_locale() -> str:
|
||||
@@ -33,3 +45,27 @@ def _clear_content_type_caches() -> None:
|
||||
|
||||
ContentType.objects.clear_cache()
|
||||
clear_ct_cache()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def paperless_dirs(
|
||||
tmp_path: Path,
|
||||
settings: Settings,
|
||||
) -> Generator[PaperlessDirs, None, None]:
|
||||
"""The standard temp directory layout, applied to Django settings."""
|
||||
from documents.search import reset_backend
|
||||
from paperless_testing.dirs import build_paperless_dirs
|
||||
from paperless_testing.dirs import dirs_settings
|
||||
|
||||
dirs = build_paperless_dirs(tmp_path)
|
||||
for name, value in dirs_settings(dirs).items():
|
||||
setattr(settings, name, value)
|
||||
|
||||
# Not directory settings, but they are needed alongside the layout by the
|
||||
# sanity checker tests.
|
||||
settings.IGNORABLE_FILES = {".DS_Store", "Thumbs.db", "desktop.ini"}
|
||||
settings.APP_LOGO = ""
|
||||
|
||||
reset_backend()
|
||||
yield dirs
|
||||
reset_backend()
|
||||
|
||||
Reference in New Issue
Block a user