Limit email chatter in fixtures

This commit is contained in:
zandercymatics 2023-12-21 10:06:45 -07:00
parent 91577e13de
commit 9e65d687ac
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 14 additions and 5 deletions

View file

@ -218,5 +218,8 @@ class DomainFixture(DomainApplicationFixture):
creator=user, status=DomainApplication.ApplicationStatus.IN_REVIEW creator=user, status=DomainApplication.ApplicationStatus.IN_REVIEW
).last() ).last()
logger.debug(f"Approving {application} for {user}") logger.debug(f"Approving {application} for {user}")
application.approve()
# We don't want fixtures sending out real emails to
# fake email addresses, so we just skip that and log it instead
application.approve(do_fake_send_email=True)
application.save() application.save()

View file

@ -561,8 +561,8 @@ class DomainApplication(TimeStampedModel):
return not self.approved_domain.is_active() return not self.approved_domain.is_active()
return True return True
def _send_status_update_email(self, new_status, email_template, email_template_subject): def _send_status_update_email(self, new_status, email_template, email_template_subject, do_fake_send_email=False):
"""Send a atatus update email to the submitter. """Send a status update email to the submitter.
The email goes to the email address that the submitter gave as their The email goes to the email address that the submitter gave as their
contact information. If there is not submitter information, then do contact information. If there is not submitter information, then do
@ -571,7 +571,12 @@ class DomainApplication(TimeStampedModel):
if self.submitter is None or self.submitter.email is None: if self.submitter is None or self.submitter.email is None:
logger.warning(f"Cannot send {new_status} email, no submitter email address.") logger.warning(f"Cannot send {new_status} email, no submitter email address.")
return return None
if do_fake_send_email:
logger.info(f"Email was not sent. Would send {new_status} to email: {self.submitter.email}")
return None
try: try:
send_templated_email( send_templated_email(
email_template, email_template,
@ -651,7 +656,7 @@ class DomainApplication(TimeStampedModel):
], ],
target=ApplicationStatus.APPROVED, target=ApplicationStatus.APPROVED,
) )
def approve(self): def approve(self, do_fake_send_email=False):
"""Approve an application that has been submitted. """Approve an application that has been submitted.
This has substantial side-effects because it creates another database This has substantial side-effects because it creates another database
@ -680,6 +685,7 @@ class DomainApplication(TimeStampedModel):
"application approved", "application approved",
"emails/status_change_approved.txt", "emails/status_change_approved.txt",
"emails/status_change_approved_subject.txt", "emails/status_change_approved_subject.txt",
do_fake_send_email,
) )
@transition( @transition(