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.
This commit is contained in:
@@ -89,3 +89,8 @@ def prepare() -> None:
|
|||||||
if not PERSONAL_INI.exists():
|
if not PERSONAL_INI.exists():
|
||||||
shutil.copy(DEFAULT_PERSONAL_INI, PERSONAL_INI)
|
shutil.copy(DEFAULT_PERSONAL_INI, PERSONAL_INI)
|
||||||
logger.info(f"Created the default FanFicFare configuration at {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."
|
||||||
|
)
|
||||||
|
|||||||
@@ -140,3 +140,18 @@ def test_prepare_without_cwa_creates_only_bindery_folders(monkeypatch, tmp_path,
|
|||||||
assert config.PERSONAL_INI.exists()
|
assert config.PERSONAL_INI.exists()
|
||||||
assert {p.name for p in tmp_path.iterdir()} == {"config", "uploads", "tmp"}
|
assert {p.name for p in tmp_path.iterdir()} == {"config", "uploads", "tmp"}
|
||||||
assert caplog.records == []
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user