Skip to content

Commit

Permalink
Merge pull request #2169 from cisagov/za/2147-show-non-federal-for-fe…
Browse files Browse the repository at this point in the history
…deral-agency

Ticket #2147: Ensure domain Request and domain Info have "Non-federal" instead of None when empty
  • Loading branch information
zandercymatics committed May 16, 2024
2 parents fbafe67 + 70cd55f commit cfce03a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/registrar/models/domain_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -751,6 +752,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 = FederalAgency.objects.filter(agency="Non-Federal Agency").first()
self.save()

# create the domain
Domain = apps.get_model("registrar.Domain")

Expand Down
2 changes: 1 addition & 1 deletion src/registrar/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<td class="field-generic_org_type">Federal</td>', count=1)
# Now let's make sure the long description does not exist
Expand Down
22 changes: 22 additions & 0 deletions src/registrar/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DraftDomain,
DomainInvitation,
UserDomainRole,
FederalAgency,
)

import boto3_mocking
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -942,6 +963,7 @@ def test_approval_creates_info(self):
domain=domain,
notes="test notes",
domain_request=domain_request,
federal_agency=FederalAgency.objects.get(agency="Non-Federal Agency"),
).__dict__

# Test the two records for consistency
Expand Down

0 comments on commit cfce03a

Please sign in to comment.