style: apply ruff format to all source files
This commit is contained in:
@@ -36,12 +36,16 @@ class TestBuildMessage:
|
||||
def test_subject_substitution(self):
|
||||
"""{author} и {period} подставляются в тему."""
|
||||
cfg = _make_email_config(subject="Отчёт {author} за {period}", attach=False)
|
||||
msg = build_message(cfg, "/tmp/report.xlsx", "Кокос А.Н.", "2026-06-01--2026-06-30")
|
||||
msg = build_message(
|
||||
cfg, "/tmp/report.xlsx", "Кокос А.Н.", "2026-06-01--2026-06-30"
|
||||
)
|
||||
assert msg["Subject"] == "Отчёт Кокос А.Н. за 2026-06-01--2026-06-30"
|
||||
|
||||
def test_body_substitution(self):
|
||||
"""{author} и {period} подставляются в тело."""
|
||||
cfg = _make_email_config(body_text="Автор: {author}, период: {period}", attach=False)
|
||||
cfg = _make_email_config(
|
||||
body_text="Автор: {author}, период: {period}", attach=False
|
||||
)
|
||||
msg = build_message(cfg, "/tmp/report.xlsx", "Иванов", "Q1")
|
||||
plain_part = msg.get_payload()[0]
|
||||
assert "Автор: Иванов, период: Q1" in plain_part.as_string()
|
||||
@@ -81,14 +85,20 @@ class TestBuildMessage:
|
||||
msg = build_message(cfg, str(report), "A", "P")
|
||||
assert len(msg.get_payload()) == 1
|
||||
|
||||
@pytest.mark.parametrize("ext,expected_mime", [
|
||||
(".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
|
||||
(".odt", "application/vnd.oasis.opendocument.text"),
|
||||
(".csv", "text/csv"),
|
||||
(".html", "text/html"),
|
||||
(".json", "application/json"),
|
||||
(".md", "text/markdown"),
|
||||
])
|
||||
@pytest.mark.parametrize(
|
||||
"ext,expected_mime",
|
||||
[
|
||||
(
|
||||
".xlsx",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
),
|
||||
(".odt", "application/vnd.oasis.opendocument.text"),
|
||||
(".csv", "text/csv"),
|
||||
(".html", "text/html"),
|
||||
(".json", "application/json"),
|
||||
(".md", "text/markdown"),
|
||||
],
|
||||
)
|
||||
def test_mime_type_by_extension(self, ext, expected_mime, tmp_path):
|
||||
report = tmp_path / f"report{ext}"
|
||||
report.write_text("content")
|
||||
@@ -154,7 +164,9 @@ class TestSendReport:
|
||||
with mock.patch("smtplib.SMTP") as mock_smtp_class:
|
||||
mock_smtp = mock.MagicMock()
|
||||
mock_smtp_class.return_value.__enter__.return_value = mock_smtp
|
||||
mock_smtp.login.side_effect = smtplib.SMTPAuthenticationError(535, b"Bad auth")
|
||||
mock_smtp.login.side_effect = smtplib.SMTPAuthenticationError(
|
||||
535, b"Bad auth"
|
||||
)
|
||||
|
||||
with pytest.raises(RedmineAPIError, match="Ошибка аутентификации SMTP"):
|
||||
send_report(cfg, str(report), "A", "P")
|
||||
@@ -176,7 +188,9 @@ class TestSendReport:
|
||||
with mock.patch("smtplib.SMTP") as mock_smtp_class:
|
||||
mock_smtp = mock.MagicMock()
|
||||
mock_smtp_class.return_value.__enter__.return_value = mock_smtp
|
||||
mock_smtp.send_message.side_effect = smtplib.SMTPException("Something went wrong")
|
||||
mock_smtp.send_message.side_effect = smtplib.SMTPException(
|
||||
"Something went wrong"
|
||||
)
|
||||
|
||||
with pytest.raises(RedmineAPIError, match="Ошибка отправки письма"):
|
||||
send_report(cfg, str(report), "A", "P")
|
||||
|
||||
Reference in New Issue
Block a user