test_send.py 955 B

123456789101112131415161718192021222324252627282930313233343536373839
  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, cls_smtp=MockServer)
  20. # This should fail but we test everything else goes through
  21. msg = email.send(
  22. subject="An example",
  23. receivers=['koli.mikael@example.com']
  24. )
  25. assert isinstance(msg, EmailMessage)
  26. def test_send_function():
  27. # This should fail but we test everything else goes through
  28. with pytest.raises(ConnectionRefusedError):
  29. send_email(host="localhost", port=0, subject="An example")