mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-05 09:21:54 +02:00
review changes
This commit is contained in:
parent
65d89872f2
commit
f26db7185b
3 changed files with 44 additions and 8 deletions
|
@ -77,6 +77,37 @@ class TestEmails(TestCase):
|
|||
# check that an email was sent
|
||||
self.assertTrue(self.mock_client.send_email.called)
|
||||
|
||||
# check the call sequence for the email
|
||||
args, kwargs = self.mock_client.send_email.call_args
|
||||
self.assertIn("Destination", kwargs)
|
||||
self.assertIn("CcAddresses", kwargs["Destination"])
|
||||
|
||||
self.assertEqual(["testy2@town.com", "mayor@igorville.gov"], kwargs["Destination"]["CcAddresses"])
|
||||
|
||||
@boto3_mocking.patching
|
||||
@override_settings(IS_PRODUCTION=True)
|
||||
def test_email_with_cc_in_prod(self):
|
||||
"""Test sending email with cc works in prod"""
|
||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||
send_templated_email(
|
||||
"emails/update_to_approved_domain.txt",
|
||||
"emails/update_to_approved_domain_subject.txt",
|
||||
"doesnotexist@igorville.com",
|
||||
context={"domain": "test", "user": "test", "date": 1, "changes": "test"},
|
||||
bcc_address=None,
|
||||
cc_addresses=["testy2@town.com", "mayor@igorville.gov"],
|
||||
)
|
||||
|
||||
# check that an email was sent
|
||||
self.assertTrue(self.mock_client.send_email.called)
|
||||
|
||||
# check the call sequence for the email
|
||||
args, kwargs = self.mock_client.send_email.call_args
|
||||
self.assertIn("Destination", kwargs)
|
||||
self.assertIn("CcAddresses", kwargs["Destination"])
|
||||
|
||||
self.assertEqual(["testy2@town.com", "mayor@igorville.gov"], kwargs["Destination"]["CcAddresses"])
|
||||
|
||||
@boto3_mocking.patching
|
||||
@less_console_noise_decorator
|
||||
def test_submission_confirmation(self):
|
||||
|
|
|
@ -87,12 +87,6 @@ class TestWithDomainPermissions(TestWithUser):
|
|||
|
||||
self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain)
|
||||
|
||||
self.security_contact, _ = PublicContact.objects.get_or_create(
|
||||
domain=self.domain,
|
||||
contact_type=PublicContact.ContactTypeChoices.SECURITY,
|
||||
email="security@igorville.gov",
|
||||
)
|
||||
|
||||
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_dsdata)
|
||||
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_multdsdata)
|
||||
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_dnssec_none)
|
||||
|
@ -2007,6 +2001,8 @@ class TestDomainChangeNotifications(TestDomainOverview):
|
|||
@less_console_noise_decorator
|
||||
def test_notification_on_org_name_change(self):
|
||||
"""Test that an email is sent when the organization name is changed."""
|
||||
# We may end up sending emails on org name changes later, but it will be addressed
|
||||
# in the portfolio itself, rather than the individual domain.
|
||||
|
||||
self.domain_information.organization_name = "Town of Igorville"
|
||||
self.domain_information.address_line1 = "123 Main St"
|
||||
|
|
|
@ -48,14 +48,19 @@ def send_templated_email( # noqa
|
|||
No valid recipient addresses are provided
|
||||
"""
|
||||
|
||||
# by default assume we can send to all addresses (prod has no whitelist)
|
||||
sendable_cc_addresses = cc_addresses
|
||||
|
||||
if not settings.IS_PRODUCTION: # type: ignore
|
||||
# Split into a function: C901 'send_templated_email' is too complex.
|
||||
# Raises an error if we cannot send an email (due to restrictions).
|
||||
# Does nothing otherwise.
|
||||
_can_send_email(to_address, bcc_address)
|
||||
|
||||
# if we're not in prod, we need to check the whitelist for CC'ed addresses
|
||||
sendable_cc_addresses, blocked_cc_addresses = get_sendable_addresses(cc_addresses)
|
||||
|
||||
if len(sendable_cc_addresses) < len(cc_addresses):
|
||||
if blocked_cc_addresses:
|
||||
logger.warning("Some CC'ed addresses were removed: %s.", blocked_cc_addresses)
|
||||
|
||||
template = get_template(template_name)
|
||||
|
@ -111,7 +116,7 @@ def send_templated_email( # noqa
|
|||
},
|
||||
},
|
||||
)
|
||||
logger.info("Email sent to %s, bcc %s, cc %s", to_address, bcc_address, sendable_cc_addresses)
|
||||
logger.info("Email sent to [%s], bcc [%s], cc %s", to_address, bcc_address, sendable_cc_addresses)
|
||||
else:
|
||||
ses_client = boto3.client(
|
||||
"ses",
|
||||
|
@ -123,6 +128,10 @@ def send_templated_email( # noqa
|
|||
send_email_with_attachment(
|
||||
settings.DEFAULT_FROM_EMAIL, to_address, subject, email_body, attachment_file, ses_client
|
||||
)
|
||||
logger.info(
|
||||
"Email with attachment sent to [%s], bcc [%s], cc %s", to_address, bcc_address, sendable_cc_addresses
|
||||
)
|
||||
|
||||
except Exception as exc:
|
||||
raise EmailSendingError("Could not send SES email.") from exc
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue