Skip to content

Instantly share code, notes, and snippets.

@anandology
Created May 24, 2021 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anandology/f3be96a32e23507c1284d23b6ec76084 to your computer and use it in GitHub Desktop.
Save anandology/f3be96a32e23507c1284d23b6ec76084 to your computer and use it in GitHub Desktop.
email test using py.test
def test_sendmail(monkeypatch):
emails = []
def mock_sendmail(self, from_addr, to_addrs, msg, mail_options=(), rcpt_options=()):
emails.append(dict(from_addr=from_addr, to_addrs=to_addrs, msg=msg))
monkeypatch.setattr(smtplib.SMTP, "sendmail", mock_sendmail)
frappe.sendmail(
recipients=['test@example.com'],
sender='noreply@example.com',
subject='Test Mail',
message='Dear Test, welcome!',
delayed=False)
assert len(emails) == 1
email = emails[0]
assert email['from_addr'] == 'noreply@example.com'
assert email['to_addrs'] == ['test@example.com']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment