From f961e4781e8642b4f202c340787cd2c0738abf44 Mon Sep 17 00:00:00 2001 From: Timothy Allen Date: Fri, 2 Oct 2026 21:04:49 +0200 Subject: [PATCH] Warn when the ingest folder has no library to match Without CWA_URL and CALIBRE_DB_PATH, each update goes to CWA as a new book. --- bindery/config.py | 5 +++++ tests/test_config.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/bindery/config.py b/bindery/config.py index 1d3521f..ac09fad 100644 --- a/bindery/config.py +++ b/bindery/config.py @@ -89,3 +89,8 @@ def prepare() -> None: if not PERSONAL_INI.exists(): shutil.copy(DEFAULT_PERSONAL_INI, PERSONAL_INI) logger.info(f"Created the default FanFicFare configuration at {PERSONAL_INI}") + if INGEST_DIR and not (CWA_URL or CALIBRE_DB_PATH): + logger.warning( + "INGEST_DIR is set, but CWA_URL and CALIBRE_DB_PATH are not. Bindery cannot find the library book " + "of a story, so each update adds a new book to CWA." + ) diff --git a/tests/test_config.py b/tests/test_config.py index 1f72bbe..999da69 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -140,3 +140,18 @@ def test_prepare_without_cwa_creates_only_bindery_folders(monkeypatch, tmp_path, assert config.PERSONAL_INI.exists() assert {p.name for p in tmp_path.iterdir()} == {"config", "uploads", "tmp"} assert caplog.records == [] + + +@pytest.mark.parametrize( + ("url", "database", "warns"), + [("", None, True), ("https://cwa.invalid", None, False), ("", Path("/library/metadata.db"), False)], +) +def test_prepare_warns_about_an_ingest_folder_without_a_library(monkeypatch, tmp_path, caplog, url, database, warns): + monkeypatch.setattr(config, "CWA_URL", url) + monkeypatch.setattr(config, "CALIBRE_DB_PATH", database) + for name, folder in [("CONFIG_DIR", "config"), ("UPLOAD_DIR", "uploads"), ("TMP_DIR", "tmp"), ("INGEST_DIR", "in")]: + monkeypatch.setattr(config, name, tmp_path / folder) + monkeypatch.setattr(config, "PERSONAL_INI", tmp_path / "config" / "personal.ini") + with caplog.at_level("WARNING"): + config.prepare() + assert ("each update adds a new book" in caplog.text) is warns