test(notifier): ✅ add tests for notifier module
This commit is contained in:
+23
-15
@@ -4,7 +4,7 @@ from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from exchangelib import Message
|
||||
from exchangelib import Account, Message
|
||||
|
||||
from logwatcher.config import FIXTURE_PATH
|
||||
from logwatcher.logging_config import setup_logging
|
||||
@@ -23,7 +23,8 @@ os.environ["PYTEST_DEBUG_TEMPROOT"] = str(Path("output/test").absolute())
|
||||
|
||||
@pytest.fixture
|
||||
def tmp_log_file(tmp_path):
|
||||
return tmp_path / "logwatcher_test.log"
|
||||
"""Return path of logs logwatcher related."""
|
||||
return tmp_path / "logwatcher_test.log"
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def tmp_setup_logging(tmp_log_file):
|
||||
@@ -32,39 +33,46 @@ def tmp_setup_logging(tmp_log_file):
|
||||
|
||||
@pytest.fixture(name="original_log_dir")
|
||||
def original_log_dir_fixture() -> Path:
|
||||
"""
|
||||
All real log files provided by N2 technicians.
|
||||
Used for integration tests: these files contain both valid lines
|
||||
and lines to be ignored (system logs, empty lines, directory headers).
|
||||
"""Return log directory containing real logs.
|
||||
|
||||
All real log files provided by N2 technicians.
|
||||
Used for integration tests: these files contain both valid lines
|
||||
and lines to be ignored (system logs, empty lines, directory headers).
|
||||
"""
|
||||
return FIXTURE_PATH / "original_logs"
|
||||
|
||||
@pytest.fixture(name="valid_log_dir")
|
||||
def valid_log_dir_fixture() -> Path:
|
||||
"""
|
||||
All valid log files provided by N2 technicians.
|
||||
Used for integration tests: these files contain both relevant and irrelevant logs
|
||||
for N2 technicians.
|
||||
"""Return log directory containing only valid logs.
|
||||
|
||||
All valid log files provided by N2 technicians.
|
||||
Used for integration tests: these files contain both relevant and irrelevant logs
|
||||
for N2 technicians.
|
||||
"""
|
||||
return FIXTURE_PATH / "valid_logs"
|
||||
|
||||
@pytest.fixture(name="invalid_log_dir")
|
||||
def invalid_log_dir_fixture() -> Path:
|
||||
"""
|
||||
All invalid log files created for testing only.
|
||||
Used for integration tests of parsing.
|
||||
"""Return log directory containing invalid logs.
|
||||
|
||||
All invalid log files created for testing only.
|
||||
Used for integration tests of parsing.
|
||||
"""
|
||||
return FIXTURE_PATH / "invalid_logs"
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def make_mock_account():
|
||||
"""A fake Account with a msg_folder_root returning a fake Logs folder."""
|
||||
"""Create a fake Account.
|
||||
|
||||
A fake Account with a msg_folder_root returning a fake Logs folder.
|
||||
"""
|
||||
|
||||
def _make_mock_account(
|
||||
messages: list[Message] | None = None, analyzed_folder: MagicMock | None = None
|
||||
):
|
||||
account = MagicMock()
|
||||
account = MagicMock(spec=Account)
|
||||
account.fullname = "fake"
|
||||
logs_folder = account.msg_folder_root.__truediv__.return_value
|
||||
logs_folder.all.return_value = messages or []
|
||||
logs_folder.glob.return_value = [analyzed_folder] if analyzed_folder else []
|
||||
|
||||
Reference in New Issue
Block a user