Files
logwatcher/tests/test_mail_utils.py
T

37 lines
1.3 KiB
Python

from unittest.mock import MagicMock
from logwatcher.mail_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.mail_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.mail_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()