mirror of
https://github.com/django/django.git
synced 2025-06-09 05:29:13 +00:00
Adapted sendtestemail to be more argparse-ish
This commit is contained in:
parent
0d9b018e07
commit
ba37ac749e
@ -7,14 +7,15 @@ from django.core.management.base import BaseCommand, CommandError
|
|||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = "Sends a test email to the email addresses specified as arguments."
|
help = "Sends a test email to the email addresses specified as arguments."
|
||||||
args = "<email1 email2 ...>"
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument('email', nargs='+',
|
||||||
|
help='One or more email addresses to send the test mail to.')
|
||||||
|
|
||||||
def handle(self, *args, **kwargs):
|
def handle(self, *args, **kwargs):
|
||||||
if not args:
|
|
||||||
raise CommandError('You must provide at least one destination email.')
|
|
||||||
send_mail(
|
send_mail(
|
||||||
subject='Test email from %s on %s' % (socket.gethostname(), datetime.datetime.now()),
|
subject='Test email from %s on %s' % (socket.gethostname(), datetime.datetime.now()),
|
||||||
message="If you\'re reading this, it was successful.",
|
message="If you\'re reading this, it was successful.",
|
||||||
from_email=None,
|
from_email=None,
|
||||||
recipient_list=args,
|
recipient_list=kwargs['email'],
|
||||||
)
|
)
|
||||||
|
@ -32,10 +32,3 @@ class SendTestEmailManagementCommand(SimpleTestCase):
|
|||||||
mail_message = mail.outbox[0]
|
mail_message = mail.outbox[0]
|
||||||
self.assertEqual(mail_message.subject[0:15], 'Test email from')
|
self.assertEqual(mail_message.subject[0:15], 'Test email from')
|
||||||
self.assertEqual(mail_message.recipients(), recipients)
|
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")
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user