test(notifier): ✅ add tests for notifier module
This commit is contained in:
@@ -24,13 +24,13 @@ from logwatcher.mail_reader import (
|
||||
|
||||
@pytest.fixture(name="empty_mail")
|
||||
def get_empty_mail_fixture() -> Message:
|
||||
"""A fake Message"""
|
||||
"""Return a fake Message."""
|
||||
return Message(subject="test without attachment", text_body="test")
|
||||
|
||||
|
||||
@pytest.fixture(name="log_mail_with_attachment")
|
||||
def get_log_mail_with_attachment(original_log_dir: Path) -> Message:
|
||||
"""A fake Message with a .txt file attachment."""
|
||||
"""Return a fake Message with a .txt file attachment."""
|
||||
file = original_log_dir / "CR_20260727110008.txt"
|
||||
|
||||
return Message(
|
||||
@@ -49,7 +49,7 @@ def get_log_mail_with_attachment(original_log_dir: Path) -> Message:
|
||||
|
||||
@pytest.fixture(name="log_mail_with_body")
|
||||
def get_log_mail_with_body() -> Message:
|
||||
"""A fake Message with logs in text body."""
|
||||
"""Return a fake Message with logs in text body."""
|
||||
return Message(
|
||||
subject="test with logs in text body",
|
||||
text_body="Compte-rendu du suivi des imports NOSYMAG du 02/09/2026 à 15:00:10\n\n\n"
|
||||
@@ -88,14 +88,14 @@ class FakeProtocol:
|
||||
"""Protocol whose .version access raises UnauthorizedError."""
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
def version(self): # noqa: D102
|
||||
raise UnauthorizedError("invalid credentials")
|
||||
|
||||
|
||||
class FakeAccount:
|
||||
"""Account with a protocol that raises on version access."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self): # noqa: D107
|
||||
self.protocol = FakeProtocol()
|
||||
|
||||
|
||||
@@ -103,14 +103,14 @@ class OkProtocol:
|
||||
"""Protocol whose .version succeeds."""
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
def version(self): # noqa: D102
|
||||
return MagicMock()
|
||||
|
||||
|
||||
class OkAccount:
|
||||
"""Account with a protocol that returns a version successfully."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self): # noqa: D102
|
||||
self.protocol = OkProtocol()
|
||||
|
||||
|
||||
@@ -154,10 +154,7 @@ def test_find_log_attachment_accepts_no_extension(empty_mail: Message):
|
||||
def test_find_log_attachment_rejects_other_names(
|
||||
empty_mail: Message,
|
||||
):
|
||||
"""
|
||||
Rejects attachments not starting with CR_ even with .txt
|
||||
or .log extension or extensionless.
|
||||
"""
|
||||
"""Rejects attachments not starting with CR_ even with .txt or .log extension or extensionless."""
|
||||
attachments = (
|
||||
FileAttachment(
|
||||
name="attachment.pdf",
|
||||
|
||||
Reference in New Issue
Block a user