mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Un-hardcode message_id in test backend; add console backend
* Un-hardcode status message_id in test backend For the test EmailBackend, get message ID's based on array position in `mail.outbox`, so that tests can predict the message ID. * Add a console backend for use in development Adds an EmailBackend derived from both Anymail's test backend and Django's console backend, to provide anymail statuses and signal handling while printing messages to the console. For use during development on localhost. Closes #87
This commit is contained in:
committed by
Mike Edmunds
parent
09def30868
commit
771d4040df
@@ -27,6 +27,11 @@ class EmailBackend(AnymailBaseBackend):
|
||||
if not hasattr(mail, 'outbox'):
|
||||
mail.outbox = [] # see django.core.mail.backends.locmem
|
||||
|
||||
def get_esp_message_id(self, message):
|
||||
# Get a unique ID for the message. The message must have been added to
|
||||
# the outbox first.
|
||||
return mail.outbox.index(message)
|
||||
|
||||
def build_message_payload(self, message, defaults):
|
||||
return TestPayload(backend=self, message=message, defaults=defaults)
|
||||
|
||||
@@ -41,7 +46,10 @@ class EmailBackend(AnymailBaseBackend):
|
||||
raise response
|
||||
except AttributeError:
|
||||
# Default is to return 'sent' for each recipient
|
||||
status = AnymailRecipientStatus(message_id=1, status='sent')
|
||||
status = AnymailRecipientStatus(
|
||||
message_id=self.get_esp_message_id(message),
|
||||
status='sent'
|
||||
)
|
||||
response = {
|
||||
'recipient_status': {email: status for email in payload.recipient_emails}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user