Share the folder setup of the configuration tests
This commit is contained in:
+20
-24
@@ -16,6 +16,14 @@ def reload_config(monkeypatch):
|
|||||||
importlib.reload(config)
|
importlib.reload(config)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def folders(monkeypatch, tmp_path):
|
||||||
|
"""Put the folders of Bindery in a temporary folder. The ingest folder does not exist yet."""
|
||||||
|
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")
|
||||||
|
|
||||||
|
|
||||||
def test_bool(monkeypatch):
|
def test_bool(monkeypatch):
|
||||||
for value in ("true", "Yes", " 1 ", "on", "y"):
|
for value in ("true", "Yes", " 1 ", "on", "y"):
|
||||||
monkeypatch.setenv("X_TEST", value)
|
monkeypatch.setenv("X_TEST", value)
|
||||||
@@ -180,15 +188,12 @@ def test_only_a_clear_false_turns_cwa_off(monkeypatch, reload_config, value):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("ignored", [[], ["CWA_URL", "CALIBRE_DB_PATH"]])
|
@pytest.mark.parametrize("ignored", [[], ["CWA_URL", "CALIBRE_DB_PATH"]])
|
||||||
def test_prepare_with_cwa_off_logs_nothing_about_missing_cwa(monkeypatch, tmp_path, caplog, ignored):
|
def test_prepare_with_cwa_off_logs_nothing_about_missing_cwa(folders, monkeypatch, tmp_path, caplog, ignored):
|
||||||
monkeypatch.setattr(config, "CWA_ENABLED", False)
|
monkeypatch.setattr(config, "CWA_ENABLED", False)
|
||||||
monkeypatch.setattr(config, "IGNORED_SETTINGS", ignored)
|
monkeypatch.setattr(config, "IGNORED_SETTINGS", ignored)
|
||||||
monkeypatch.setattr(config, "INGEST_DIR", None)
|
monkeypatch.setattr(config, "INGEST_DIR", None)
|
||||||
monkeypatch.setattr(config, "CWA_URL", "")
|
monkeypatch.setattr(config, "CWA_URL", "")
|
||||||
monkeypatch.setattr(config, "CALIBRE_DB_PATH", None)
|
monkeypatch.setattr(config, "CALIBRE_DB_PATH", None)
|
||||||
for name, folder in [("CONFIG_DIR", "config"), ("UPLOAD_DIR", "uploads"), ("TMP_DIR", "tmp")]:
|
|
||||||
monkeypatch.setattr(config, name, tmp_path / folder)
|
|
||||||
monkeypatch.setattr(config, "PERSONAL_INI", tmp_path / "config" / "personal.ini")
|
|
||||||
with caplog.at_level("INFO"):
|
with caplog.at_level("INFO"):
|
||||||
config.prepare()
|
config.prepare()
|
||||||
lines = [r.getMessage() for r in caplog.records]
|
lines = [r.getMessage() for r in caplog.records]
|
||||||
@@ -206,13 +211,12 @@ def test_prepare_with_cwa_off_logs_nothing_about_missing_cwa(monkeypatch, tmp_pa
|
|||||||
(True, "https://cwa.invalid", None, []),
|
(True, "https://cwa.invalid", None, []),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_prepare_warns_about_each_missing_cwa_function(monkeypatch, tmp_path, caplog, ingest, url, database, expected):
|
def test_prepare_warns_about_each_missing_cwa_function(
|
||||||
|
folders, monkeypatch, tmp_path, caplog, ingest, url, database, expected
|
||||||
|
):
|
||||||
monkeypatch.setattr(config, "CWA_URL", url)
|
monkeypatch.setattr(config, "CWA_URL", url)
|
||||||
monkeypatch.setattr(config, "CALIBRE_DB_PATH", database)
|
monkeypatch.setattr(config, "CALIBRE_DB_PATH", database)
|
||||||
monkeypatch.setattr(config, "INGEST_DIR", tmp_path if ingest else None)
|
monkeypatch.setattr(config, "INGEST_DIR", tmp_path if ingest else None)
|
||||||
for name, folder in [("CONFIG_DIR", "config"), ("UPLOAD_DIR", "uploads"), ("TMP_DIR", "tmp")]:
|
|
||||||
monkeypatch.setattr(config, name, tmp_path / folder)
|
|
||||||
monkeypatch.setattr(config, "PERSONAL_INI", tmp_path / "config" / "personal.ini")
|
|
||||||
with caplog.at_level("WARNING"):
|
with caplog.at_level("WARNING"):
|
||||||
config.prepare()
|
config.prepare()
|
||||||
warnings = [r.getMessage() for r in caplog.records]
|
warnings = [r.getMessage() for r in caplog.records]
|
||||||
@@ -221,14 +225,11 @@ def test_prepare_warns_about_each_missing_cwa_function(monkeypatch, tmp_path, ca
|
|||||||
assert text in warning
|
assert text in warning
|
||||||
|
|
||||||
|
|
||||||
def test_prepare_without_cwa_creates_only_bindery_folders(monkeypatch, tmp_path, caplog):
|
def test_prepare_without_cwa_creates_only_bindery_folders(folders, monkeypatch, tmp_path, caplog):
|
||||||
monkeypatch.setattr(config, "CWA_ENABLED", False)
|
monkeypatch.setattr(config, "CWA_ENABLED", False)
|
||||||
monkeypatch.setattr(config, "INGEST_DIR", None)
|
monkeypatch.setattr(config, "INGEST_DIR", None)
|
||||||
monkeypatch.setattr(config, "CWA_URL", "")
|
monkeypatch.setattr(config, "CWA_URL", "")
|
||||||
monkeypatch.setattr(config, "CALIBRE_DB_PATH", None)
|
monkeypatch.setattr(config, "CALIBRE_DB_PATH", None)
|
||||||
for name, folder in [("CONFIG_DIR", "config"), ("UPLOAD_DIR", "uploads"), ("TMP_DIR", "tmp")]:
|
|
||||||
monkeypatch.setattr(config, name, tmp_path / folder)
|
|
||||||
monkeypatch.setattr(config, "PERSONAL_INI", tmp_path / "config" / "personal.ini")
|
|
||||||
config.prepare()
|
config.prepare()
|
||||||
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"}
|
||||||
@@ -239,12 +240,11 @@ def test_prepare_without_cwa_creates_only_bindery_folders(monkeypatch, tmp_path,
|
|||||||
("url", "database", "warns"),
|
("url", "database", "warns"),
|
||||||
[("", None, True), ("https://cwa.invalid", None, False), ("", Path("/library/metadata.db"), False)],
|
[("", 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):
|
def test_prepare_warns_about_an_ingest_folder_without_a_library(
|
||||||
|
folders, monkeypatch, tmp_path, caplog, url, database, warns
|
||||||
|
):
|
||||||
monkeypatch.setattr(config, "CWA_URL", url)
|
monkeypatch.setattr(config, "CWA_URL", url)
|
||||||
monkeypatch.setattr(config, "CALIBRE_DB_PATH", database)
|
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"):
|
with caplog.at_level("WARNING"):
|
||||||
config.prepare()
|
config.prepare()
|
||||||
assert ("each update adds a new book" in caplog.text) is warns
|
assert ("each update adds a new book" in caplog.text) is warns
|
||||||
@@ -271,24 +271,20 @@ def test_log_level_in_lower_case(monkeypatch, reload_config):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(("username", "warns"), [("", True), ("bindery", False)])
|
@pytest.mark.parametrize(("username", "warns"), [("", True), ("bindery", False)])
|
||||||
def test_prepare_warns_about_a_cwa_password_without_a_user_name(monkeypatch, tmp_path, caplog, username, warns):
|
def test_prepare_warns_about_a_cwa_password_without_a_user_name(
|
||||||
|
folders, monkeypatch, tmp_path, caplog, username, warns
|
||||||
|
):
|
||||||
monkeypatch.setattr(config, "CWA_URL", "https://cwa.invalid")
|
monkeypatch.setattr(config, "CWA_URL", "https://cwa.invalid")
|
||||||
monkeypatch.setattr(config, "CWA_USERNAME", username)
|
monkeypatch.setattr(config, "CWA_USERNAME", username)
|
||||||
monkeypatch.setattr(config, "CWA_PASSWORD", "secret")
|
monkeypatch.setattr(config, "CWA_PASSWORD", "secret")
|
||||||
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"):
|
with caplog.at_level("WARNING"):
|
||||||
config.prepare()
|
config.prepare()
|
||||||
assert ("CWA_PASSWORD is set" in caplog.text) is warns
|
assert ("CWA_PASSWORD is set" in caplog.text) is warns
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("exists", [False, True])
|
@pytest.mark.parametrize("exists", [False, True])
|
||||||
def test_prepare_does_not_make_the_ingest_folder(monkeypatch, tmp_path, caplog, exists):
|
def test_prepare_does_not_make_the_ingest_folder(folders, monkeypatch, tmp_path, caplog, exists):
|
||||||
monkeypatch.setattr(config, "CWA_URL", "https://cwa.invalid")
|
monkeypatch.setattr(config, "CWA_URL", "https://cwa.invalid")
|
||||||
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")
|
|
||||||
if exists:
|
if exists:
|
||||||
config.INGEST_DIR.mkdir()
|
config.INGEST_DIR.mkdir()
|
||||||
config.prepare()
|
config.prepare()
|
||||||
|
|||||||
Reference in New Issue
Block a user