feat(cleaner): ✨ add command prune

this new command will be called by cron-like process to clean purge old logs and old mails. All files were formatted and mail_utils was renamed in utils since it now defines utility function not only for mail functions.
This commit is contained in:
2026-09-25 16:30:45 +02:00
parent 63c4d1387e
commit 02e85ddbfd
20 changed files with 471 additions and 164 deletions
+8 -3
View File
@@ -6,7 +6,7 @@ from unittest.mock import MagicMock
import pytest
from exchangelib import Account, Message
from logwatcher.config import FIXTURE_PATH
from logwatcher.config import FIXTURE_PATH, OUTPUT_PATH
from logwatcher.logging_config import setup_logging
# original log directory
@@ -19,18 +19,21 @@ VALID_LOG_DIR = FIXTURE_PATH / "valid_logs"
INVALID_LOG_DIR = FIXTURE_PATH / "invalid_logs"
# define temp directory only for testing
os.environ["PYTEST_DEBUG_TEMPROOT"] = str(Path("output/test").absolute())
os.environ["PYTEST_DEBUG_TEMPROOT"] = str(OUTPUT_PATH)
@pytest.fixture
def tmp_log_file(tmp_path):
"""Return path of logs logwatcher related."""
return tmp_path / "logwatcher_test.log"
@pytest.fixture(autouse=True)
def tmp_setup_logging(tmp_log_file):
"""Redirige les logs vers un dossier temporaire pendant les tests."""
setup_logging(file_path=tmp_log_file)
@pytest.fixture(name="original_log_dir")
def original_log_dir_fixture() -> Path:
"""Return log directory containing real logs.
@@ -41,6 +44,7 @@ def original_log_dir_fixture() -> Path:
"""
return FIXTURE_PATH / "original_logs"
@pytest.fixture(name="valid_log_dir")
def valid_log_dir_fixture() -> Path:
"""Return log directory containing only valid logs.
@@ -51,6 +55,7 @@ def valid_log_dir_fixture() -> Path:
"""
return FIXTURE_PATH / "valid_logs"
@pytest.fixture(name="invalid_log_dir")
def invalid_log_dir_fixture() -> Path:
"""Return log directory containing invalid logs.
@@ -78,4 +83,4 @@ def make_mock_account():
logs_folder.glob.return_value = [analyzed_folder] if analyzed_folder else []
return account
return _make_mock_account
return _make_mock_account