Fixed #27036 -- Made locmem email backend's send_messages() accept generators.
This commit is contained in:
parent
35225e2ade
commit
004ba05bca
|
@ -24,6 +24,6 @@ class EmailBackend(BaseEmailBackend):
|
||||||
msg_count = 0
|
msg_count = 0
|
||||||
for message in messages: # .message() triggers header validation
|
for message in messages: # .message() triggers header validation
|
||||||
message.message()
|
message.message()
|
||||||
|
mail.outbox.append(message)
|
||||||
msg_count += 1
|
msg_count += 1
|
||||||
mail.outbox.extend(messages)
|
|
||||||
return msg_count
|
return msg_count
|
||||||
|
|
|
@ -748,12 +748,16 @@ class BaseEmailBackendTests(HeadersCheckMixin, object):
|
||||||
def test_send_many(self):
|
def test_send_many(self):
|
||||||
email1 = EmailMessage('Subject', 'Content1', 'from@example.com', ['to@example.com'])
|
email1 = EmailMessage('Subject', 'Content1', 'from@example.com', ['to@example.com'])
|
||||||
email2 = EmailMessage('Subject', 'Content2', 'from@example.com', ['to@example.com'])
|
email2 = EmailMessage('Subject', 'Content2', 'from@example.com', ['to@example.com'])
|
||||||
num_sent = mail.get_connection().send_messages([email1, email2])
|
# send_messages() may take a list or a generator.
|
||||||
self.assertEqual(num_sent, 2)
|
emails_lists = ([email1, email2], (email for email in [email1, email2]))
|
||||||
messages = self.get_mailbox_content()
|
for emails_list in emails_lists:
|
||||||
self.assertEqual(len(messages), 2)
|
num_sent = mail.get_connection().send_messages(emails_list)
|
||||||
self.assertEqual(messages[0].get_payload(), "Content1")
|
self.assertEqual(num_sent, 2)
|
||||||
self.assertEqual(messages[1].get_payload(), "Content2")
|
messages = self.get_mailbox_content()
|
||||||
|
self.assertEqual(len(messages), 2)
|
||||||
|
self.assertEqual(messages[0].get_payload(), 'Content1')
|
||||||
|
self.assertEqual(messages[1].get_payload(), 'Content2')
|
||||||
|
self.flush_mailbox()
|
||||||
|
|
||||||
def test_send_verbose_name(self):
|
def test_send_verbose_name(self):
|
||||||
email = EmailMessage("Subject", "Content", '"Firstname Sürname" <from@example.com>',
|
email = EmailMessage("Subject", "Content", '"Firstname Sürname" <from@example.com>',
|
||||||
|
|
Loading…
Reference in New Issue