summaryrefslogtreecommitdiff
path: root/tests/mail/test_sendtestemail.py
diff options
context:
space:
mode:
authorLoek van Gent <loek@1procentclub.nl>2015-03-07 13:55:59 +0100
committerTim Graham <timograham@gmail.com>2015-03-20 12:03:50 -0400
commitd898ba1bec588450d591ebd5076993f96d05eb24 (patch)
tree04d40bad0735180546fbc8f0eb7bec3fd2cd3b2a /tests/mail/test_sendtestemail.py
parent55f12f8709f0604df7e1817a4c114ead1fb9a311 (diff)
Fixed #24419 -- Added sendtestemail management command
Diffstat (limited to 'tests/mail/test_sendtestemail.py')
-rw-r--r--tests/mail/test_sendtestemail.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/mail/test_sendtestemail.py b/tests/mail/test_sendtestemail.py
new file mode 100644
index 0000000000..7a4203fb75
--- /dev/null
+++ b/tests/mail/test_sendtestemail.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.core import mail
+from django.core.management import call_command
+from django.core.management.base import CommandError
+from django.test import SimpleTestCase
+from django.utils.six import StringIO
+
+
+class SendTestEmailManagementCommand(SimpleTestCase):
+ """
+ Test the sending of a test email using the `sendtestemail` command.
+ """
+
+ def test_send_test_email(self):
+ """
+ The mail is sent with the correct subject and recipient.
+ """
+ recipient = "joe@somewhere.org"
+ call_command("sendtestemail", recipient)
+ self.assertEqual(len(mail.outbox), 1)
+ mail_message = mail.outbox[0]
+ self.assertEqual(mail_message.subject[0:15], 'Test email from')
+ self.assertEqual(mail_message.recipients(), [recipient])
+
+ def test_send_test_email_with_multiple_addresses(self):
+ """
+ The mail may be sent with multiple recipients.
+ """
+ recipients = ["joe@somewhere.org", "jane@elsewhere.net"]
+ call_command("sendtestemail", recipients[0], recipients[1])
+ self.assertEqual(len(mail.outbox), 1)
+ mail_message = mail.outbox[0]
+ self.assertEqual(mail_message.subject[0:15], 'Test email from')
+ self.assertEqual(mail_message.recipients(), recipients)
+
+ def test_send_test_email_missing_recipient(self):
+ """
+ A CommandError is raised if no recipients are specified.
+ """
+ with self.assertRaisesMessage(CommandError, 'You must provide at least one destination email'):
+ call_command("sendtestemail")