intermittent commit
This commit is contained in:
48
tests/test_smtp_helpers.py
Normal file
48
tests/test_smtp_helpers.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from govoplan_mail.backend.config import SmtpConfig
|
||||
from govoplan_mail.backend.sending.smtp import (
|
||||
SmtpConfigurationError,
|
||||
_prepare_smtp_send,
|
||||
_smtp_send_result,
|
||||
)
|
||||
|
||||
|
||||
class SmtpSendHelperTests(unittest.TestCase):
|
||||
def test_prepare_smtp_send_validates_envelope(self):
|
||||
config = SmtpConfig(host="smtp.example.org", port=587, security="starttls")
|
||||
with self.assertRaisesRegex(SmtpConfigurationError, "envelope sender"):
|
||||
_prepare_smtp_send(smtp_config=config, envelope_from="", envelope_recipients=["user@example.org"])
|
||||
with self.assertRaisesRegex(SmtpConfigurationError, "recipient"):
|
||||
_prepare_smtp_send(smtp_config=config, envelope_from="sender@example.org", envelope_recipients=[""])
|
||||
|
||||
def test_prepare_smtp_send_filters_blank_recipients(self):
|
||||
config = SmtpConfig(host="smtp.example.org", port=587, security="starttls")
|
||||
self.assertEqual(
|
||||
_prepare_smtp_send(
|
||||
smtp_config=config,
|
||||
envelope_from="sender@example.org",
|
||||
envelope_recipients=["", "user@example.org"],
|
||||
),
|
||||
("smtp.example.org", 587, ["user@example.org"]),
|
||||
)
|
||||
|
||||
def test_smtp_send_result_decodes_refused_recipients(self):
|
||||
config = SmtpConfig(host="smtp.example.org", port=587, security="starttls")
|
||||
result = _smtp_send_result(
|
||||
smtp_config=config,
|
||||
host="smtp.example.org",
|
||||
port=587,
|
||||
envelope_from="sender@example.org",
|
||||
envelope_recipients=["ok@example.org", "blocked@example.org"],
|
||||
refused={"blocked@example.org": (550, b"blocked")},
|
||||
)
|
||||
self.assertEqual(result.accepted_count, 1)
|
||||
self.assertEqual(result.refused_recipients["blocked@example.org"], (550, "blocked"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user