From 4acd59e803caebe614c624d5b0c5e407f533845c Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Wed, 15 Jan 2025 16:00:26 +0100 Subject: [PATCH] tests.finalize:finalize_docs_collections - add test for "finalize doc-collections" command --- tests/test_finalize.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_finalize.py diff --git a/tests/test_finalize.py b/tests/test_finalize.py new file mode 100644 index 00000000..3d34ee09 --- /dev/null +++ b/tests/test_finalize.py @@ -0,0 +1,35 @@ +from math import ceil +from pathlib import Path + +from acacore.database import FilesDB +from acacore.models.file import ConvertedFile + +from digiarch.cli import app +from digiarch.common import AVID +from tests.conftest import run_click + + +def test_finalize_docs_collections(avid_folder_copy: Path): + avid = AVID(avid_folder_copy) + + with FilesDB(avid.database_path) as database: + files: list[ConvertedFile] = database.statutory_files.select().fetchall() + + docs_in_collections: int = 3 + expected_paths: dict[Path, Path] = { + f.relative_path: Path( + avid.dirs.documents.name, + f"docCollection{ceil(n / docs_in_collections)}", + str(n), + f"1{f.suffix}", + ) + for n, f in enumerate(sorted(files, key=lambda f: f.relative_path), 1) + } + + run_click(avid_folder_copy, app, "finalize", "doc-collections", "--docs-in-collection", docs_in_collections) + + with FilesDB(avid.database_path) as database: + for file in files: + test_file: ConvertedFile | None = database.statutory_files[{"uuid": str(file.uuid)}] + assert test_file + assert test_file.relative_path == expected_paths[file.relative_path]