Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

locmem.py 884B

123456789101112131415161718192021222324252627282930
  1. """
  2. Backend for test environment.
  3. """
  4. from django.core import mail
  5. from django.core.mail.backends.base import BaseEmailBackend
  6. class EmailBackend(BaseEmailBackend):
  7. """
  8. An email backend for use during test sessions.
  9. The test connection stores email messages in a dummy outbox,
  10. rather than sending them out on the wire.
  11. The dummy outbox is accessible through the outbox instance attribute.
  12. """
  13. def __init__(self, *args, **kwargs):
  14. super().__init__(*args, **kwargs)
  15. if not hasattr(mail, 'outbox'):
  16. mail.outbox = []
  17. def send_messages(self, messages):
  18. """Redirect messages to the dummy outbox"""
  19. msg_count = 0
  20. for message in messages: # .message() triggers header validation
  21. message.message()
  22. mail.outbox.append(message)
  23. msg_count += 1
  24. return msg_count