forked from Github-Mirrors/canaille
unit tests: sending mail with invalid recipients
This commit is contained in:
parent
a7f340e778
commit
20ffc0fb84
1 changed files with 16 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
|||
import smtplib
|
||||
import warnings
|
||||
from unittest import mock
|
||||
|
||||
|
@ -17,6 +18,21 @@ def test_send_test_email(testclient, logged_admin, smtpd):
|
|||
assert len(smtpd.messages) == 1
|
||||
|
||||
|
||||
@mock.patch("smtplib.SMTP")
|
||||
def test_send_test_email_recipient_refused(SMTP, testclient, logged_admin, smtpd):
|
||||
SMTP.side_effect = mock.Mock(
|
||||
side_effect=smtplib.SMTPRecipientsRefused("test@test.com")
|
||||
)
|
||||
assert len(smtpd.messages) == 0
|
||||
|
||||
res = testclient.get("/admin/mail")
|
||||
res.form["mail"] = "test@test.com"
|
||||
res = res.form.submit()
|
||||
assert "The test invitation mail has been sent correctly" in res.text
|
||||
|
||||
assert len(smtpd.messages) == 0
|
||||
|
||||
|
||||
@mock.patch("smtplib.SMTP")
|
||||
def test_send_test_email_failed(SMTP, testclient, logged_admin):
|
||||
SMTP.side_effect = mock.Mock(side_effect=OSError("unit test mail error"))
|
||||
|
|
Loading…
Reference in a new issue