This commit is contained in:
matthewswspence 2024-09-24 10:48:23 -05:00
parent 89f19bf807
commit 9de6831591
No known key found for this signature in database
GPG key ID: FB458202A7852BA4

View file

@ -1978,36 +1978,47 @@ class TestDomainChangeNotifications(TestDomainOverview):
AllowedEmail(email="info@example.com"),
]
AllowedEmail.objects.bulk_create(allowed_emails)
def setUp(self):
super().setUp()
self.mock_client_class = MagicMock()
self.mock_client = self.mock_client_class.return_value
@classmethod
def tearDownClass(cls):
super().tearDownClass()
AllowedEmail.objects.all().delete()
@boto3_mocking.patching
def test_notification_email_sent_on_org_name_change(self):
"""Test that an email is sent when the organization name is changed."""
with patch('registrar.utility.email.boto3.client') as mock_boto3_client:
mock_ses_client = mock_boto3_client.return_value
self.domain_information.organization_name = "Town of Igorville"
self.domain_information.save()
org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id}))
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
self.domain_information.organization_name = "Town of Igorville"
self.domain_information.save()
org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id}))
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
org_name_page.form["organization_name"] = "Not igorville"
org_name_page.form["organization_name"] = "Not igorville"
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
success_result_page = org_name_page.form.submit()
# Check that the page loads successfully
self.assertEqual(success_result_page.status_code, 200)
self.assertContains(success_result_page, "Not igorville")
self.assertEqual(success_result_page.status_code, 200)
self.assertContains(success_result_page, "Not igorville")
# Check that an email was sent
mock_ses_client.send_email.assert_called_once()
# Check email content
call_kwargs = mock_ses_client.send_email.call_args[1]
self.assertEqual(call_kwargs['FromEmailAddress'], settings.DEFAULT_FROM_EMAIL)
self.assertIn('DOMAIN: Igorville.gov', call_kwargs['Content']['Simple']['Subject']['Data'])
self.assertIn('INFORMATION UPDATED: Org Name/Address', call_kwargs['Content']['Simple']['Body']['Text']['Data'])
# Check that an email was sent
self.assertTrue(self.mock_client.send_email.called)
# Check email content
# check the call sequence for the email
args, kwargs = self.mock_client.send_email.call_args
self.assertIn("Content", kwargs)
self.assertIn("Simple", kwargs["Content"])
self.assertIn("Subject", kwargs["Content"]["Simple"])
self.assertIn("Body", kwargs["Content"]["Simple"])
# check for things in the email content (not an exhaustive list)
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
self.assertIn("DOMAIN:", body)