mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	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:
		@@ -1,13 +1,18 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from typing import Any
 | 
					from typing import Any
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from django.conf import settings
 | 
				
			||||||
from django.core.mail import mail_admins, mail_managers, send_mail
 | 
					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 django.core.management.commands import sendtestemail
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from zerver.lib.send_email import FromAddress
 | 
					from zerver.lib.send_email import FromAddress
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Command(sendtestemail.Command):
 | 
					class Command(sendtestemail.Command):
 | 
				
			||||||
    def handle(self, *args: Any, **kwargs: str) -> None:
 | 
					    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"
 | 
					        subject = "Zulip Test email"
 | 
				
			||||||
        message = ("Success!  If you receive this message, you've "
 | 
					        message = ("Success!  If you receive this message, you've "
 | 
				
			||||||
                   "successfully configured sending email from your "
 | 
					                   "successfully configured sending email from your "
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,6 +28,11 @@ class TestCheckConfig(ZulipTestCase):
 | 
				
			|||||||
            with self.assertRaisesRegex(CommandError, "Error: You must set asdf in /etc/zulip/settings.py."):
 | 
					            with self.assertRaisesRegex(CommandError, "Error: You must set asdf in /etc/zulip/settings.py."):
 | 
				
			||||||
                check_config()
 | 
					                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):
 | 
					class TestZulipBaseCommand(ZulipTestCase):
 | 
				
			||||||
    def setUp(self) -> None:
 | 
					    def setUp(self) -> None:
 | 
				
			||||||
        self.zulip_realm = get_realm("zulip")
 | 
					        self.zulip_realm = get_realm("zulip")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user