send_test_email: Throw an error if email not configured.

This should help minimize confusion when folks try to use this before
properly configuring outgoing email.

Thanks to Bruce Eckel for the report.
This commit is contained in:
Tim Abbott
2018-05-14 12:01:48 -07:00
parent 2cca5dc79f
commit a2ed06314d
2 changed files with 10 additions and 0 deletions

View File

@@ -1,13 +1,18 @@
from typing import Any
from django.conf import settings
from django.core.mail import mail_admins, mail_managers, send_mail
from django.core.management import CommandError
from django.core.management.commands import sendtestemail
from zerver.lib.send_email import FromAddress
class Command(sendtestemail.Command):
def handle(self, *args: Any, **kwargs: str) -> None:
if settings.WARN_NO_EMAIL:
raise CommandError("Outgoing email not yet configured, see\n "
"https://zulip.readthedocs.io/en/latest/production/email.html")
subject = "Zulip Test email"
message = ("Success! If you receive this message, you've "
"successfully configured sending email from your "

View File

@@ -28,6 +28,11 @@ class TestCheckConfig(ZulipTestCase):
with self.assertRaisesRegex(CommandError, "Error: You must set asdf in /etc/zulip/settings.py."):
check_config()
@override_settings(WARN_NO_EMAIL=True)
def test_check_send_email(self) -> None:
with self.assertRaisesRegex(CommandError, "Outgoing email not yet configured, see"):
call_command("send_test_email", 'test@example.com')
class TestZulipBaseCommand(ZulipTestCase):
def setUp(self) -> None:
self.zulip_realm = get_realm("zulip")