mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 10:31:50 +01:00
feat: Refactor and expand CLI smoke tests for subcommand/config coverage (#581)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
|
||||
from kleinanzeigen_bot.model.config_model import AdDefaults
|
||||
from kleinanzeigen_bot.model.config_model import AdDefaults, Config
|
||||
|
||||
|
||||
def test_migrate_legacy_description_prefix() -> None:
|
||||
@@ -60,3 +60,17 @@ def test_migrate_legacy_description_suffix() -> None:
|
||||
"suffix": "Legacy Suffix"
|
||||
}
|
||||
}).description_suffix == "Legacy Suffix"
|
||||
|
||||
|
||||
def test_minimal_config_validation() -> None:
|
||||
"""
|
||||
Unit: Minimal config validation.
|
||||
"""
|
||||
minimal_cfg = {
|
||||
"ad_defaults": {"contact": {"name": "dummy", "zipcode": "12345"}},
|
||||
"login": {"username": "dummy", "password": "dummy"},
|
||||
"publishing": {"delete_old_ads": "BEFORE_PUBLISH", "delete_old_ads_by_title": False},
|
||||
}
|
||||
config = Config.model_validate(minimal_cfg)
|
||||
assert config.login.username == "dummy"
|
||||
assert config.login.password == "dummy" # noqa: S105
|
||||
|
||||
@@ -1358,3 +1358,29 @@ class TestKleinanzeigenBotChangedAds:
|
||||
|
||||
# The changed ad should be loaded with 'due' selector because it's due for republication
|
||||
assert len(ads_to_publish) == 1
|
||||
|
||||
|
||||
def test_file_logger_writes_message(tmp_path:Path, caplog:pytest.LogCaptureFixture) -> None:
|
||||
"""
|
||||
Unit: Logger can be initialized and used, robust to pytest log capture.
|
||||
"""
|
||||
log_path = tmp_path / "logger_test.log"
|
||||
logger_name = "logger_test_logger_unique"
|
||||
logger = logging.getLogger(logger_name)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.propagate = False
|
||||
for h in list(logger.handlers):
|
||||
logger.removeHandler(h)
|
||||
handle = logging.FileHandler(str(log_path), encoding = "utf-8")
|
||||
handle.setLevel(logging.DEBUG)
|
||||
formatter = logging.Formatter("%(levelname)s:%(name)s:%(message)s")
|
||||
handle.setFormatter(formatter)
|
||||
logger.addHandler(handle)
|
||||
logger.info("Logger test log message")
|
||||
handle.flush()
|
||||
handle.close()
|
||||
logger.removeHandler(handle)
|
||||
assert log_path.exists()
|
||||
with open(log_path, "r", encoding = "utf-8") as f:
|
||||
contents = f.read()
|
||||
assert "Logger test log message" in contents
|
||||
|
||||
Reference in New Issue
Block a user