From e30650abee974197b5edeab624f80964b7b54b8b Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 14 May 2024 14:00:32 -0600 Subject: [PATCH 1/3] Set federal agency if none exist --- src/registrar/models/domain_request.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/registrar/models/domain_request.py b/src/registrar/models/domain_request.py index 09f2b9fab..57f901779 100644 --- a/src/registrar/models/domain_request.py +++ b/src/registrar/models/domain_request.py @@ -751,6 +751,10 @@ def approve(self, send_email=True): domain request into an admin on that domain. It also triggers an email notification.""" + if self.federal_agency is None: + self.federal_agency = "Non-Federal Agency" + self.save() + # create the domain Domain = apps.get_model("registrar.Domain") From af20a9b52a6daca90c6b43c49bdb046c86b43fde Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 14 May 2024 14:50:17 -0600 Subject: [PATCH 2/3] Add unit test --- src/registrar/models/domain_request.py | 3 ++- src/registrar/tests/test_models.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/registrar/models/domain_request.py b/src/registrar/models/domain_request.py index 57f901779..2501cdc87 100644 --- a/src/registrar/models/domain_request.py +++ b/src/registrar/models/domain_request.py @@ -9,6 +9,7 @@ from django_fsm import FSMField, transition # type: ignore from django.utils import timezone from registrar.models.domain import Domain +from registrar.models.federal_agency import FederalAgency from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes @@ -752,7 +753,7 @@ def approve(self, send_email=True): notification.""" if self.federal_agency is None: - self.federal_agency = "Non-Federal Agency" + self.federal_agency = FederalAgency.objects.filter(agency="Non-Federal Agency").first() self.save() # create the domain diff --git a/src/registrar/tests/test_models.py b/src/registrar/tests/test_models.py index 1558ab310..847168356 100644 --- a/src/registrar/tests/test_models.py +++ b/src/registrar/tests/test_models.py @@ -12,6 +12,7 @@ DraftDomain, DomainInvitation, UserDomainRole, + FederalAgency, ) import boto3_mocking @@ -75,6 +76,26 @@ def assertNotRaises(self, exception_type): with less_console_noise(): return self.assertRaises(Exception, None, exception_type) + def test_federal_agency_set_to_non_federal_on_approve(self): + """Ensures that when the federal_agency field is 'none' when .approve() is called, + the field is set to the 'Non-Federal Agency' record""" + domain_request = completed_domain_request( + status=DomainRequest.DomainRequestStatus.IN_REVIEW, + name="city2.gov", + federal_agency=None, + ) + + # Ensure that the federal agency is None + self.assertEqual(domain_request.federal_agency, None) + + # Approve the request + domain_request.approve() + self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.APPROVED) + + # After approval, it should be "Non-Federal agency" + expected_federal_agency = FederalAgency.objects.filter(agency="Non-Federal Agency").first() + self.assertEqual(domain_request.federal_agency, expected_federal_agency) + def test_empty_create_fails(self): """Can't create a completely empty domain request. NOTE: something about theexception this test raises messes up with the From 70cd55f623cf3dd69131cd288fcb8302fe4dae7a Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Wed, 15 May 2024 08:16:46 -0600 Subject: [PATCH 3/3] Fix unit test --- src/registrar/tests/test_admin.py | 2 +- src/registrar/tests/test_models.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index 632099dde..4a6e76e3d 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -646,7 +646,7 @@ def test_short_org_name_in_domains_list(self): response = self.client.get("/admin/registrar/domain/") # There are 4 template references to Federal (4) plus four references in the table # for our actual domain_request - self.assertContains(response, "Federal", count=54) + self.assertContains(response, "Federal", count=56) # This may be a bit more robust self.assertContains(response, '