refactor(tests): ✅ udpate tests

update tests by adding a test_utils module
This commit is contained in:
2026-09-15 13:20:20 +02:00
parent 555af86884
commit 20ad43d694
7 changed files with 111 additions and 96 deletions
+37
View File
@@ -0,0 +1,37 @@
from unittest.mock import MagicMock
from logwatcher.utils import get_or_create_folder
def test_get_or_create_analyzed_folder_exists(make_mock_account, monkeypatch):
"""
Returns the existing 'Analyzed' folder without creating it.
Args:
make_mock_account: Fake account owning the Logs folder.
monkeypatch: MonkeyPatch to generate test context
"""
existing_folder = MagicMock()
account = make_mock_account(analyzed_folder=existing_folder)
fake_folder_cls = MagicMock()
with monkeypatch.context() as m:
m.setattr("logwatcher.utils.Folder", fake_folder_cls)
result = get_or_create_folder(account, "Analyzed")
assert result is existing_folder
fake_folder_cls.assert_not_called()
def test_get_or_create_analyzed_folder_creates(make_mock_account, monkeypatch):
"""Creates the 'Analyzed' folder when it doesn't exist."""
account = make_mock_account(analyzed_folder=None)
fake_folder_instance = MagicMock()
fake_folder_cls = MagicMock(return_value=fake_folder_instance)
with monkeypatch.context() as m:
m.setattr("logwatcher.utils.Folder", fake_folder_cls)
result = get_or_create_folder(account, "Analyzed")
assert result is fake_folder_instance
fake_folder_instance.save.assert_called_once()