Stop the start with a clear message for a bad setting
A bad UPDATE_INTERVAL_HOURS or LOG_LEVEL no longer ends in a traceback. Warn about a CWA_PASSWORD without a CWA_USERNAME.
This commit is contained in:
@@ -155,3 +155,36 @@ def test_prepare_warns_about_an_ingest_folder_without_a_library(monkeypatch, tmp
|
||||
with caplog.at_level("WARNING"):
|
||||
config.prepare()
|
||||
assert ("each update adds a new book" in caplog.text) is warns
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("name", "value", "error"),
|
||||
[
|
||||
("UPDATE_INTERVAL_HOURS", "daily", "UPDATE_INTERVAL_HOURS must be a number, not 'daily'"),
|
||||
("LOG_LEVEL", "loud", "LOG_LEVEL must be one of DEBUG, INFO, WARNING, ERROR, CRITICAL, not 'LOUD'"),
|
||||
],
|
||||
)
|
||||
def test_a_bad_value_stops_the_start_with_a_clear_message(monkeypatch, reload_config, name, value, error):
|
||||
monkeypatch.setenv(name, value)
|
||||
with pytest.raises(SystemExit) as stop:
|
||||
reload_config()
|
||||
assert str(stop.value) == error
|
||||
|
||||
|
||||
def test_log_level_in_lower_case(monkeypatch, reload_config):
|
||||
monkeypatch.setenv("LOG_LEVEL", " debug ")
|
||||
reload_config()
|
||||
assert config.LOG_LEVEL == "DEBUG"
|
||||
|
||||
|
||||
@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):
|
||||
monkeypatch.setattr(config, "CWA_URL", "https://cwa.invalid")
|
||||
monkeypatch.setattr(config, "CWA_USERNAME", username)
|
||||
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"):
|
||||
config.prepare()
|
||||
assert ("CWA_PASSWORD is set" in caplog.text) is warns
|
||||
|
||||
Reference in New Issue
Block a user