Add logging, templatize SUMMARY in email templates, templatize complete_application in tests, to integrate FSM inspect the status change that was made in the admin view here and call the transition method that's now defined in the model

This commit is contained in:
rachidatecs 2023-06-12 17:29:30 -04:00
parent 54efe9ee32
commit f3bf3f9e66
No known key found for this signature in database
GPG key ID: 3CEBBFA7325E5525
9 changed files with 190 additions and 329 deletions

View file

@ -1,8 +1,8 @@
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 registrar.models import DomainApplication, User
from .common import completed_application
from django.conf import settings
from unittest.mock import MagicMock
@ -14,73 +14,6 @@ class TestDomainApplicationAdmin(TestCase):
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
@ -92,7 +25,7 @@ class TestDomainApplicationAdmin(TestCase):
with boto3_mocking.clients.handler_for("sesv2", mock_client):
# Create a sample application
application = self._completed_application()
application = completed_application(status=DomainApplication.SUBMITTED)
# Create a mock request
request = self.factory.post(