Skip to content

Commit

Permalink
refactore code
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro committed Nov 6, 2024
1 parent 0390c27 commit 06e91ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions newsroom/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def _send_email(to, subject, text_body, cc=None, html_body=None, sender=None, se
if sender is None:
sender = current_app.config["MAIL_DEFAULT_SENDER"]

if cc is None:
cc = []

if sender_name is not None:
sender = (sender_name, sender)

Expand All @@ -106,7 +109,7 @@ def _send_email(to, subject, text_body, cc=None, html_body=None, sender=None, se
return app.mail.send(msg)


def send_email(to, subject, text_body, cc=[], html_body=None, sender=None, sender_name=None, attachments_info=None):
def send_email(to, subject, text_body, cc=None, html_body=None, sender=None, sender_name=None, attachments_info=None):
"""
Sends the email
:param to: List of recipients
Expand Down Expand Up @@ -247,7 +250,7 @@ def send_template_email(
to: List[str],
template: str,
template_kwargs: Optional[TemplateKwargs] = None,
cc: Optional[List[str]] = [],
cc: Optional[List[str]] = None,
**kwargs: EmailKwargs,
) -> None:
"""Send email to list of recipients using default locale."""
Expand All @@ -263,7 +266,7 @@ def _send_localized_email(
timezone: str,
template_kwargs: TemplateKwargs,
email_kwargs: EmailKwargs,
cc: Optional[List[str]] = [],
cc: Optional[List[str]] = None,
) -> None:
language = to_email_language(language)
email_templates = get_resource_service("email_templates")
Expand Down
3 changes: 3 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def mock_send_email(
if sender is None:
sender = app.config["MAIL_DEFAULT_SENDER"]

if cc is None:
cc = []

msg = SuperdeskMessage(subject=subject, sender=sender, recipients=to, cc=cc)
msg.body = text_body
msg.html = html_body
Expand Down

0 comments on commit 06e91ad

Please sign in to comment.