test_send.py 974 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from email.message import EmailMessage
  2. import pytest
  3. from redmail import EmailSender, send_email
  4. class MockServer:
  5. def __init__(self, host, port):
  6. self.host = host
  7. self.port = port
  8. self.is_login = False
  9. def starttls(self):
  10. return
  11. def login(self, user=None, password=None):
  12. self.is_login = True
  13. return
  14. def send_message(self, msg):
  15. return
  16. def quit(self):
  17. return
  18. def test_send():
  19. email = EmailSender(host="localhost", port=0)
  20. email._cls_smtp_server = MockServer
  21. # This should fail but we test everything else goes through
  22. msg = email.send(
  23. subject="An example",
  24. receivers=['koli.mikael@example.com']
  25. )
  26. assert isinstance(msg, EmailMessage)
  27. def test_send_function():
  28. # This should fail but we test everything else goes through
  29. with pytest.raises(ConnectionRefusedError):
  30. send_email(host="localhost", port=0, subject="An example")