mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 09:27:43 +00:00
test_emails: Use zerver.lib.send_email for rendering email.
Previously the rendering code in test_emails.py did not match the rendering code in send_email.py. This commit removes the duplication to reduce the chance they drift in the future. This commit also changes test_emails.html to ensure that we always display both the HTML and text versions of an email.
This commit is contained in:
@@ -16,8 +16,9 @@ def display_email(user):
|
||||
# https://github.com/zulip/zulip/issues/4676 is resolved
|
||||
return user.email
|
||||
|
||||
def send_email(template_prefix, to_email, from_email=None, reply_to_email=None, context={}):
|
||||
# type: (str, Text, Optional[Text], Optional[Text], Dict[str, Any]) -> bool
|
||||
# Intended only for test code
|
||||
def build_email(template_prefix, to_email, from_email=None, reply_to_email=None, context={}):
|
||||
# type: (str, Text, Optional[Text], Optional[Text], Dict[str, Any]) -> EmailMultiAlternatives
|
||||
subject = loader.render_to_string(template_prefix + '.subject',
|
||||
context=context, using='Jinja2_plaintext').strip()
|
||||
message = loader.render_to_string(template_prefix + '.txt',
|
||||
@@ -36,6 +37,12 @@ def send_email(template_prefix, to_email, from_email=None, reply_to_email=None,
|
||||
mail = EmailMultiAlternatives(subject, message, from_email, [to_email], reply_to=reply_to)
|
||||
if html_message is not None:
|
||||
mail.attach_alternative(html_message, 'text/html')
|
||||
return mail
|
||||
|
||||
def send_email(template_prefix, to_email, from_email=None, reply_to_email=None, context={}):
|
||||
# type: (str, Text, Optional[Text], Optional[Text], Dict[str, Any]) -> bool
|
||||
mail = build_email(template_prefix, to_email, from_email=from_email,
|
||||
reply_to_email=reply_to_email, context=context)
|
||||
return mail.send() > 0
|
||||
|
||||
def send_email_to_user(template_prefix, user, from_email=None, context={}):
|
||||
|
||||
Reference in New Issue
Block a user