Implement 'investigating' email templates and tigger email send on admin domain application save, status change to investidated.

This commit is contained in:
rachidatecs 2023-06-07 13:19:22 -04:00
parent d4162c5d9c
commit 31295053f9
No known key found for this signature in database
GPG key ID: 3CEBBFA7325E5525
4 changed files with 245 additions and 2 deletions

View file

@ -0,0 +1,120 @@
from django.test import TestCase, RequestFactory
from django.contrib.admin.sites import AdminSite
from registrar.admin import DomainApplicationAdmin
from django.contrib.auth import get_user_model
from registrar.models import Contact, DraftDomain, Website, DomainApplication, User
from django.conf import settings
from unittest.mock import MagicMock, ANY
import boto3_mocking # type: ignore
class TestDomainApplicationAdmin(TestCase):
def setUp(self):
self.site = AdminSite()
self.factory = RequestFactory()
def _completed_application(
self,
has_other_contacts=True,
has_current_website=True,
has_alternative_gov_domain=True,
has_type_of_work=True,
has_anything_else=True,
):
"""A completed domain application."""
user = get_user_model().objects.create(username="username")
ao, _ = Contact.objects.get_or_create(
first_name="Testy",
last_name="Tester",
title="Chief Tester",
email="testy@town.com",
phone="(555) 555 5555",
)
domain, _ = DraftDomain.objects.get_or_create(name="city.gov")
alt, _ = Website.objects.get_or_create(website="city1.gov")
current, _ = Website.objects.get_or_create(website="city.com")
you, _ = Contact.objects.get_or_create(
first_name="Testy you",
last_name="Tester you",
title="Admin Tester",
email="mayor@igorville.gov",
phone="(555) 555 5556",
)
other, _ = Contact.objects.get_or_create(
first_name="Testy2",
last_name="Tester2",
title="Another Tester",
email="testy2@town.com",
phone="(555) 555 5557",
)
domain_application_kwargs = dict(
organization_type="federal",
federal_type="executive",
purpose="Purpose of the site",
is_policy_acknowledged=True,
organization_name="Testorg",
address_line1="address 1",
address_line2="address 2",
state_territory="NY",
zipcode="10002",
authorizing_official=ao,
requested_domain=domain,
submitter=you,
creator=user,
)
if has_type_of_work:
domain_application_kwargs["type_of_work"] = "e-Government"
if has_anything_else:
domain_application_kwargs["anything_else"] = "There is more"
application, _ = DomainApplication.objects.get_or_create(
**domain_application_kwargs
)
if has_other_contacts:
application.other_contacts.add(other)
if has_current_website:
application.current_websites.add(current)
if has_alternative_gov_domain:
application.alternative_domains.add(alt)
return application
@boto3_mocking.patching
def test_save_model_sends_email_on_property_change(self):
# make sure there is no user with this email
EMAIL = "mayor@igorville.gov"
User.objects.filter(email=EMAIL).delete()
mock_client = MagicMock()
mock_client_instance = mock_client.return_value
with boto3_mocking.clients.handler_for("sesv2", mock_client):
# Create a sample application
application = self._completed_application()
# Create a mock request
request = self.factory.post(
"/admin/registrar/domainapplication/{}/change/".format(application.pk)
)
# Create an instance of the model admin
model_admin = DomainApplicationAdmin(DomainApplication, self.site)
# Modify the application's property
application.status = "investigating"
# Use the model admin's save_model method
model_admin.save_model(request, application, form=None, change=True)
# Assert that the email was sent
mock_client_instance.send_email.assert_called_once_with(
FromEmailAddress=settings.DEFAULT_FROM_EMAIL,
Destination={"ToAddresses": [EMAIL]},
Content=ANY,
)
# Cleanup
application.delete()